44 push :
55 tags :
66 - ' v[0-9]*'
7+ workflow_dispatch :
8+ inputs :
9+ tag :
10+ description : ' Existing tag to create or update a GitHub Release for (e.g. v0.2.2)'
11+ required : true
12+ type : string
713
814permissions :
915 contents : write
1218 release :
1319 name : Create GitHub Release
1420 runs-on : ubuntu-latest
21+ env :
22+ RELEASE_TAG : ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag || github.ref_name }}
1523 steps :
24+ - name : Validate release tag
25+ if : github.event_name == 'workflow_dispatch'
26+ run : |
27+ set -euo pipefail
28+ tag="${{ github.event.inputs.tag }}"
29+ if [[ ! "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
30+ echo "tag must look like vX.Y.Z, got: $tag" >&2
31+ exit 1
32+ fi
33+ git ls-remote --exit-code origin "refs/tags/${tag}" >/dev/null
34+
1635 - uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
36+ with :
37+ ref : ${{ env.RELEASE_TAG }}
1738
1839 - uses : actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
1940 with :
@@ -23,15 +44,15 @@ jobs:
2344 id : meta
2445 run : |
2546 pkg_name=$(python -c "import tomllib,pathlib; print(tomllib.loads(pathlib.Path('pyproject.toml').read_text())['project']['name'])")
26- pkg_version="${GITHUB_REF_NAME #v}"
47+ pkg_version="${RELEASE_TAG #v}"
2748 echo "name=${pkg_name}" >> "$GITHUB_OUTPUT"
2849 echo "version=${pkg_version}" >> "$GITHUB_OUTPUT"
2950
3051 - name : Extract changelog notes
3152 id : notes
3253 run : |
3354 set -euo pipefail
34- version="${GITHUB_REF_NAME #v}"
55+ version="${RELEASE_TAG #v}"
3556 if [[ -f CHANGELOG.md ]]; then
3657 body="$(python scripts/extract-changelog.py "$version")"
3758 else
4768 - name : Create GitHub Release
4869 uses : softprops/action-gh-release@da05d552573ad5aba039eaac05058a918a7bf631 # v2.2.2
4970 with :
50- tag_name : ${{ github.ref_name }}
71+ tag_name : ${{ env.RELEASE_TAG }}
5172 name : ${{ steps.meta.outputs.name }} ${{ steps.meta.outputs.version }}
5273 body : ${{ steps.notes.outputs.body }}
5374 generate_release_notes : false
0 commit comments