update release workflow to catch forgotten version bumping

I forgot to bump the version to 0.1.8 in the last release but my workflows still ran and replaced the 0.1.7 files. Added a validation check and now refuses to release on an existing tag.
This commit is contained in:
Golumpa 2026-06-23 15:14:20 +01:00
parent 5e46502ee3
commit 2188e62d4b

View file

@ -7,9 +7,38 @@ permissions:
contents: write contents: write
jobs: jobs:
validate-release:
name: Validate Release
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Checkout Source Code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Check release tag is new
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
version="$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")"
tag="v${version}"
if git rev-parse -q --verify "refs/tags/${tag}" >/dev/null; then
echo "::error title=Release tag already exists::${tag} already exists. Bump project.version in pyproject.toml before running the release workflow."
exit 1
fi
if gh release view "$tag" >/dev/null 2>&1; then
echo "::error title=GitHub release already exists::${tag} already has a GitHub release. Bump project.version in pyproject.toml before running the release workflow."
exit 1
fi
build-windows: build-windows:
name: Build Windows name: Build Windows
if: github.ref == 'refs/heads/main' if: github.ref == 'refs/heads/main'
needs: validate-release
runs-on: windows-latest runs-on: windows-latest
steps: steps:
@ -44,6 +73,7 @@ jobs:
build-linux: build-linux:
name: Build Linux name: Build Linux
if: github.ref == 'refs/heads/main' if: github.ref == 'refs/heads/main'
needs: validate-release
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
@ -81,6 +111,7 @@ jobs:
build-macos: build-macos:
name: Build Macos name: Build Macos
if: github.ref == 'refs/heads/main' if: github.ref == 'refs/heads/main'
needs: validate-release
runs-on: macos-15-intel runs-on: macos-15-intel
steps: steps:
@ -195,9 +226,14 @@ jobs:
nte-history-exporter-v${version}-x86_64-apple-darwin.zip nte-history-exporter-v${version}-x86_64-apple-darwin.zip
) )
if gh release view "$tag" >/dev/null 2>&1; then if git rev-parse -q --verify "refs/tags/${tag}" >/dev/null; then
gh release edit "$tag" --notes-file release-notes.md echo "::error title=Release tag already exists::${tag} already exists. Bump project.version in pyproject.toml before running the release workflow."
gh release upload "$tag" "${files[@]}" --clobber exit 1
else
gh release create "$tag" "${files[@]}" --title "${tag} Release" --notes-file release-notes.md
fi fi
if gh release view "$tag" >/dev/null 2>&1; then
echo "::error title=GitHub release already exists::${tag} already has a GitHub release. Bump project.version in pyproject.toml before running the release workflow."
exit 1
fi
gh release create "$tag" "${files[@]}" --title "${tag} Release" --notes-file release-notes.md