diff --git a/.buildkite/pipeline.yaml b/.buildkite/pipeline.yaml index ed717ef6..655e1fe2 100644 --- a/.buildkite/pipeline.yaml +++ b/.buildkite/pipeline.yaml @@ -33,8 +33,11 @@ steps: command: | sg release run test --workdir=. --config-from-commit + # Promote jobs run only for the promote config commit. Creating the promote + # branch also builds its first commit, the internal config commit, which + # --config-from-commit would otherwise accept, running finalize twice. - label: "(promote) Release: test" - if: build.branch =~ /^promote\/release-.*/ && build.branch !~ /-update-main$/ + if: build.branch =~ /^promote\/release-.*/ && build.branch !~ /-update-main$/ && build.message =~ /^promote-release:/ plugins: - ssh://git@github.com/sourcegraph/sg-buildkite-plugin.git#main: ~ command: | @@ -57,7 +60,7 @@ steps: sg release run internal finalize --workdir=. --config-from-commit - label: "(promote) Release: finalize" - if: build.branch =~ /^promote\/release-.*/ && build.branch !~ /-update-main$/ + if: build.branch =~ /^promote\/release-.*/ && build.branch !~ /-update-main$/ && build.message =~ /^promote-release:/ plugins: - ssh://git@github.com/sourcegraph/sg-buildkite-plugin.git#main: ~ command: | diff --git a/release.yaml b/release.yaml index 8aebbbb8..ded54771 100644 --- a/release.yaml +++ b/release.yaml @@ -349,7 +349,16 @@ promoteToPublic: # Create the final branch holding the tagged commit git checkout "${promote_branch}" git switch -c "${release_branch}" - git tag {{version}} + # A retried finalize finds its own tag; only a tag elsewhere is an error + if tagged=$(git rev-parse -q --verify "refs/tags/{{version}}^{commit}"); then + if [ "${tagged}" != "$(git rev-parse HEAD)" ]; then + echo "Tag {{version}} already exists at ${tagged}, not at ${promote_branch} ($(git rev-parse HEAD))" >&2 + exit 1 + fi + echo "Tag {{version}} already points at ${promote_branch}, not recreating it" + else + git tag {{version}} + fi git push origin ${release_branch} --tags # Web URL to the tag