GitHub Release #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: GitHub Release | |
| on: | |
| push: | |
| tags: | |
| - 'v[0-9]*' | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: 'Existing tag to create or update a GitHub Release for (e.g. v0.2.2)' | |
| required: true | |
| type: string | |
| permissions: | |
| contents: write | |
| jobs: | |
| release: | |
| name: Create GitHub Release | |
| runs-on: ubuntu-latest | |
| env: | |
| RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag || github.ref_name }} | |
| steps: | |
| - name: Validate release tag format | |
| if: github.event_name == 'workflow_dispatch' | |
| run: | | |
| set -euo pipefail | |
| tag="${{ github.event.inputs.tag }}" | |
| if [[ ! "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| echo "tag must look like vX.Y.Z, got: $tag" >&2 | |
| exit 1 | |
| fi | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | |
| with: | |
| ref: ${{ env.RELEASE_TAG }} | |
| fetch-depth: 0 | |
| - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6 | |
| with: | |
| python-version: '3.12' | |
| - name: Read package metadata | |
| id: meta | |
| run: | | |
| pkg_name=$(python -c "import tomllib,pathlib; print(tomllib.loads(pathlib.Path('pyproject.toml').read_text())['project']['name'])") | |
| pkg_version="${RELEASE_TAG#v}" | |
| echo "name=${pkg_name}" >> "$GITHUB_OUTPUT" | |
| echo "version=${pkg_version}" >> "$GITHUB_OUTPUT" | |
| - name: Extract changelog notes | |
| id: notes | |
| run: | | |
| set -euo pipefail | |
| version="${RELEASE_TAG#v}" | |
| if [[ -f CHANGELOG.md ]]; then | |
| body="$(python scripts/extract-changelog.py "$version")" | |
| else | |
| body="Release ${version}." | |
| fi | |
| delimiter="EOF_${RANDOM}_${RANDOM}" | |
| { | |
| echo "body<<${delimiter}" | |
| echo "$body" | |
| echo "${delimiter}" | |
| } >> "$GITHUB_OUTPUT" | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@da05d552573ad5aba039eaac05058a918a7bf631 # v2.2.2 | |
| with: | |
| tag_name: ${{ env.RELEASE_TAG }} | |
| name: ${{ steps.meta.outputs.name }} ${{ steps.meta.outputs.version }} | |
| body: ${{ steps.notes.outputs.body }} | |
| generate_release_notes: false | |
| make_latest: true |