Skip to content

Commit 5a313de

Browse files
authored
Merge pull request #71 from hotdata-dev/ci/release-workflow-dispatch
ci: add manual GitHub Release workflow dispatch
2 parents 453f207 + 1e80ee5 commit 5a313de

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

.github/workflows/release.yml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ on:
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

814
permissions:
915
contents: write
@@ -12,8 +18,23 @@ jobs:
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
@@ -47,7 +68,7 @@ jobs:
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

RELEASING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ Pushing a `vX.Y.Z` tag triggers two workflows:
3434
| `publish.yml` | Build wheel/sdist and publish to PyPI |
3535
| `release.yml` | Create the GitHub Release with notes from `CHANGELOG.md` |
3636

37+
## Recover a missing GitHub Release
38+
39+
If PyPI publish succeeded but the GitHub Release workflow failed, rerun it from `main`
40+
without retagging:
41+
42+
```bash
43+
gh workflow run "GitHub Release" --ref main -f tag=vX.Y.Z
44+
```
45+
46+
The tag must already exist on the remote. The workflow checks out that tag, extracts the
47+
matching `CHANGELOG.md` section, and creates or updates the GitHub Release.
48+
3749
## Enforcement
3850

3951
- **PR check** (`check-release.yml`): if `pyproject.toml` version changes, `CHANGELOG.md` must contain a matching `## [X.Y.Z]` section.

0 commit comments

Comments
 (0)