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
26 changes: 16 additions & 10 deletions scripts/tag-version.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
#!/bin/bash

git fetch --tags
# Fail the step if the tag cannot be created or pushed. Without this, a rejected
# `git push` still exits 0 and the release step goes on to use a tag that was
# never created.
Comment on lines +3 to +5
set -eo pipefail

# Get the latest tag
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`)
git fetch --tags --force

# Check if the latest tag starts with 'v' and remove it
if [[ $latest_tag == v* ]]; then
latest_tag=${latest_tag:1}
# Highest released version, chosen by version order rather than by "whichever tag
# git describe finds on the newest tagged commit".
latest_tag=$(git tag -l '[0-9]*.[0-9]*.[0-9]*' | sort -V | tail -1)

if [[ -z $latest_tag ]]; then
echo "No version tag found; refusing to guess the next version" >&2
exit 1
fi
Comment on lines +12 to 17

# Split the latest tag into an array
Expand All @@ -17,9 +23,9 @@ IFS='.' read -r -a version_parts <<< "$latest_tag"
new_tag="${version_parts[0]}.${version_parts[1]}.$((version_parts[2] + 1))"

# Create and push the new tag
git tag $new_tag
git push origin $new_tag
git tag "$new_tag"
git push origin "$new_tag"
echo "new_tag=$new_tag"

echo "new_tag=$new_tag" >> $GITHUB_OUTPUT
echo "NEW_TAG=$new_tag" >> $GITHUB_ENV
echo "new_tag=$new_tag" >> "$GITHUB_OUTPUT"
echo "NEW_TAG=$new_tag" >> "$GITHUB_ENV"