Skip to content

Commit

Permalink
add qualification phase for agent 6
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jan 24, 2025
1 parent f392387 commit fb0c103
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 10 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/create_rc_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,14 @@ jobs:
echo "CHANGES=$(inv -e release.check-for-changes -r "$MATRIX")" >> $GITHUB_OUTPUT
fi
- name: Check if agent 6 is in qualification phase
if: ${{ env.IS_AGENT6_RELEASE == 'true' }}
run: |
is_qualification=$(inv -e release.is-qualification --output)
echo "IS_QUALIFICATION=$is_qualification" >> $GITHUB_ENV
- name: Create RC PR
if: ${{ steps.check_for_changes.outputs.CHANGES == 'true' || env.IS_AGENT6_RELEASE == 'true' }}
if: ${{ steps.check_for_changes.outputs.CHANGES == 'true' || ( env.IS_AGENT6_RELEASE == 'true' && env.IS_QUALIFICATION == 'false') }}
env:
MATRIX: ${{ matrix.value }}
run: |
Expand All @@ -118,3 +124,8 @@ jobs:
else
inv -e release.create-rc -r "$MATRIX" --slack-webhook=${{ secrets.AGENT_RELEASE_SYNC_SLACK_WEBHOOK }}
fi
- name: Rebuild agent 6 RC pipeline if no changes and in qualification phase
if: ${{ env.IS_AGENT6_RELEASE == 'true' && steps.check_for_changes.outputs.CHANGES == 'false' && env.IS_QUALIFICATION == 'true' }}
run: |
inv -e release.run-rc-pipeline 6.53.x
5 changes: 4 additions & 1 deletion tasks/libs/releasing/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
VERSION_RE = re.compile(r'(v)?(\d+)[.](\d+)([.](\d+))?(-devel)?(-rc\.(\d+))?')

# Regex matching rc version tag format like 7.50.0-rc.1
RC_VERSION_RE = re.compile(r'\d+[.]\d+[.]\d+-rc\.\d+')
RC_VERSION_RE = re.compile(r'^\d+[.]\d+[.]\d+-rc\.\d+$')

# Regex matching final version tag format like 7.54.0
FINAL_VERSION_RE = re.compile(r'^\d+[.]\d+[.]\d+$')

# Regex matching minor release rc version tag like x.y.0-rc.1 (semver PATCH == 0), but not x.y.1-rc.1 (semver PATCH > 0)
MINOR_RC_VERSION_RE = re.compile(r'\d+[.]\d+[.]0-rc\.\d+')
Expand Down
73 changes: 65 additions & 8 deletions tasks/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from time import sleep

from gitlab import GitlabError
from invoke import task
from invoke import Failure, task
from invoke.exceptions import Exit

from tasks.libs.ciproviders.github_api import GithubAPI, create_release_pr
Expand Down Expand Up @@ -66,6 +66,7 @@
)
from tasks.libs.releasing.notes import _add_dca_prelude, _add_prelude
from tasks.libs.releasing.version import (
FINAL_VERSION_RE,
MINOR_RC_VERSION_RE,
RC_VERSION_RE,
VERSION_RE,
Expand All @@ -86,6 +87,7 @@

BACKPORT_LABEL_COLOR = "5319e7"
TAG_BATCH_SIZE = 3
QUALIFICATION_TAG = "qualification"


@task
Expand Down Expand Up @@ -149,10 +151,11 @@ def __get_force_option(force: bool) -> str:
return force_option


def __tag_single_module(ctx, module, agent_version, commit, force_option, devel):
def __tag_single_module(ctx, module, tag_name, commit, force_option, devel):
"""Tag a given module."""
tags = []
for tag in module.tag(agent_version):
tags_to_commit = module.tag(tag_name) if VERSION_RE.match(tag_name) else [tag_name]
for tag in tags_to_commit:
if devel:
tag += "-devel"

Expand Down Expand Up @@ -211,7 +214,15 @@ def tag_modules(

@task
def tag_version(
ctx, release_branch=None, commit="HEAD", push=True, force=False, devel=False, version=None, trust=False
ctx,
release_branch=None,
commit="HEAD",
push=True,
force=False,
devel=False,
version=None,
trust=False,
start_qual=False,
):
"""Create tags for a given Datadog Agent version.
Expand All @@ -221,6 +232,7 @@ def tag_version(
push: Will push the tags to the origin remote (on by default).
force: Will allow the task to overwrite existing tags. Needed to move existing tags (off by default).
devel: Will create -devel tags (used after creation of the release branch)
start_qual: Will start the qualification phase for agent 6 release candidate by adding a qualification tag
Examples:
$ inv -e release.tag-version 7.27.x # Create tags and push them to origin
Expand All @@ -237,6 +249,16 @@ def tag_version(
with agent_context(ctx, release_branch, skip_checkout=release_branch is None):
tags = __tag_single_module(ctx, get_default_modules()["."], agent_version, commit, force_option, devel)

# create or update the qualification tag using the force option (points tag to next RC)
if is_agent6(ctx) and (start_qual or is_qualification(ctx)):
if FINAL_VERSION_RE.match(agent_version):
ctx.run(f"git push --delete origin {QUALIFICATION_TAG}")
else:
force_option = __get_force_option(not start_qual)
tags += __tag_single_module(
ctx, get_default_modules()["."], QUALIFICATION_TAG, commit, force_option, False
)

if push:
tags_list = ' '.join(tags)
ctx.run(f"git push origin {tags_list}{force_option}")
Expand Down Expand Up @@ -490,7 +512,20 @@ def create_rc(ctx, release_branch, patch_version=False, upstream="origin", slack


@task
def build_rc(ctx, release_branch, patch_version=False, k8s_deployments=False):
def is_qualification(ctx, output=False):
try:
ctx.run(f"git tag | grep {QUALIFICATION_TAG}", hide=True)
if output:
print('true')
return True
except Failure:
if output:
print("false")
return False


@task
def build_rc(ctx, release_branch, patch_version=False, k8s_deployments=False, start_qual=False):
"""To be done after the PR created by release.create-rc is merged, with the same options
as release.create-rc.
Expand All @@ -499,6 +534,7 @@ def build_rc(ctx, release_branch, patch_version=False, k8s_deployments=False):
Args:
k8s_deployments: When set to True the child pipeline deploying to subset of k8s staging clusters will be triggered.
start_qual: Start the qualification phase for agent 6 release candidates.
"""

major_version = get_version_major(release_branch)
Expand Down Expand Up @@ -548,7 +584,7 @@ def build_rc(ctx, release_branch, patch_version=False, k8s_deployments=False):
# tag_version only takes the highest version (Agent 7 currently), and creates
# the tags for all supported versions
# TODO: make it possible to do Agent 6-only or Agent 7-only tags?
tag_version(ctx, version=str(new_version), force=False)
tag_version(ctx, version=str(new_version), force=False, start_qual=start_qual)
tag_modules(ctx, version=str(new_version), force=False)

print(color_message(f"Waiting until the {new_version} tag appears in Gitlab", "bold"))
Expand All @@ -564,10 +600,31 @@ def build_rc(ctx, release_branch, patch_version=False, k8s_deployments=False):
print(color_message("Creating RC pipeline", "bold"))

# Step 2: Run the RC pipeline
run_rc_pipeline(release_branch, gitlab_tag.name, k8s_deployments)


@task
def run_rc_pipeline(ctx, release_branch, gitlab_tag=None, k8s_deployments=False):
with agent_context(ctx, release_branch):
if not gitlab_tag:
err_msg = "Error: Expected exactly one release candidate tag associated with the qualification tag commit. Tags found:"
try:
res = ctx.run(f"git tag --points-at $(git rev-list -n 1 {QUALIFICATION_TAG}) | grep 6.53")
except Failure as err:
raise Exit(message=f"{err_msg} []", code=1) from err

tags = [tag for tag in res.stdout.split("\n") if tag.strip()]
if len(tags) > 1:
raise Exit(message=f"{err_msg} {tags}", code=1)
if not RC_VERSION_RE.match(tags[0]):
raise Exit(
message=f"Error: The tag '{tags[0]}' does not match expected release candidate pattern", code=1
)
gitlab_tag = tags[0]

run(
ctx,
git_ref=gitlab_tag.name,
git_ref=gitlab_tag,
use_release_entries=True,
repo_branch="beta",
deploy=True,
Expand Down Expand Up @@ -1294,7 +1351,7 @@ def check_previous_agent6_rc(ctx):
err_msg += agent6_prs

response = get_ci_pipeline_events(
'ci_level:pipeline @ci.pipeline.name:"DataDog/datadog-agent" @git.tag:6.53.* [email protected]:true',
'ci_level:pipeline @ci.pipeline.name:"DataDog/datadog-agent" @git.tag:6.53.* [email protected]:true [email protected]_pipeline:retry',
7,
)
if not response.data:
Expand Down

0 comments on commit fb0c103

Please sign in to comment.