Skip to content

Commit 080c749

Browse files
committed
feat(release): Set gitconfig before git write operations
1 parent 5b903ef commit 080c749

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

.github/workflows/create_rc_pr.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,5 @@ jobs:
9797
env:
9898
MATRIX: ${{ matrix.value }}
9999
run: |
100-
git config user.name "github-actions[bot]"
101-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
102100
git fetch
103101
inv -e release.create-rc -r "$MATRIX" --slack-webhook=${{ secrets.AGENT_RELEASE_SYNC_SLACK_WEBHOOK }}

tasks/libs/common/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,15 @@ def is_pr_context(branch, pr_id, test_name):
506506
return True
507507

508508

509+
def set_gitconfig_in_ci(ctx):
510+
"""
511+
Set username and email when runing git "write" commands in CI
512+
"""
513+
if running_in_ci():
514+
ctx.run('git config --global user.name "github-actions[bot]"', hide=True)
515+
ctx.run('git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"', hide=True)
516+
517+
509518
@contextmanager
510519
def gitlab_section(section_name, collapsed=False, echo=False):
511520
"""

tasks/release.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
)
3939
from tasks.libs.common.gomodules import get_default_modules
4040
from tasks.libs.common.user_interactions import yes_no_question
41+
from tasks.libs.common.utils import set_gitconfig_in_ci
4142
from tasks.libs.common.worktree import agent_context
4243
from tasks.libs.pipeline.notifications import (
4344
DEFAULT_JIRA_PROJECT,
@@ -253,6 +254,7 @@ def tag_modules(
253254

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)