Skip to content

Commit

Permalink
feat(release): Set gitconfig before git write operations
Browse files Browse the repository at this point in the history
  • Loading branch information
chouetz committed Dec 17, 2024
1 parent 5b903ef commit 080c749
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/create_rc_pr.yml
Original file line number Diff line number Diff line change
@@ -97,7 +97,5 @@ jobs:
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 -r "$MATRIX" --slack-webhook=${{ secrets.AGENT_RELEASE_SYNC_SLACK_WEBHOOK }}
9 changes: 9 additions & 0 deletions tasks/libs/common/utils.py
Original file line number Diff line number Diff line change
@@ -506,6 +506,15 @@ def is_pr_context(branch, pr_id, test_name):
return True


def set_gitconfig_in_ci(ctx):
"""
Set username and email when runing git "write" commands in CI
"""
if running_in_ci():
ctx.run('git config --global user.name "github-actions[bot]"', hide=True)
ctx.run('git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"', hide=True)


@contextmanager
def gitlab_section(section_name, collapsed=False, echo=False):
"""
9 changes: 9 additions & 0 deletions tasks/release.py
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@
)
from tasks.libs.common.gomodules import get_default_modules
from tasks.libs.common.user_interactions import yes_no_question
from tasks.libs.common.utils import set_gitconfig_in_ci
from tasks.libs.common.worktree import agent_context
from tasks.libs.pipeline.notifications import (
DEFAULT_JIRA_PROJECT,
@@ -253,6 +254,7 @@ def tag_modules(

if push:
tags_list = ' '.join(tags)
set_gitconfig_in_ci(ctx)
ctx.run(f"git push origin {tags_list}{force_option}")
print(f"Pushed tag {tags_list}")
print(f"Created module tags for version {agent_version}")
@@ -288,6 +290,7 @@ def tag_version(

if push:
tags_list = ' '.join(tags)
set_gitconfig_in_ci(ctx)
ctx.run(f"git push origin {tags_list}{force_option}")
print(f"Pushed tag {tags_list}")
print(f"Created tags for version {agent_version}")
@@ -348,6 +351,7 @@ def finish(ctx, release_branch, upstream="origin"):

commit_message = f"'Final updates for release.json and Go modules for {new_version} release'"

set_gitconfig_in_ci(ctx)
ok = try_git_command(ctx, f"git commit -m {commit_message}")
if not ok:
raise Exit(
@@ -490,6 +494,7 @@ def create_rc(ctx, release_branch, patch_version=False, upstream="origin", slack
ctx.run("git add release.json")
ctx.run("git ls-files . | grep 'go.mod$' | xargs git add")

set_gitconfig_in_ci(ctx)
ok = try_git_command(
ctx, f"git commit --no-verify -m 'Update release.json and Go modules for {new_highest_version}'"
)
@@ -672,6 +677,7 @@ def _main():
# Step 2 - Push newly created release branch to the remote repository

print(color_message("Pushing new branch to the upstream repository", "bold"))
set_gitconfig_in_ci(ctx)
res = ctx.run(f"git push --set-upstream {upstream} {release_branch}", warn=True)
if res.exited is None or res.exited > 0:
raise Exit(
@@ -772,6 +778,7 @@ def create_release_branches(ctx, base_directory="~/dd", major_version: int = 7,
_save_release_json(rj)
# Commit release.json
ctx.run("git add release.json")
set_gitconfig_in_ci(ctx)
ok = try_git_command(ctx, f"git commit -m 'Update release.json with current milestone to {next}'")

if not ok:
@@ -901,6 +908,7 @@ def cleanup(ctx, release_branch):
ctx.run("git add release.json")

commit_message = f"Update last_stable to {version}"
set_gitconfig_in_ci(ctx)
ok = try_git_command(ctx, f"git commit -m '{commit_message}'")
if not ok:
raise Exit(
@@ -1214,6 +1222,7 @@ def check_for_changes(ctx, release_branch, warning_mode=False):
with clone(ctx, repo_name, repo['branch'], options="--filter=blob:none --no-checkout"):
# We can add the new commit now to be used by release candidate creation
print(f"Creating new tag {next_version} on {repo_name}", file=sys.stderr)
set_gitconfig_in_ci(ctx)
ctx.run(f"git tag {next_version}")
ctx.run(f"git push origin tag {next_version}")
# This repo has changes, the next check is not needed

0 comments on commit 080c749

Please sign in to comment.