|
| 1 | +name: release |
| 2 | + |
| 3 | +# Triggered by pushing a semver tag (e.g. v1.2.3 or v1.2.3-rc.1). The job pulls |
| 4 | +# the matching section out of CHANGELOG.md and publishes it as a draft GitHub |
| 5 | +# Release, attaching the auto-generated source code archives. |
| 6 | +on: |
| 7 | + push: |
| 8 | + tags: |
| 9 | + - "v[0-9]+.[0-9]+.[0-9]+" |
| 10 | + - "v[0-9]+.[0-9]+.[0-9]+-*" |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + release: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + |
| 21 | + # Pull the notes for this tag out of CHANGELOG.md. We match the heading |
| 22 | + # whose version equals the tag without the leading "v" (so tag v1.2.3 maps |
| 23 | + # to a "## [1.2.3]" / "## 1.2.3" heading) and emit everything up to the |
| 24 | + # next "## " heading. If no section is found we fall back to a generic note |
| 25 | + # rather than failing the release. |
| 26 | + - name: Extract release notes |
| 27 | + id: notes |
| 28 | + run: | |
| 29 | + version="${GITHUB_REF_NAME#v}" |
| 30 | + notes_file="$(mktemp)" |
| 31 | + awk -v ver="$version" ' |
| 32 | + $0 ~ "^## " { |
| 33 | + if (found) exit |
| 34 | + heading = $0 |
| 35 | + gsub(/[][]/, "", heading) |
| 36 | + if (index(heading, ver)) { found = 1; next } |
| 37 | + } |
| 38 | + found { print } |
| 39 | + ' CHANGELOG.md > "$notes_file" |
| 40 | +
|
| 41 | + if [ ! -s "$notes_file" ]; then |
| 42 | + printf 'Release %s\n' "$GITHUB_REF_NAME" > "$notes_file" |
| 43 | + fi |
| 44 | +
|
| 45 | + echo "file=$notes_file" >> "$GITHUB_OUTPUT" |
| 46 | +
|
| 47 | + - name: Create GitHub Release |
| 48 | + uses: softprops/action-gh-release@v2 |
| 49 | + with: |
| 50 | + name: ${{ github.ref_name }} |
| 51 | + body_path: ${{ steps.notes.outputs.file }} |
| 52 | + draft: true |
| 53 | + # Mark as prerelease when the tag carries an rc/alpha/beta suffix. |
| 54 | + prerelease: ${{ contains(github.ref_name, '-rc') || contains(github.ref_name, '-alpha') || contains(github.ref_name, '-beta') }} |
0 commit comments