Skip to content
Merged
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
32 changes: 28 additions & 4 deletions script/release
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ die() {
branch=$(git rev-parse --abbrev-ref HEAD)
[ "$branch" = "$release_branch" ] || die "On $branch - releases are cut from $release_branch."

# The remote's tags before the fetch. The push below may only move the major
# tag from the object it has here, so a release that lands any time after this
# line makes the push fail instead of being overwritten.
remote_tags=$(git ls-remote --tags "$remote")

# --force because a run that failed mid-push leaves the local major tag moved
# ahead of the remote, and a plain fetch refuses to rewind it.
git fetch --tags --force "$remote" "$release_branch"
Expand Down Expand Up @@ -81,9 +86,19 @@ fi
echo -e "Latest release: ${BLUE}${latest_tag:-none}${OFF}"
echo -e "New release: ${BLUE}${new_tag}${OFF} at $(git log -1 --format='%h %s')"

# What the remote has right now, so the push can refuse to clobber a release
# someone else lands while this one sits at the prompt. Empty when absent.
major_remote=$(git ls-remote "$remote" "refs/tags/$major_tag" | cut -f1)
# The major tag as the remote had it before the fetch; empty when absent. Not a
# fresh ls-remote: that could pick up a release that landed after the checks
# above, and the push would then move the major tag back from it. Not the
# local tag either: a run that failed mid-push for a new major leaves a local
# tag the remote never had.
major_expected=$(awk -v ref="refs/tags/$major_tag" '$2 == ref { print $1 }' <<<"$remote_tags")

# A release that landed during the fetch: the checks and the tag shown below
# would describe it, not the state the lease holds.
if [ -n "$major_expected" ] &&
[ "$(git rev-parse -q --verify "refs/tags/$major_tag" || true)" != "$major_expected" ]; then
die "$major_tag changed on $remote while this release was starting - run script/release again."
fi

if git rev-parse -q --verify "refs/tags/$major_tag" >/dev/null; then
major_exists='yes'
Expand All @@ -99,6 +114,15 @@ echo 'Every workflow on the major tag picks this up immediately.'
read -r -p 'Tag and push? [y/N] ' reply || reply=''
[[ $reply =~ ^[Yy]$ ]] || die 'Aborted - nothing was tagged.'

# A release that landed while the prompt waited. The lease would refuse the
# push anyway; this stops before anything is tagged and says why.
# Only the exact line counts: an annotated tag can also list its peeled
# commit as refs/tags/vN^{}.
major_now=$(git ls-remote --tags "$remote" "refs/tags/$major_tag" |
awk -v ref="refs/tags/$major_tag" '$2 == ref { print $1 }')
[ "$major_now" = "$major_expected" ] ||
die "$major_tag changed on $remote since the checks ran - nothing was tagged. Run script/release again."

[ "$resuming" = 'yes' ] || git tag --annotate --message "$new_tag" "$new_tag"
git tag --annotate --force --message "Sync $major_tag with $new_tag" "$major_tag"

Expand All @@ -108,7 +132,7 @@ git tag --annotate --force --message "Sync $major_tag with $new_tag" "$major_tag
# The major tag deliberately carries no '+'. --force-with-lease does the
# forcing, and a '+' in the refspec forces unconditionally and silently
# bypasses the lease, which would make the guard below do nothing.
git push --atomic --force-with-lease="refs/tags/$major_tag:$major_remote" "$remote" \
git push --atomic --force-with-lease="refs/tags/$major_tag:$major_expected" "$remote" \
"refs/tags/$new_tag:refs/tags/$new_tag" \
"refs/tags/$major_tag:refs/tags/$major_tag"

Expand Down
Loading