diff --git a/.github/scripts/compare-release-versions.sh b/.github/scripts/compare-release-versions.sh new file mode 100755 index 0000000000..9b697c30cc --- /dev/null +++ b/.github/scripts/compare-release-versions.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# Compare the semver tag against the current release in the VERSION file + +set -uo pipefail + +# Bail if VERSION cannot be found +if [[ ! -f version/VERSION ]]; then + echo "The VERSION file could not be found. Please create a VERSION file in the version/ directory. The contents of version should match the tag without the v prefix." + exit 1 +fi + +# Bail if the input was not a tag +if [[ ! "$GITHUB_REF_TYPE" == "tag" ]]; then + echo "This action only runs on tags. Please create a tag and try again." + exit 1 +fi + +# Create a clean semver tag without the v prefix +CLEAN_TAG=$(echo "$GITHUB_REF_NAME" | sed 's/^v//') + +VERSION=$(cat version/VERSION) +if [[ "$VERSION" != "$CLEAN_TAG" ]]; then + echo "The VERSION file does not match the tag. Please update the version/VERSION file to match the tag without the v prefix." + echo "The VERSION file contains: $VERSION but the tag is: $CLEAN_TAG." + exit 1 +fi + +echo "The VERSION file matches the tag. Proceeding with the release of $VERSION." diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4ad15135e6..726d8ec7ed 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -33,6 +33,9 @@ jobs: - name: Fetch tags run: git fetch --force --tags + - name: Compare versions + run: ./.github/scripts/compare-release-version.sh + - name: Determine Go version id: go uses: ./.github/actions/go-version