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

feat(release): Set gitconfig before git write operations #32277

Merged
merged 4 commits into from
Feb 13, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix tests and update post rebase
  • Loading branch information
chouetz committed Feb 12, 2025
commit ff2ceb49e0a280995cc7962570715feab64296b3
1 change: 0 additions & 1 deletion .github/workflows/create_rc_pr.yml
Original file line number Diff line number Diff line change
@@ -119,7 +119,6 @@ jobs:
env:
MATRIX: ${{ matrix.value }}
run: |
git fetch
if ${{ env.IS_AGENT6_RELEASE == 'true' }}; then
inv -e release.create-rc -r "$MATRIX" --slack-webhook=${{ secrets.AGENT6_RELEASE_SLACK_WEBHOOK }} --patch-version
else
4 changes: 2 additions & 2 deletions tasks/libs/common/utils.py
Original file line number Diff line number Diff line change
@@ -506,8 +506,8 @@ def set_gitconfig_in_ci(ctx):
Set username and email when runing git "write" commands in CI
"""
if running_in_ci():
set_git_config('user.name', 'github-actions[bot]')
set_git_config('user.email', 'github-actions[bot]@users.noreply.github.com')
set_git_config(ctx, 'user.name', 'github-actions[bot]')
set_git_config(ctx, 'user.email', 'github-actions[bot]@users.noreply.github.com')


@contextmanager
11 changes: 2 additions & 9 deletions tasks/release.py
Original file line number Diff line number Diff line change
@@ -36,7 +36,6 @@
get_last_commit,
get_last_release_tag,
is_agent6,
set_git_config,
try_git_command,
)
from tasks.libs.common.gomodules import get_default_modules
@@ -1350,14 +1349,7 @@ def bump_integrations_core(ctx, slack_webhook=None):
"""
Create a PR to bump the integrations core fields in the release.json file
"""
github_workflow_url = ""
if os.environ.get("GITHUB_ACTIONS"):
set_git_config('user.name', 'github-actions[bot]')
set_git_config('user.email', 'github-actions[bot]@users.noreply.github.com')
github_server_url = os.environ.get("GITHUB_SERVER_URL")
github_run_id = os.environ.get("GITHUB_RUN_ID")
github_workflow_url = f"{github_server_url}/{GITHUB_REPO_NAME}/actions/runs/{github_run_id}"

github_workflow_url = f"{os.environ.get('GITHUB_SERVER_URL', 'github.com')}/{GITHUB_REPO_NAME}/actions/runs/{os.environ.get('GITHUB_RUN_ID', '1')}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the bump_integrations_core task isn't run through github actions, this will default to:
github.com/DataDog/datadog-agent/actions/runs/1

should we set the url to an empty string ("") when not running in GitHub Actions to avoid confusion?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted to save a if but you are right this might be misleading

commit_hash = get_git_references(ctx, "integrations-core", "HEAD").split()[0]

rj = load_release_json()
@@ -1373,6 +1365,7 @@ def bump_integrations_core(ctx, slack_webhook=None):
ctx.run("git add release.json")

commit_message = "bump integrations core to HEAD"
set_gitconfig_in_ci(ctx)
ok = try_git_command(ctx, f"git commit -m '{commit_message}'")
if not ok:
raise Exit(
12 changes: 12 additions & 0 deletions tasks/unit_tests/release_tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import os
import re
import sys
import unittest
@@ -786,6 +787,7 @@ def test_no_changes(self, version_mock, print_mock, _):
}
),
)
@patch.dict(os.environ, {'GITHUB_ACTIONS': 'true'})
@patch('os.chdir', new=MagicMock())
def test_changes_new_commit_first_repo(self, version_mock, print_mock, _):
with mock_git_clone():
@@ -796,6 +798,8 @@ def test_changes_new_commit_first_repo(self, version_mock, print_mock, _):
c = MockContext(
run={
'git rev-parse --abbrev-ref HEAD': Result("main"),
'git config user.name github-actions[bot]': Result(""),
'git config user.email github-actions[bot]@users.noreply.github.com': Result(""),
'git ls-remote -h https://github.com/DataDog/omnibus-software "refs/heads/main"': Result(
"4n0th3rc0mm1t9 refs/heads/main"
),
@@ -867,6 +871,7 @@ def test_changes_new_commit_first_repo(self, version_mock, print_mock, _):
),
)
@patch('os.chdir', new=MagicMock())
@patch.dict(os.environ, {'GITHUB_ACTIONS': 'false'})
def test_changes_new_commit_all_repo(self, version_mock, print_mock, _):
with mock_git_clone():
next = MagicMock()
@@ -1018,6 +1023,7 @@ def test_changes_new_release_one_repo(self, version_mock, print_mock, _):
}
),
)
@patch.dict(os.environ, {'GITHUB_ACTIONS': 'true'})
@patch('os.chdir', new=MagicMock())
def test_changes_new_commit_second_repo_branch_out(self, version_mock, print_mock, _):
with mock_git_clone():
@@ -1028,6 +1034,8 @@ def test_changes_new_commit_second_repo_branch_out(self, version_mock, print_moc
c = MockContext(
run={
'git rev-parse --abbrev-ref HEAD': Result("main"),
'git config user.name github-actions[bot]': Result(""),
'git config user.email github-actions[bot]@users.noreply.github.com': Result(""),
'git ls-remote -h https://github.com/DataDog/omnibus-software "refs/heads/7.55.x"': Result(
"4n0th3rc0mm1t0 refs/heads/main"
),
@@ -1264,6 +1272,7 @@ def test_update_module_optional_in_agent_7(self):
class TestTagModules(unittest.TestCase):
@patch('tasks.release.__tag_single_module', new=MagicMock(side_effect=[[str(i)] for i in range(2)]))
@patch('tasks.release.agent_context', new=MagicMock())
@patch.dict(os.environ, {'GITHUB_ACTIONS': 'false'})
def test_2_tags(self):
c = MockContext(run=Result("yolo"))
with patch('tasks.release.get_default_modules') as mock_modules:
@@ -1276,6 +1285,7 @@ def test_2_tags(self):

@patch('tasks.release.__tag_single_module', new=MagicMock(side_effect=[[str(i)] for i in range(3)]))
@patch('tasks.release.agent_context', new=MagicMock())
@patch.dict(os.environ, {'GITHUB_ACTIONS': 'false'})
def test_3_tags(self):
c = MockContext(run=Result("yolo"))
with patch('tasks.release.get_default_modules') as mock_modules:
@@ -1288,6 +1298,7 @@ def test_3_tags(self):

@patch('tasks.release.__tag_single_module', new=MagicMock(side_effect=[[str(i)] for i in range(4)]))
@patch('tasks.release.agent_context', new=MagicMock())
@patch.dict(os.environ, {'GITHUB_ACTIONS': 'false'})
def test_4_tags(self):
c = MockContext(run=Result("yolo"))
with patch('tasks.release.get_default_modules') as mock_modules:
@@ -1304,6 +1315,7 @@ def test_4_tags(self):

@patch('tasks.release.__tag_single_module', new=MagicMock(side_effect=[[str(i)] for i in range(100)]))
@patch('tasks.release.agent_context', new=MagicMock())
@patch.dict(os.environ, {'GITHUB_ACTIONS': 'false'})
def test_100_tags(self):
c = MockContext(run=Result("yolo"))
with patch('tasks.release.get_default_modules') as mock_modules:
Loading