From 281be56f98e8bd5205867cb4a59b4eca05e9b1b1 Mon Sep 17 00:00:00 2001 From: PJ Date: Sun, 6 Sep 2026 13:54:39 +0530 Subject: [PATCH] validate release versions and tolerate an already-landed tag push --- .github/workflows/release.yml | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3079aa3..af58a99 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,6 +11,10 @@ on: permissions: contents: write +concurrency: + group: release + cancel-in-progress: false + jobs: prepare: runs-on: ubuntu-latest @@ -20,18 +24,31 @@ jobs: release_id: ${{ steps.release.outputs.release_id }} steps: - uses: actions/checkout@v7 + with: + ref: main - name: Determine version id: version + env: + REQUESTED_VERSION: ${{ inputs.version }} run: | - if [ -n "${{ inputs.version }}" ]; then - VERSION="${{ inputs.version }}" + if [ -n "$REQUESTED_VERSION" ]; then + VERSION="$REQUESTED_VERSION" VERSION="${VERSION#v}" else CURRENT=$(jq -r .version src-tauri/tauri.conf.json) IFS=. read -r MAJOR MINOR PATCH <<< "$CURRENT" VERSION="$MAJOR.$MINOR.$((PATCH + 1))" fi + if ! [[ "$VERSION" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then + echo "::error::Expected a release version such as 0.2.0." + exit 1 + fi + EXISTING=$(git ls-remote --tags origin "refs/tags/v$VERSION") + if [ -n "$EXISTING" ]; then + echo "::error::v$VERSION already exists; choose a new version." + exit 1 + fi echo "version=$VERSION" >> "$GITHUB_OUTPUT" echo "tag=v$VERSION" >> "$GITHUB_OUTPUT" echo "Releasing v$VERSION" @@ -73,7 +90,12 @@ jobs: sleep 3 done git tag "$TAG" - git push origin "$TAG" + if ! git push origin "$TAG"; then + # A push can land remotely even when Git reports a ref-lock failure. + # Accept only this exact commit; never move an existing release tag. + REMOTE=$(git ls-remote --tags origin "refs/tags/$TAG" | cut -f1) + [ "$REMOTE" = "$(git rev-parse HEAD)" ] || exit 1 + fi - name: Create draft release id: release