-
Notifications
You must be signed in to change notification settings - Fork 0
63 lines (55 loc) · 1.82 KB
/
Copy pathrelease.yml
File metadata and controls
63 lines (55 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Create a GitHub Release when a version tag is pushed.
#
# Release notes are extracted from CHANGELOG.md for the tagged version.
# Falls back to auto-generated notes if the version isn't found in CHANGELOG.md.
name: Release
on:
push:
tags:
- 'v*'
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract release notes from CHANGELOG.md
id: notes
run: |
VERSION="${GITHUB_REF_NAME#v}"
# Extract the section for this version from CHANGELOG.md.
# Matches from "## [VERSION]" up to (but excluding) the next "## [".
NOTES=$(awk -v ver="$VERSION" '
/^## \[/ {
if (found) exit
if (index($0, "[" ver "]")) { found=1; next }
}
found { print }
' CHANGELOG.md)
if [ -z "$NOTES" ]; then
echo "found=false" >> "$GITHUB_OUTPUT"
else
echo "found=true" >> "$GITHUB_OUTPUT"
# Write multi-line notes to file for gh release
echo "$NOTES" > /tmp/release-notes.md
fi
- name: Create GitHub Release (with changelog notes)
if: steps.notes.outputs.found == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "${{ github.ref_name }}" \
--title "${{ github.ref_name }}" \
--notes-file /tmp/release-notes.md
- name: Create GitHub Release (auto-generated notes)
if: steps.notes.outputs.found != 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "${{ github.ref_name }}" \
--title "${{ github.ref_name }}" \
--generate-notes