def _main(arg_strings=None):
    parser = _make_parser()
    args = parser.parse_args(arg_strings)
    version_name = "open-ce-v{}".format(args.version)
    release_number = ".".join(args.version.split(".")[:-1])
    branch_name = "open-ce-r{}".format(release_number)
    primary_repo_url = "[email protected]:{}/{}.git".format(
        args.github_org, args.primary_repo)

    version_msg = "Open-CE Version {}".format(args.version)
    release_name = "v{}".format(args.version)
    if args.code_name:
        version_msg = "{} Code-named {}".format(version_msg, args.code_name)
        release_name = "{} ({})".format(release_name, args.code_name)

    primary_repo_path = os.path.abspath(
        os.path.join(args.repo_dir, args.primary_repo))
    print("--->Making clone location: " + primary_repo_path)
    os.makedirs(primary_repo_path, exist_ok=True)
    print("--->Cloning {}".format(primary_repo_url))
    git_utils.clone_repo(primary_repo_url, primary_repo_path, args.branch)

    print("--->Creating {} branch in {}".format(version_name,
                                                args.primary_repo))
    git_utils.create_branch(primary_repo_path, branch_name)

    print("--->Updating env files.")
    _update_env_files(primary_repo_path, version_name)

    print("--->Committing env files.")
    git_utils.commit_changes(primary_repo_path,
                             "Updates for {}".format(release_number))

    print("--->Tag Primary Branch")
    git_utils.create_tag(primary_repo_path, version_name, version_msg)

    push = git_utils.ask_for_input(
        "Would you like to push changes to primary repo?")
    if push.startswith("y"):
        print("--->Pushing branch.")
        git_utils.push_branch(primary_repo_path, branch_name)
        print("--->Pushing tag.")
        git_utils.push_branch(primary_repo_path, version_name)

    tag_all_repos.tag_all_repos(github_org=args.github_org,
                                tag=version_name,
                                tag_msg=version_msg,
                                branch=args.branch,
                                repo_dir=args.repo_dir,
                                pat=args.pat,
                                skipped_repos=[args.primary_repo, ".github"] +
                                inputs.parse_arg_list(args.skipped_repos),
                                prev_tag=None)

    release = git_utils.ask_for_input(
        "Would you like to create a github release?")
    if release.startswith("y"):
        print("--->Creating Draft Release.")
        git_utils.create_release(args.github_org, args.primary_repo, args.pat,
                                 version_name, release_name, version_msg, True)
def tag_repos(repos, tag, tag_msg, repo_dir):
    '''
    Tags a list of repos.
    '''
    print("---------------------------Tagging all Repos")
    for repo in repos:
        repo_path = os.path.abspath(os.path.join(repo_dir, repo["name"]))
        print("--->Tagging {}".format(repo["name"]))
        git_utils.create_tag(repo_path, tag, tag_msg)
예제 #3
0
def tag_all_repos(github_org, tag, tag_msg, branch, repo_dir, pat, skipped_repos, prev_tag): # pylint: disable=too-many-arguments
    '''
    Clones, then tags all repos with a given tag, and pushes back to remote.
    These steps are performed in separate loops to make debugging easier.
    '''
    skipped_repos = inputs.parse_arg_list(skipped_repos)
    repos = git_utils.get_all_repos(github_org, pat)
    repos = [repo for repo in repos if repo["name"] not in skipped_repos ]
    print("---------------------------Cloning all Repos")
    for repo in repos:
        repo_path = os.path.abspath(os.path.join(repo_dir, repo["name"]))
        print("--->Making clone location: " + repo_path)
        os.makedirs(repo_path, exist_ok=True)
        print("--->Cloning {}".format(repo["name"]))
        git_utils.clone_repo(repo["ssh_url"], repo_path)
        if branch and git_utils.branch_exists(repo_path, branch):
            print("--->Branch '{}' exists, checking it out.".format(branch))
            git_utils.checkout(repo_path, branch)
        elif prev_tag:
            repo_branch = git_utils.get_tag_branch(repo_path, prev_tag)
            print("--->Checking out branch '{}' which contains tag '{}'.".format(repo_branch, prev_tag))
            git_utils.checkout(repo_path, repo_branch)

    print("---------------------------Tagging all Repos")
    for repo in repos:
        repo_path = os.path.abspath(os.path.join(repo_dir, repo["name"]))
        print("--->Tagging {}".format(repo["name"]))
        git_utils.create_tag(repo_path, tag, tag_msg)

    push = git_utils.ask_for_input("Would you like to push all tags to remote?")
    if not push.startswith("y"):
        return

    print("---------------------------Pushing all Repos")
    for repo in repos:
        try:
            repo_path = os.path.abspath(os.path.join(repo_dir, repo["name"]))
            print("--->Pushing {}".format(repo["name"]))
            git_utils.push_branch(repo_path, tag)
        except Exception as exc:# pylint: disable=broad-except
            print("Error encountered when trying to push {}".format(repo["name"]))
            print(exc)
            cont_tag = git_utils.ask_for_input("Would you like to continue tagging other repos?")
            if cont_tag.startswith("y"):
                continue
            raise
예제 #4
0
def tag_bugfixing_commits(repo, data):
    """Add tags to commits which are bug fixes in the form of 'fixes-<bug_id>'

    For each bug report of a fixed bug in data, retrieve which commit
    fixed the bug in question.  To each such commit, add lightweight
    tag denoting which bug it fixes to the repository.  This could be
    later used to find out which bugfixes affected given file.

    NOTE that the script needs to have write permissions to the
    repository in question.

    Parameters
    ----------
    data : dict | OrderedDict
        The combined bug report and repository information from
        the JSON file.

    repo :  str | git.Repo | pygit2.Repository
        Pathname to the repository, or either GitPython (git.Repo)
        or pygit2 (pygit2.Repository) repository object.

        Type of this parameter selects implementation used.
        This could be the result of args_utils.repo_by_backend()

    Side effects
    ------------
    Creates lightweight tags in the repository.  Prints progress
    messages on stderr.
    """
    n_skipped = 0

    tags = set(git_utils.retrieve_tags(repo))
    for commit in tqdm(data):
        bugtag = 'fixes-{:d}'.format(int(data[commit]['bug_report']['bug_id']))
        if bugtag in tags:
            n_skipped = n_skipped + 1
            continue

        # assumes that 'sha' field is fixed
        git_utils.create_tag(repo, bugtag,
                             data[commit]['commit']['metadata']['sha'])

    # info about process
    print('%d / %d skipped: already tagged' % (n_skipped, len(data)),
          file=sys.stderr)
예제 #5
0
def _main(arg_strings=None):  # pylint: disable=too-many-locals, too-many-statements
    parser = _make_parser()
    args = parser.parse_args(arg_strings)

    config_file = None
    if args.conda_build_configs:
        config_file = os.path.abspath(args.conda_build_configs)

    primary_repo_path = "./"

    open_ce_env_file = os.path.abspath(
        os.path.join(primary_repo_path, "envs", "opence-env.yaml"))
    if not _has_git_tag_changed(primary_repo_path, args.branch,
                                open_ce_env_file):
        print("--->The opence-env git_tag has not changed.")
        print("--->No release is needed.")
        return
    print("--->The opence-env git_tag has changed!")
    current_tag = _get_git_tag_from_env_file(open_ce_env_file)
    previous_tag = _get_previous_git_tag_from_env_file(primary_repo_path,
                                                       args.branch,
                                                       open_ce_env_file)
    version = _git_tag_to_version(current_tag)
    release_number = ".".join(version.split(".")[:-1])
    bug_fix = version.split(".")[-1]
    branch_name = "open-ce-r{}".format(release_number)
    version_msg = "Open-CE Version {}".format(version)
    release_name = "v{}".format(version)

    env_file_contents = env_config.load_env_config_files([open_ce_env_file],
                                                         utils.ALL_VARIANTS(),
                                                         ignore_urls=True)
    for env_file_content in env_file_contents:
        env_file_tag = env_file_content.get(
            env_config.Key.git_tag_for_env.name, None)
        if env_file_tag != current_tag:
            message = "Incorrect {} '{}' found in the following env_file:\n{}".format(
                env_config.Key.git_tag_for_env.name, env_file_tag,
                env_file_content)
            raise Exception(message)

    if not git_utils.branch_exists(primary_repo_path, branch_name):
        print("--->Creating {} branch in {}".format(branch_name,
                                                    args.primary_repo))
        git_utils.create_branch(primary_repo_path, branch_name)
    else:
        print("--->Branch {} already exists in {}. Not creating it.".format(
            current_tag, args.primary_repo))

    print("--->Tag Primary Branch")
    git_utils.create_tag(primary_repo_path, current_tag, version_msg)

    if args.not_dry_run:
        print("--->Pushing branch.")
        git_utils.push_branch(primary_repo_path, branch_name)
        print("--->Pushing tag.")
        git_utils.push_branch(primary_repo_path, current_tag)
    else:
        print("--->Skipping pushing branch and tag for dry run.")

    repos = _get_all_feedstocks(env_files=env_file_contents,
                                github_org=args.github_org,
                                pat=args.pat,
                                skipped_repos=[args.primary_repo, ".github"] +
                                inputs.parse_arg_list(args.skipped_repos))

    repos.sort(key=lambda repo: repo["name"])

    tag_all_repos.clone_repos(repos=repos,
                              branch=None,
                              repo_dir=args.repo_dir,
                              prev_tag=previous_tag)
    tag_all_repos.tag_repos(repos=repos,
                            tag=current_tag,
                            tag_msg=version_msg,
                            repo_dir=args.repo_dir)
    if args.not_dry_run:
        tag_all_repos.push_repos(repos=repos,
                                 tag=current_tag,
                                 repo_dir=args.repo_dir,
                                 continue_query=False)
    else:
        print("--->Skipping pushing feedstocks for dry run.")

    print("--->Generating Release Notes.")
    release_notes = _create_release_notes(
        repos,
        version,
        release_number,
        bug_fix,
        current_tag,
        previous_tag,
        utils.ALL_VARIANTS(),
        config_file,
        repo_dir=args.repo_dir,
    )
    print(release_notes)

    if args.not_dry_run:
        print("--->Creating Draft Release.")
        git_utils.create_release(args.github_org, args.primary_repo, args.pat,
                                 current_tag, release_name, release_notes,
                                 True)
    else:
        print("--->Skipping release creation for dry run.")