Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add agent 6 schedule to create rc pr workflow #32073

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions .github/workflows/create_rc_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ on:
schedule:
- cron: '0 14 * * 1,3,5' # Run on Monday, Wednesday, and Friday at 14:00 UTC
- cron: '0 8 * * 1,3,5' # Same as above but at 08:00 UTC, to warn agent-integrations team about releasing
- cron: '0 9 * * 1' # Run Agent 6 workflow on Monday at 09:00 UTC

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

AGENT6_RELEASE_BRANCH: '6.53.x'
IS_AGENT6_RELEASE: ${{ github.event.schedule == '0 9 * * 1' }}
permissions: {}

jobs:
Expand All @@ -19,18 +21,21 @@ jobs:
warning: ${{ steps.warning.outputs.value }}
steps:
- name: Checkout repository
if: ${{ env.IS_AGENT6_RELEASE == 'false' }}
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
sparse-checkout: 'tasks'
persist-credentials: false

- name: Install python
if: ${{ env.IS_AGENT6_RELEASE == 'false' }}
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: 3.11
cache: "pip"

- name: Install Python dependencies
if: ${{ env.IS_AGENT6_RELEASE == 'false' }}
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
Expand All @@ -40,7 +45,11 @@ jobs:
- name: Determine the release active branches
id: branches
run: |
echo "value=$(inv release.get-unreleased-release-branches)" >> $GITHUB_OUTPUT
if ${{ env.IS_AGENT6_RELEASE == 'true' }}; then
echo "value=[\"$AGENT6_RELEASE_BRANCH\"]" >> $GITHUB_OUTPUT
else
echo "value=$(inv release.get-unreleased-release-branches)" >> $GITHUB_OUTPUT
fi
- name: Set the warning option
id: warning
Expand Down Expand Up @@ -87,17 +96,18 @@ jobs:
WARNING: ${{ needs.find_release_branches.outputs.warning }}
run: |
if [ -n "${{ needs.find_release_branches.outputs.warning }}" ]; then
echo "CHANGES=$(inv -e release.check-for-changes -r "$MATRIX" "$WARNING")" >> $GITHUB_OUTPUT
echo "CHANGES=$(inv -e release.check-for-changes -r "$MATRIX" "$WARNING" | tail -n 1)" >> $GITHUB_OUTPUT
else
echo "CHANGES=$(inv -e release.check-for-changes -r "$MATRIX")" >> $GITHUB_OUTPUT
echo "CHANGES=$(inv -e release.check-for-changes -r "$MATRIX" | tail -n 1)" >> $GITHUB_OUTPUT
fi
- name: Create RC PR
if: ${{ steps.check_for_changes.outputs.CHANGES == 'true'}}
if: ${{ steps.check_for_changes.outputs.CHANGES == 'true' || env.IS_AGENT6_RELEASE == 'true' }}
env:
MATRIX: ${{ matrix.value }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git fetch
inv -e release.create-rc "$MATRIX" --slack-webhook=${{ secrets.AGENT_RELEASE_SYNC_SLACK_WEBHOOK }}
if ${{ env.IS_AGENT6_RELEASE == 'true' }}; then
inv -e release.create-rc "$MATRIX" --slack-webhook=${{ secrets.AGENT_RELEASE_SYNC_SLACK_WEBHOOK }} --github-action --patch-version
else
inv -e release.create-rc "$MATRIX" --slack-webhook=${{ secrets.AGENT_RELEASE_SYNC_SLACK_WEBHOOK }} --github-action
fi
19 changes: 1 addition & 18 deletions tasks/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from tasks.go import tidy
from tasks.libs.ciproviders.github_api import GithubAPI
from tasks.libs.common.color import Color, color_message
from tasks.libs.common.git import check_uncommitted_changes
from tasks.libs.common.git import check_uncommitted_changes, get_git_config, revert_git_config, set_git_config

LICENSE_HEADER = """// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
Expand Down Expand Up @@ -502,23 +502,6 @@ def update(ctx):
print("Update complete.")


def get_git_config(key):
result = subprocess.run(['git', 'config', '--get', key], capture_output=True, text=True)
return result.stdout.strip() if result.returncode == 0 else None


def set_git_config(key, value):
subprocess.run(['git', 'config', key, value])


def revert_git_config(original_config):
for key, value in original_config.items():
if value is None:
subprocess.run(['git', 'config', '--unset', key])
else:
subprocess.run(['git', 'config', key, value])


@task()
def pull_request(ctx):
# Save current Git configuration
Expand Down
26 changes: 24 additions & 2 deletions tasks/libs/common/git.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import os
import subprocess
import tempfile
from contextlib import contextmanager
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -161,7 +162,7 @@ def check_base_branch(branch, release_version):
return branch == get_default_branch() or branch == release_version.branch()


def try_git_command(ctx, git_command):
def try_git_command(ctx, git_command, github_action=False):
"""
Try a git command that should be retried (after user confirmation) if it fails.
Primarily useful for commands which can fail if commit signing fails: we don't want the
Expand All @@ -179,7 +180,11 @@ def try_git_command(ctx, git_command):
"orange",
)
)
do_retry = yes_no_question("Do you want to retry this operation?", color="orange", default=True)
do_retry = (
False
if github_action
else yes_no_question("Do you want to retry this operation?", color="orange", default=True)
)
continue

return True
Expand Down Expand Up @@ -270,3 +275,20 @@ def get_last_release_tag(ctx, repo, pattern):
last_tag_name = last_tag_name_with_suffix.removesuffix("^{}")
last_tag_name = last_tag_name.removeprefix("refs/tags/")
return last_tag_commit, last_tag_name


def get_git_config(key):
result = subprocess.run(['git', 'config', '--get', key], capture_output=True, text=True)
return result.stdout.strip() if result.returncode == 0 else None


def set_git_config(key, value):
subprocess.run(['git', 'config', key, value])


def revert_git_config(original_config):
for key, value in original_config.items():
if value is None:
subprocess.run(['git', 'config', '--unset', key])
else:
subprocess.run(['git', 'config', key, value])
15 changes: 11 additions & 4 deletions tasks/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
get_last_commit,
get_last_release_tag,
is_agent6,
set_git_config,
try_git_command,
)
from tasks.libs.common.gomodules import get_default_modules
Expand Down Expand Up @@ -391,7 +392,7 @@ def finish(ctx, release_branch, upstream="origin"):


@task(help={'upstream': "Remote repository name (default 'origin')"})
def create_rc(ctx, release_branch, patch_version=False, upstream="origin", slack_webhook=None):
def create_rc(ctx, release_branch, patch_version=False, upstream="origin", slack_webhook=None, github_action=False):
"""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
Expand Down Expand Up @@ -427,12 +428,16 @@ def create_rc(ctx, release_branch, patch_version=False, upstream="origin", slack
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.
"""

major_version = get_version_major(release_branch)

with agent_context(ctx, release_branch):
github = GithubAPI(repository=GITHUB_REPO_NAME)

if github_action:
set_git_config('user.name', 'github-actions[bot]')
set_git_config('user.email', 'github-actions[bot]@users.noreply.github.com')
upstream = f"https://x-access-token:{os.environ.get('GITHUB_TOKEN')}@github.com/{GITHUB_REPO_NAME}.git"

# 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, major_version, patch_version)
Expand Down Expand Up @@ -463,7 +468,7 @@ def create_rc(ctx, release_branch, patch_version=False, upstream="origin", slack
# Step 1: Update release entries
print(color_message("Updating release entries", "bold"))
new_version = next_rc_version(ctx, major_version, patch_version)
if not yes_no_question(
if not github_action and not yes_no_question(
f'Do you want to create release candidate with:\n- new version: {new_version}\n- new highest version: {new_highest_version}\n- new final version: {new_final_version}?',
color="bold",
default=False,
Expand Down Expand Up @@ -492,7 +497,9 @@ def create_rc(ctx, release_branch, patch_version=False, upstream="origin", slack
ctx.run("git ls-files . | grep 'go.mod$' | xargs git add")

ok = try_git_command(
ctx, f"git commit --no-verify -m 'Update release.json and Go modules for {new_highest_version}'"
ctx,
f"git commit --no-verify -m 'Update release.json and Go modules for {new_highest_version}'",
github_action,
)
if not ok:
raise Exit(
Expand Down
Loading