From 99a2a9ce72397abf56e7b60e1a6ac83598f97329 Mon Sep 17 00:00:00 2001 From: Juanpe Araque Date: Wed, 14 May 2025 15:41:24 +0200 Subject: [PATCH 1/3] Ensure ddev release tag fetches tags before getting the full list of tags --- .gitlab-ci.yml | 41 ++++++++++++------- .../dev/tooling/commands/release/tag.py | 19 ++++++++- .../datadog_checks/dev/tooling/git.py | 13 +++++- datadog_checks_dev/tests/tooling/test_git.py | 19 +++++++++ 4 files changed, 75 insertions(+), 17 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6dea80f2d590d..3c40faa9fe46d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -128,27 +128,40 @@ release-manual: tagger-image-builder: stage: build image: 486234852809.dkr.ecr.us-east-1.amazonaws.com/docker:24.0.4-gbi-focal - only: - changes: - - .gitlab/tagger/**/* - - ddev/**/* - - .gitlab-ci.yml - refs: - - master + rules: + - if: $CI_PIPELINE_SOURCE == 'schedule' + when: never + - if: $CI_COMMIT_TAG + when: never + - if: $CI_COMMIT_BRANCH == 'master' + when: always + - changes: + - .gitlab/tagger/**/* + - ddev/**/* + - .gitlab-ci.yml + # Allow to manually trigger a build if we need to + - when: manual + allow_failure: true script: - docker buildx build --tag $TAGGER_IMAGE -f .gitlab/tagger/Dockerfile . --push - except: [ tags, schedules ] tags: [ "arch:amd64" ] validate-log-intgs-builder: stage: build image: 486234852809.dkr.ecr.us-east-1.amazonaws.com/docker:24.0.4-gbi-focal - only: - changes: - - .gitlab/validate-logs-intgs/**/* - - .gitlab-ci.yml - refs: - - master + rules: + - if: $CI_PIPELINE_SOURCE == 'schedule' + when: never + - if: $CI_COMMIT_TAG + when: never + - if: $CI_COMMIT_BRANCH == 'master' + when: always + - changes: + - .gitlab/validate-logs-intgs/**/* + - .gitlab-ci.yml + # Allow to manually trigger a build if we need to + - when: manual + allow_failure: true script: - cd .gitlab/validate-logs-intgs/ - docker buildx build --tag $VALIDATE_LOG_INTGS . --push diff --git a/datadog_checks_dev/datadog_checks/dev/tooling/commands/release/tag.py b/datadog_checks_dev/datadog_checks/dev/tooling/commands/release/tag.py index 12118ae74c878..545dba0216af7 100644 --- a/datadog_checks_dev/datadog_checks/dev/tooling/commands/release/tag.py +++ b/datadog_checks_dev/datadog_checks/dev/tooling/commands/release/tag.py @@ -3,7 +3,7 @@ # Licensed under a 3-clause BSD style license (see LICENSE) import click -from ...git import git_tag, git_tag_list +from ...git import git_fetch, git_tag, git_tag_list from ...release import get_release_tag_string from ...utils import complete_valid_checks, get_valid_checks, get_version_string from ..console import CONTEXT_SETTINGS, abort, echo_info, echo_success, echo_waiting, echo_warning @@ -19,7 +19,8 @@ @click.option('--push/--no-push', default=True) @click.option('--dry-run', '-n', is_flag=True) @click.option('--skip-prerelease', is_flag=True) -def tag(check, version, push, dry_run, skip_prerelease): +@click.option('--fetch/--no-fetch', default=True) +def tag(check, version, push, dry_run, skip_prerelease, fetch): """Tag the HEAD of the git repo with the current release number for a specific check. The tag is pushed to origin by default. @@ -28,6 +29,13 @@ def tag(check, version, push, dry_run, skip_prerelease): Notice: specifying a different version than the one in `__about__.py` is a maintenance task that should be run under very specific circumstances (e.g. re-align an old release performed on the wrong commit). + + Return codes: + 0: Success + 1: Invalid command call + 2: Nothing to tag + 3: Failed to fetch tags + Other: Git tag command returned a non-zero exit code """ tagging_all = check == 'all' @@ -44,6 +52,13 @@ def tag(check, version, push, dry_run, skip_prerelease): # Check for any new tags tagged = False + # Fetch all tags from the remote + if fetch: + echo_info('Fetching all tags from remote...') + + if (result := git_fetch(tags=True)).code != 0: + abort(f'Failed to fetch tags: {result.stderr}', 3) + existing_tags = git_tag_list() for check in checks: diff --git a/datadog_checks_dev/datadog_checks/dev/tooling/git.py b/datadog_checks_dev/datadog_checks/dev/tooling/git.py index 0190826e4d6ba..aa440c6494e41 100644 --- a/datadog_checks_dev/datadog_checks/dev/tooling/git.py +++ b/datadog_checks_dev/datadog_checks/dev/tooling/git.py @@ -7,7 +7,7 @@ from semver import VersionInfo from ..fs import chdir -from ..subprocess import run_command +from ..subprocess import SubprocessResult, run_command from .constants import get_root @@ -144,6 +144,17 @@ def git_tag(tag_name, push=False): return result +def git_fetch(remote: str = 'origin', tags: bool = False) -> SubprocessResult: + """ + Fetch all tags from the remote + """ + with chdir(get_root()): + cmd = ['git', 'fetch', remote] + if tags: + cmd.append('--tags') + return run_command(cmd, capture=True) + + def git_tag_list(pattern=None, contains=None): """ Return a list of all the tags in the git repo matching a regex passed in diff --git a/datadog_checks_dev/tests/tooling/test_git.py b/datadog_checks_dev/tests/tooling/test_git.py index f89c2626db7cc..dcd78b8a4082f 100644 --- a/datadog_checks_dev/tests/tooling/test_git.py +++ b/datadog_checks_dev/tests/tooling/test_git.py @@ -2,6 +2,7 @@ # All rights reserved # Licensed under a 3-clause BSD style license (see LICENSE) import mock +import pytest from datadog_checks.dev.tooling.constants import set_root from datadog_checks.dev.tooling.git import ( @@ -9,6 +10,7 @@ get_commits_since, get_current_branch, git_commit, + git_fetch, git_show_file, git_tag, git_tag_list, @@ -200,3 +202,20 @@ def test_tracked_by_git(): tracked_by_git('bar') chdir.assert_called_once_with('/foo/') run.assert_called_once_with('git ls-files --error-unmatch bar', capture=True) + + +@pytest.mark.parametrize( + 'tags, expected_command', + [ + (True, ['git', 'fetch', 'origin', '--tags']), + (False, ['git', 'fetch', 'origin']), + ], + ids=['with_tags', 'without_tags'], +) +def test_git_fetch(tags: bool, expected_command: list[str]): + with mock.patch('datadog_checks.dev.tooling.git.chdir') as chdir: + with mock.patch('datadog_checks.dev.tooling.git.run_command') as run: + set_root('/foo/') + git_fetch(tags=tags) + chdir.assert_called_once_with('/foo/') + run.assert_called_once_with(expected_command, capture=True) From bdeb116c5836ac4a1ff5727d1d7e2da50c3b3941 Mon Sep 17 00:00:00 2001 From: Juanpe Araque Date: Wed, 14 May 2025 15:48:15 +0200 Subject: [PATCH 2/3] Add changelog info --- datadog_checks_dev/changelog.d/20292.added | 1 + 1 file changed, 1 insertion(+) create mode 100644 datadog_checks_dev/changelog.d/20292.added diff --git a/datadog_checks_dev/changelog.d/20292.added b/datadog_checks_dev/changelog.d/20292.added new file mode 100644 index 0000000000000..17627ebcbf850 --- /dev/null +++ b/datadog_checks_dev/changelog.d/20292.added @@ -0,0 +1 @@ +Update release tag to ensure that tags are fetched before getting the list of tags \ No newline at end of file From 76d1b3dfa03d00a8a80640a5d6835be19a0cbd73 Mon Sep 17 00:00:00 2001 From: Juanpe Araque Date: Fri, 23 May 2025 14:28:15 +0200 Subject: [PATCH 3/3] Remove manual build for log ints builder --- .gitlab-ci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3c40faa9fe46d..cfe1419cf349f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -159,9 +159,6 @@ validate-log-intgs-builder: - changes: - .gitlab/validate-logs-intgs/**/* - .gitlab-ci.yml - # Allow to manually trigger a build if we need to - - when: manual - allow_failure: true script: - cd .gitlab/validate-logs-intgs/ - docker buildx build --tag $VALIDATE_LOG_INTGS . --push