tasks/release.py
def create_rc(ctx, major_versions="6,7", patch_version=False, upstream="origin"):
    """
    Updates the release entries in release.json to prepare the next RC build.
    If the previous version of the Agent (determined as the latest tag on the
    current branch) is not an RC:
    - by default, updates the release entries for the next minor version of
      the Agent.
    - if --patch-version is specified, updates the release entries for the next
      patch version of the Agent.

    This changes which tags will be considered on the dependency repositories (only
    tags that match the same major and minor version as the Agent).

    If the previous version of the Agent was an RC, updates the release entries for RC + 1.

    Examples:
    If the latest tag on the branch is 7.31.0, and invoke release.create-rc --patch-version
    is run, then the task will prepare the release entries for 7.31.1-rc.1, and therefore
    will only use 7.31.X tags on the dependency repositories that follow the Agent version scheme.

    If the latest tag on the branch is 7.32.0-devel or 7.31.0, and invoke release.create-rc
    is run, then the task will prepare the release entries for 7.32.0-rc.1, and therefore
    will only use 7.32.X tags on the dependency repositories that follow the Agent version scheme.

    Updates internal module dependencies with the new RC.

    Commits the above changes, and then creates a PR on the upstream repository with the change.

    Notes:
    This requires a Github token (either in the GITHUB_TOKEN environment variable, or in the MacOS keychain),
    with 'repo' permissions.
    This also requires that there are no local uncommitted changes, that the current branch is 'main' or the
    release branch, and that no branch named 'release/<new rc version>' already exists locally or upstream.
    """
    if sys.version_info[0] < 3:
        return Exit(message="Must use Python 3 for this task", code=1)

    github = GithubAPI(repository=REPOSITORY_NAME, api_token=get_github_token())

    list_major_versions = parse_major_versions(major_versions)

    # Get the version of the highest major: useful for some logging & to get
    # the version to use for Go submodules updates
    new_highest_version = next_rc_version(ctx, max(list_major_versions), patch_version)
    # Get the next final version of the highest major: useful to know which
    # milestone to target, as well as decide which tags from dependency repositories
    # can be used.
    new_final_version = next_final_version(ctx, max(list_major_versions), patch_version)

    # Get a string representation of the RC, eg. "6/7.32.0-rc.1"
    versions_string = f"{'/'.join([str(n) for n in list_major_versions[:-1]] + [str(new_highest_version)])}"

    print(color_message(f"Preparing RC for agent version(s) {list_major_versions}", "bold"))

    # Step 0: checks

    print(color_message("Checking repository state", "bold"))
    ctx.run("git fetch")

    if check_uncommitted_changes(ctx):
        raise Exit(
            color_message(
                "There are uncomitted changes in your repository. Please commit or stash them before trying again.",
                "red",
            ),
            code=1,
        )

    # Check that the current and update branches are valid
    current_branch = ctx.run("git rev-parse --abbrev-ref HEAD", hide=True).stdout.strip()
    update_branch = f"release/{new_highest_version}"

    if not check_base_branch(current_branch, new_highest_version):
        raise Exit(
            color_message(
                f"The branch you are on is neither {DEFAULT_BRANCH} or the correct release branch ({new_highest_version.branch()}). Aborting.",
                "red",
            ),
            code=1,
        )

    if check_local_branch(ctx, update_branch):
        raise Exit(
            color_message(
                f"The branch {update_branch} already exists locally. Please remove it before trying again.",
                "red",
            ),
            code=1,
        )

    if check_upstream_branch(github, update_branch):
        raise Exit(
            color_message(
                f"The branch {update_branch} already exists upstream. Please remove it before trying again.",
                "red",
            ),
            code=1,
        )

    # Find milestone based on what the next final version is. If the milestone does not exist, fail.
    milestone_name = str(new_final_version)

    milestone = github.get_milestone_by_name(milestone_name)

    if not milestone or not milestone.get("number"):
        raise Exit(
            color_message(
                f"""Could not find milestone {milestone_name} in the Github repository. Response: {milestone}
Make sure that milestone is open before trying again.""",
                "red",
            ),
            code=1,
        )

    # Step 1: Update release entries

    print(color_message("Updating release entries", "bold"))
    for major_version in list_major_versions:
        new_version = next_rc_version(ctx, major_version, patch_version)
        update_release_json(github.api_token, new_version, new_final_version)

    # Step 2: Update internal module dependencies

    print(color_message("Updating Go modules", "bold"))
    update_modules(ctx, str(new_highest_version))

    # Step 3: branch out, commit change, push branch

    print(color_message(f"Branching out to {update_branch}", "bold"))
    ctx.run(f"git checkout -b {update_branch}")

    print(color_message("Committing release.json and Go modules updates", "bold"))
    print(
        color_message(
            "If commit signing is enabled, you will have to make sure the commit gets properly signed.", "bold"
        )
    )
    ctx.run("git add release.json")
    ctx.run("git ls-files . | grep 'go.mod$' | xargs git add")

    ok = try_git_command(ctx, f"git commit -m 'Update release.json and Go modules for {versions_string}'")
    if not ok:
        raise Exit(
            color_message(
                f"Could not create commit. Please commit manually, push the {update_branch} branch and then open a PR against {current_branch}.",
                "red",
            ),
            code=1,
        )

    print(color_message("Pushing new branch to the upstream repository", "bold"))
    res = ctx.run(f"git push --set-upstream {upstream} {update_branch}", warn=True)
    if res.exited is None or res.exited > 0:
        raise Exit(
            color_message(
                f"Could not push branch {update_branch} to the upstream '{upstream}'. Please push it manually and then open a PR against {current_branch}.",
                "red",
            ),
            code=1,
        )

    print(color_message("Creating PR", "bold"))

    # Step 4: create PR

    pr = github.create_pr(
        pr_title=f"[release] Update release.json and Go modules for {versions_string}",
        pr_body="",
        base_branch=current_branch,
        target_branch=update_branch,
    )

    if not pr or not pr.get("number"):
        raise Exit(
            color_message(f"Could not create PR in the Github repository. Response: {pr}", "red"),
            code=1,
        )

    print(color_message(f"Created PR #{pr['number']}", "bold"))

    # Step 5: add milestone and labels to PR

    updated_pr = github.update_pr(
        pull_number=pr["number"],
        milestone_number=milestone["number"],
        labels=["changelog/no-changelog", "qa/skip-qa", "team/agent-platform", "team/agent-core"],
    )

    if not updated_pr or not updated_pr.get("number") or not updated_pr.get("html_url"):
        raise Exit(
            color_message(f"Could not update PR in the Github repository. Response: {updated_pr}", "red"),
            code=1,
        )

    print(color_message(f"Set labels and milestone for PR #{updated_pr['number']}", "bold"))
    print(
        color_message(
            f"Done preparing RC {versions_string}. The PR is available here: {updated_pr['html_url']}", "bold"
        )
    )

    Updates the release entries in release.json to prepare the next RC build.
    If the previous version of the Agent (determined as the latest tag on the
    current branch) is not an RC:
    - by default, updates the release entries for the next minor version of
      the Agent.
    - if --patch-version is specified, updates the release entries for the next
      patch version of the Agent.

    This changes which tags will be considered on the dependency repositories (only
    tags that match the same major and minor version as the Agent).

    If the previous version of the Agent was an RC, updates the release entries for RC + 1.

    Examples:
    If the latest tag on the branch is 7.31.0, and invoke release.create-rc --patch-version
    is run, then the task will prepare the release entries for 7.31.1-rc.1, and therefore
    will only use 7.31.X tags on the dependency repositories that follow the Agent version scheme.

    If the latest tag on the branch is 7.32.0-devel or 7.31.0, and invoke release.create-rc
    is run, then the task will prepare the release entries for 7.32.0-rc.1, and therefore
    will only use 7.32.X tags on the dependency repositories that follow the Agent version scheme.

    Updates internal module dependencies with the new RC.

    Commits the above changes, and then creates a PR on the upstream repository with the change.

    Notes:
    This requires a Github token (either in the GITHUB_TOKEN environment variable, or in the MacOS keychain),
    with 'repo' permissions.
    This also requires that there are no local uncommitted changes, that the current branch is 'main' or the
    release branch, and that no branch named 'release/<new rc version>' already exists locally or upstream.
    
Updates the release entries in release.json to prepare the next RC build.
If the previous version of the Agent (determined as the latest tag on the
current branch) is not an RC:
by default, updates the release entries for the next minor version of
the Agent.
if --patch-version is specified, updates the release entries for the next
patch version of the Agent.

This changes which tags will be considered on the dependency repositories (only
tags that match the same major and minor version as the Agent).

If the previous version of the Agent was an RC, updates the release entries for RC + 1.
Updates the release entries in release . json to prepare the next RC build . If the previous version of the Agent ( determined as the latest tag on the current branch ) is not an RC : by default updates the release entries for the next minor version of the Agent . if -- patch - version is specified updates the release entries for the next patch version of the Agent . This changes which tags will be considered on the dependency repositories ( only tags that match the same major and minor version as the Agent ) . If the previous version of the Agent was an RC updates the release entries for RC + 1 .
def create_rc(ctx, major_versions="6,7", patch_version=False, upstream="origin"):
    if sys.version_info[0] < 3:
        return Exit(message="Must use Python 3 for this task", code=1)
    github = GithubAPI(repository=REPOSITORY_NAME, api_token=get_github_token())
    list_major_versions = parse_major_versions(major_versions)
    new_highest_version = next_rc_version(ctx, max(list_major_versions), patch_version)
    new_final_version = next_final_version(ctx, max(list_major_versions), patch_version)
    versions_string = f"{'/'.join([str(n) for n in list_major_versions[:-1]] + [str(new_highest_version)])}"
    print(color_message(f"Preparing RC for agent version(s) {list_major_versions}", "bold"))
    print(color_message("Checking repository state", "bold"))
    ctx.run("git fetch")
    if check_uncommitted_changes(ctx):
        raise Exit(
            color_message(
                "There are uncomitted changes in your repository. Please commit or stash them before trying again.",
                "red",
            ),
            code=1,
        )
    current_branch = ctx.run("git rev-parse --abbrev-ref HEAD", hide=True).stdout.strip()
    update_branch = f"release/{new_highest_version}"
    if not check_base_branch(current_branch, new_highest_version):
        raise Exit(
            color_message(
                f"The branch you are on is neither {DEFAULT_BRANCH} or the correct release branch ({new_highest_version.branch()}). Aborting.",
                "red",
            ),
            code=1,
        )
    if check_local_branch(ctx, update_branch):
        raise Exit(
            color_message(
                f"The branch {update_branch} already exists locally. Please remove it before trying again.",
                "red",
            ),
            code=1,
        )
    if check_upstream_branch(github, update_branch):
        raise Exit(
            color_message(
                f"The branch {update_branch} already exists upstream. Please remove it before trying again.",
                "red",
            ),
            code=1,
        )
    milestone_name = str(new_final_version)
    milestone = github.get_milestone_by_name(milestone_name)
    if not milestone or not milestone.get("number"):
        raise Exit(
            color_message(
                f"""Could not find milestone {milestone_name} in the Github repository. Response: {milestone}
Make sure that milestone is open before trying again.""",
                "red",
            ),
            code=1,
        )
    print(color_message("Updating release entries", "bold"))
    for major_version in list_major_versions:
        new_version = next_rc_version(ctx, major_version, patch_version)
        update_release_json(github.api_token, new_version, new_final_version)
    print(color_message("Updating Go modules", "bold"))
    update_modules(ctx, str(new_highest_version))
    print(color_message(f"Branching out to {update_branch}", "bold"))
    ctx.run(f"git checkout -b {update_branch}")
    print(color_message("Committing release.json and Go modules updates", "bold"))
    print(
        color_message(
            "If commit signing is enabled, you will have to make sure the commit gets properly signed.", "bold"
        )
    )
    ctx.run("git add release.json")
    ctx.run("git ls-files . | grep 'go.mod$' | xargs git add")
    ok = try_git_command(ctx, f"git commit -m 'Update release.json and Go modules for {versions_string}'")
    if not ok:
        raise Exit(
            color_message(
                f"Could not create commit. Please commit manually, push the {update_branch} branch and then open a PR against {current_branch}.",
                "red",
            ),
            code=1,
        )
    print(color_message("Pushing new branch to the upstream repository", "bold"))
    res = ctx.run(f"git push --set-upstream {upstream} {update_branch}", warn=True)
    if res.exited is None or res.exited > 0:
        raise Exit(
            color_message(
                f"Could not push branch {update_branch} to the upstream '{upstream}'. Please push it manually and then open a PR against {current_branch}.",
                "red",
            ),
            code=1,
        )
    print(color_message("Creating PR", "bold"))
    pr = github.create_pr(
        pr_title=f"[release] Update release.json and Go modules for {versions_string}",
        pr_body="",
        base_branch=current_branch,
        target_branch=update_branch,
    )
    if not pr or not pr.get("number"):
        raise Exit(
            color_message(f"Could not create PR in the Github repository. Response: {pr}", "red"),
            code=1,
        )
    print(color_message(f"Created PR #{pr['number']}", "bold"))
    updated_pr = github.update_pr(
        pull_number=pr["number"],
        milestone_number=milestone["number"],
        labels=["changelog/no-changelog", "qa/skip-qa", "team/agent-platform", "team/agent-core"],
    )
    if not updated_pr or not updated_pr.get("number") or not updated_pr.get("html_url"):
        raise Exit(
            color_message(f"Could not update PR in the Github repository. Response: {updated_pr}", "red"),
            code=1,
        )
    print(color_message(f"Set labels and milestone for PR #{updated_pr['number']}", "bold"))
    print(
        color_message(
            f"Done preparing RC {versions_string}. The PR is available here: {updated_pr['html_url']}", "bold"
        )
    )
def create_rc ( ctx , major_versions = "6,7" , patch_version = False , upstream = "origin" ) : if sys . version_info [ 0 ] < 3 : return Exit ( message = "Must use Python 3 for this task" , code = 1 ) github = GithubAPI ( repository = REPOSITORY_NAME , api_token = get_github_token ( ) ) list_major_versions = parse_major_versions ( major_versions ) new_highest_version = next_rc_version ( ctx , max ( list_major_versions ) , patch_version ) new_final_version = next_final_version ( ctx , max ( list_major_versions ) , patch_version ) versions_string = f"{'/'.join([str(n) for n in list_major_versions[:-1]] + [str(new_highest_version)])}" print ( color_message ( f"Preparing RC for agent version(s) {list_major_versions}" , "bold" ) ) print ( color_message ( "Checking repository state" , "bold" ) ) ctx . run ( "git fetch" ) if check_uncommitted_changes ( ctx ) : raise Exit ( color_message ( "There are uncomitted changes in your repository. Please commit or stash them before trying again." , "red" , ) , code = 1 , ) current_branch = ctx . run ( "git rev-parse --abbrev-ref HEAD" , hide = True ) . stdout . strip ( ) update_branch = f"release/{new_highest_version}" if not check_base_branch ( current_branch , new_highest_version ) : raise Exit ( color_message ( f"The branch you are on is neither {DEFAULT_BRANCH} or the correct release branch ({new_highest_version.branch()}). Aborting." , "red" , ) , code = 1 , ) if check_local_branch ( ctx , update_branch ) : raise Exit ( color_message ( f"The branch {update_branch} already exists locally. Please remove it before trying again." , "red" , ) , code = 1 , ) if check_upstream_branch ( github , update_branch ) : raise Exit ( color_message ( f"The branch {update_branch} already exists upstream. Please remove it before trying again." , "red" , ) , code = 1 , ) milestone_name = str ( new_final_version ) milestone = github . get_milestone_by_name ( milestone_name ) if not milestone or not milestone . get ( "number" ) : raise Exit ( color_message ( f"""Could not find milestone {milestone_name} in the Github repository. Response: {milestone}
Make sure that milestone is open before trying again.""" , "red" , ) , code = 1 , ) print ( color_message ( "Updating release entries" , "bold" ) ) for major_version in list_major_versions : new_version = next_rc_version ( ctx , major_version , patch_version ) update_release_json ( github . api_token , new_version , new_final_version ) print ( color_message ( "Updating Go modules" , "bold" ) ) update_modules ( ctx , str ( new_highest_version ) ) print ( color_message ( f"Branching out to {update_branch}" , "bold" ) ) ctx . run ( f"git checkout -b {update_branch}" ) print ( color_message ( "Committing release.json and Go modules updates" , "bold" ) ) print ( color_message ( "If commit signing is enabled, you will have to make sure the commit gets properly signed." , "bold" ) ) ctx . run ( "git add release.json" ) ctx . run ( "git ls-files . | grep 'go.mod$' | xargs git add" ) ok = try_git_command ( ctx , f"git commit -m 'Update release.json and Go modules for {versions_string}'" ) if not ok : raise Exit ( color_message ( f"Could not create commit. Please commit manually, push the {update_branch} branch and then open a PR against {current_branch}." , "red" , ) , code = 1 , ) print ( color_message ( "Pushing new branch to the upstream repository" , "bold" ) ) res = ctx . run ( f"git push --set-upstream {upstream} {update_branch}" , warn = True ) if res . exited is None or res . exited > 0 : raise Exit ( color_message ( f"Could not push branch {update_branch} to the upstream '{upstream}'. Please push it manually and then open a PR against {current_branch}." , "red" , ) , code = 1 , ) print ( color_message ( "Creating PR" , "bold" ) ) pr = github . create_pr ( pr_title = f"[release] Update release.json and Go modules for {versions_string}" , pr_body = "" , base_branch = current_branch , target_branch = update_branch , ) if not pr or not pr . get ( "number" ) : raise Exit ( color_message ( f"Could not create PR in the Github repository. Response: {pr}" , "red" ) , code = 1 , ) print ( color_message ( f"Created PR #{pr['number']}" , "bold" ) ) updated_pr = github . update_pr ( pull_number = pr [ "number" ] , milestone_number = milestone [ "number" ] , labels = [ "changelog/no-changelog" , "qa/skip-qa" , "team/agent-platform" , "team/agent-core" ] , ) if not updated_pr or not updated_pr . get ( "number" ) or not updated_pr . get ( "html_url" ) : raise Exit ( color_message ( f"Could not update PR in the Github repository. Response: {updated_pr}" , "red" ) , code = 1 , ) print ( color_message ( f"Set labels and milestone for PR #{updated_pr['number']}" , "bold" ) ) print ( color_message ( f"Done preparing RC {versions_string}. The PR is available here: {updated_pr['html_url']}" , "bold" ) )
Updates the release entries in release.json to prepare the next RC build.
Updates the release entries in release . json to prepare the next RC build .
"""
    Updates the release entries in release.json to prepare the next RC build.
    If the previous version of the Agent (determined as the latest tag on the
    current branch) is not an RC:
    - by default, updates the release entries for the next minor version of
      the Agent.
    - if --patch-version is specified, updates the release entries for the next
      patch version of the Agent.

    This changes which tags will be considered on the dependency repositories (only
    tags that match the same major and minor version as the Agent).

    If the previous version of the Agent was an RC, updates the release entries for RC + 1.

    Examples:
    If the latest tag on the branch is 7.31.0, and invoke release.create-rc --patch-version
    is run, then the task will prepare the release entries for 7.31.1-rc.1, and therefore
    will only use 7.31.X tags on the dependency repositories that follow the Agent version scheme.

    If the latest tag on the branch is 7.32.0-devel or 7.31.0, and invoke release.create-rc
    is run, then the task will prepare the release entries for 7.32.0-rc.1, and therefore
    will only use 7.32.X tags on the dependency repositories that follow the Agent version scheme.

    Updates internal module dependencies with the new RC.

    Commits the above changes, and then creates a PR on the upstream repository with the change.

    Notes:
    This requires a Github token (either in the GITHUB_TOKEN environment variable, or in the MacOS keychain),
    with 'repo' permissions.
    This also requires that there are no local uncommitted changes, that the current branch is 'main' or the
    release branch, and that no branch named 'release/<new rc version>' already exists locally or upstream.
    """ # Get the version of the highest major: useful for some logging & to get # the version to use for Go submodules updates # Get the next final version of the highest major: useful to know which # milestone to target, as well as decide which tags from dependency repositories # can be used. # Get a string representation of the RC, eg. "6/7.32.0-rc.1" # Step 0: checks # Check that the current and update branches are valid # Find milestone based on what the next final version is. If the milestone does not exist, fail. # Step 1: Update release entries # Step 2: Update internal module dependencies # Step 3: branch out, commit change, push branch # Step 4: create PR # Step 5: add milestone and labels to PR
ctx
major_versions
patch_version
upstream
examples
None