Skip to content

Commit c0e94d6

Browse files
authored
Ensure ddev release tag fetches tags before getting the full list (#20292)
* Ensure ddev release tag fetches tags before getting the full list of tags * Add changelog info * Remove manual build for log ints builder
1 parent d10b952 commit c0e94d6

File tree

5 files changed

+73
-17
lines changed

5 files changed

+73
-17
lines changed

.gitlab-ci.yml

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,27 +128,37 @@ release-manual:
128128
tagger-image-builder:
129129
stage: build
130130
image: 486234852809.dkr.ecr.us-east-1.amazonaws.com/docker:24.0.4-gbi-focal
131-
only:
132-
changes:
133-
- .gitlab/tagger/**/*
134-
- ddev/**/*
135-
- .gitlab-ci.yml
136-
refs:
137-
- master
131+
rules:
132+
- if: $CI_PIPELINE_SOURCE == 'schedule'
133+
when: never
134+
- if: $CI_COMMIT_TAG
135+
when: never
136+
- if: $CI_COMMIT_BRANCH == 'master'
137+
when: always
138+
- changes:
139+
- .gitlab/tagger/**/*
140+
- ddev/**/*
141+
- .gitlab-ci.yml
142+
# Allow to manually trigger a build if we need to
143+
- when: manual
144+
allow_failure: true
138145
script:
139146
- docker buildx build --tag $TAGGER_IMAGE -f .gitlab/tagger/Dockerfile . --push
140-
except: [ tags, schedules ]
141147
tags: [ "arch:amd64" ]
142148

143149
validate-log-intgs-builder:
144150
stage: build
145151
image: 486234852809.dkr.ecr.us-east-1.amazonaws.com/docker:24.0.4-gbi-focal
146-
only:
147-
changes:
148-
- .gitlab/validate-logs-intgs/**/*
149-
- .gitlab-ci.yml
150-
refs:
151-
- master
152+
rules:
153+
- if: $CI_PIPELINE_SOURCE == 'schedule'
154+
when: never
155+
- if: $CI_COMMIT_TAG
156+
when: never
157+
- if: $CI_COMMIT_BRANCH == 'master'
158+
when: always
159+
- changes:
160+
- .gitlab/validate-logs-intgs/**/*
161+
- .gitlab-ci.yml
152162
script:
153163
- cd .gitlab/validate-logs-intgs/
154164
- docker buildx build --tag $VALIDATE_LOG_INTGS . --push
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update release tag to ensure that tags are fetched before getting the list of tags

datadog_checks_dev/datadog_checks/dev/tooling/commands/release/tag.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Licensed under a 3-clause BSD style license (see LICENSE)
44
import click
55

6-
from ...git import git_tag, git_tag_list
6+
from ...git import git_fetch, git_tag, git_tag_list
77
from ...release import get_release_tag_string
88
from ...utils import complete_valid_checks, get_valid_checks, get_version_string
99
from ..console import CONTEXT_SETTINGS, abort, echo_info, echo_success, echo_waiting, echo_warning
@@ -19,7 +19,8 @@
1919
@click.option('--push/--no-push', default=True)
2020
@click.option('--dry-run', '-n', is_flag=True)
2121
@click.option('--skip-prerelease', is_flag=True)
22-
def tag(check, version, push, dry_run, skip_prerelease):
22+
@click.option('--fetch/--no-fetch', default=True)
23+
def tag(check, version, push, dry_run, skip_prerelease, fetch):
2324
"""Tag the HEAD of the git repo with the current release number for a
2425
specific check. The tag is pushed to origin by default.
2526
@@ -28,6 +29,13 @@ def tag(check, version, push, dry_run, skip_prerelease):
2829
Notice: specifying a different version than the one in `__about__.py` is
2930
a maintenance task that should be run under very specific circumstances
3031
(e.g. re-align an old release performed on the wrong commit).
32+
33+
Return codes:
34+
0: Success
35+
1: Invalid command call
36+
2: Nothing to tag
37+
3: Failed to fetch tags
38+
Other: Git tag command returned a non-zero exit code
3139
"""
3240
tagging_all = check == 'all'
3341

@@ -44,6 +52,13 @@ def tag(check, version, push, dry_run, skip_prerelease):
4452

4553
# Check for any new tags
4654
tagged = False
55+
# Fetch all tags from the remote
56+
if fetch:
57+
echo_info('Fetching all tags from remote...')
58+
59+
if (result := git_fetch(tags=True)).code != 0:
60+
abort(f'Failed to fetch tags: {result.stderr}', 3)
61+
4762
existing_tags = git_tag_list()
4863

4964
for check in checks:

datadog_checks_dev/datadog_checks/dev/tooling/git.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from semver import VersionInfo
88

99
from ..fs import chdir
10-
from ..subprocess import run_command
10+
from ..subprocess import SubprocessResult, run_command
1111
from .constants import get_root
1212

1313

@@ -144,6 +144,17 @@ def git_tag(tag_name, push=False):
144144
return result
145145

146146

147+
def git_fetch(remote: str = 'origin', tags: bool = False) -> SubprocessResult:
148+
"""
149+
Fetch all tags from the remote
150+
"""
151+
with chdir(get_root()):
152+
cmd = ['git', 'fetch', remote]
153+
if tags:
154+
cmd.append('--tags')
155+
return run_command(cmd, capture=True)
156+
157+
147158
def git_tag_list(pattern=None, contains=None):
148159
"""
149160
Return a list of all the tags in the git repo matching a regex passed in

datadog_checks_dev/tests/tooling/test_git.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
# All rights reserved
33
# Licensed under a 3-clause BSD style license (see LICENSE)
44
import mock
5+
import pytest
56

67
from datadog_checks.dev.tooling.constants import set_root
78
from datadog_checks.dev.tooling.git import (
89
files_changed,
910
get_commits_since,
1011
get_current_branch,
1112
git_commit,
13+
git_fetch,
1214
git_show_file,
1315
git_tag,
1416
git_tag_list,
@@ -200,3 +202,20 @@ def test_tracked_by_git():
200202
tracked_by_git('bar')
201203
chdir.assert_called_once_with('/foo/')
202204
run.assert_called_once_with('git ls-files --error-unmatch bar', capture=True)
205+
206+
207+
@pytest.mark.parametrize(
208+
'tags, expected_command',
209+
[
210+
(True, ['git', 'fetch', 'origin', '--tags']),
211+
(False, ['git', 'fetch', 'origin']),
212+
],
213+
ids=['with_tags', 'without_tags'],
214+
)
215+
def test_git_fetch(tags: bool, expected_command: list[str]):
216+
with mock.patch('datadog_checks.dev.tooling.git.chdir') as chdir:
217+
with mock.patch('datadog_checks.dev.tooling.git.run_command') as run:
218+
set_root('/foo/')
219+
git_fetch(tags=tags)
220+
chdir.assert_called_once_with('/foo/')
221+
run.assert_called_once_with(expected_command, capture=True)

0 commit comments

Comments
 (0)