|
| 1 | +name: Release |
| 2 | + |
| 3 | +# Publishing to npm stays local (`npm run release`, using the maintainer's |
| 4 | +# 2FA). That command pushes a `vX.Y.Z` tag, which triggers this workflow to |
| 5 | +# create the matching GitHub Release from the CHANGELOG entry. |
| 6 | +on: |
| 7 | + push: |
| 8 | + tags: |
| 9 | + - 'v*' |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + github-release: |
| 16 | + name: Create GitHub Release |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v7 |
| 20 | + |
| 21 | + - name: Extract changelog notes for this tag |
| 22 | + run: | |
| 23 | + VERSION="${GITHUB_REF_NAME#v}" |
| 24 | + # Pull the section between "## <version> (...)" and the next "## ". |
| 25 | + # index()==1 matches the literal header start, so no regex escaping |
| 26 | + # of the version's dots is needed. |
| 27 | + awk -v h="## ${VERSION} (" ' |
| 28 | + index($0, h) == 1 { f = 1; next } |
| 29 | + f && /^## / { exit } |
| 30 | + f { print } |
| 31 | + ' CHANGELOG.md > release-notes.md |
| 32 | + # Fall back to a pointer if the version has no changelog section. |
| 33 | + if [ ! -s release-notes.md ]; then |
| 34 | + echo "See [CHANGELOG.md](https://github.com/${GITHUB_REPOSITORY}/blob/master/CHANGELOG.md)." > release-notes.md |
| 35 | + fi |
| 36 | + echo "----- release notes for ${VERSION} -----" |
| 37 | + cat release-notes.md |
| 38 | +
|
| 39 | + - name: Create release |
| 40 | + env: |
| 41 | + GH_TOKEN: ${{ github.token }} |
| 42 | + run: | |
| 43 | + # Mark tags containing a hyphen (e.g. v1.7.0-beta.0) as prereleases. |
| 44 | + case "$GITHUB_REF_NAME" in |
| 45 | + *-*) PRERELEASE="--prerelease" ;; |
| 46 | + *) PRERELEASE="" ;; |
| 47 | + esac |
| 48 | + gh release create "$GITHUB_REF_NAME" \ |
| 49 | + --repo "$GITHUB_REPOSITORY" \ |
| 50 | + --title "$GITHUB_REF_NAME" \ |
| 51 | + --notes-file release-notes.md \ |
| 52 | + $PRERELEASE |
0 commit comments