Skip to content

Ensure ddev release tag fetches tags before getting the full list #20292

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

Merged
merged 4 commits into from
May 23, 2025
Merged
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
38 changes: 24 additions & 14 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,27 +128,37 @@ 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
script:
- cd .gitlab/validate-logs-intgs/
- docker buildx build --tag $VALIDATE_LOG_INTGS . --push
Expand Down
1 change: 1 addition & 0 deletions datadog_checks_dev/changelog.d/20292.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update release tag to ensure that tags are fetched before getting the list of tags
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.

Expand All @@ -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'

Expand 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:
Expand Down
13 changes: 12 additions & 1 deletion datadog_checks_dev/datadog_checks/dev/tooling/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions datadog_checks_dev/tests/tooling/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
# 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 (
files_changed,
get_commits_since,
get_current_branch,
git_commit,
git_fetch,
git_show_file,
git_tag,
git_tag_list,
Expand Down Expand Up @@ -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)
Loading