Skip to content

Commit 2cee007

Browse files
release: Make the tag step safe to retry in both release files
Copies the tag step from release.yaml (#1449) to batch-change/release.yaml: keep a tag which already points at the promote commit, and fail if it points anywhere else. Both files now create the release branch with git switch -C, so a retry in a checkout which kept the branch from the first attempt no longer fails. Amp-Thread-ID: https://ampcode.com/threads/T-01a1c7a5-6b65-723b-980c-b85e1e9008b5 Co-authored-by: Amp <amp@ampcode.com>
1 parent e7c0864 commit 2cee007

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

‎batch-change/release.yaml‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,18 @@ promoteToPublic:
136136
137137
# Create the final branch holding the tagged commit
138138
git checkout "${promote_branch}"
139-
git switch -c "${release_branch}"
140-
141-
git tag {{version}}
139+
git switch -C "${release_branch}"
140+
141+
# A retried finalize finds its own tag; only a tag elsewhere is an error
142+
if tagged=$(git rev-parse -q --verify "refs/tags/{{version}}^{commit}"); then
143+
if [ "${tagged}" != "$(git rev-parse HEAD)" ]; then
144+
echo "Tag {{version}} already exists at ${tagged}, not at ${promote_branch} ($(git rev-parse HEAD))" >&2
145+
exit 1
146+
fi
147+
echo "Tag {{version}} already points at ${promote_branch}, not recreating it"
148+
else
149+
git tag {{version}}
150+
fi
142151
git push origin ${release_branch} --tags
143152
144153
# Web URL to the tag

‎release.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ promoteToPublic:
199199
200200
# Create the final branch holding the tagged commit
201201
git checkout "${promote_branch}"
202-
git switch -c "${release_branch}"
202+
git switch -C "${release_branch}"
203203
204204
# A retried finalize finds its own tag; only a tag elsewhere is an error
205205
if tagged=$(git rev-parse -q --verify "refs/tags/{{version}}^{commit}"); then

0 commit comments

Comments
 (0)