-
Notifications
You must be signed in to change notification settings - Fork 2
68 lines (58 loc) · 2 KB
/
release.yml
File metadata and controls
68 lines (58 loc) · 2 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
64
65
66
67
68
name: Release
on:
push:
tags:
- 'v*'
# The workflow creates a GitHub Release, so it needs write access to contents.
permissions:
contents: write
jobs:
release:
name: Publish GitHub Release
runs-on: ubuntu-latest
steps:
- name: Checkout (full history)
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract version from tag
id: version
run: |
TAG="${GITHUB_REF#refs/tags/}"
VERSION="${TAG#v}"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
# Treat any tag like v1.2.3-* (rc, alpha, beta, etc.) as a pre-release
if [[ "$VERSION" == *"-"* ]]; then
echo "prerelease=true" >> "$GITHUB_OUTPUT"
else
echo "prerelease=false" >> "$GITHUB_OUTPUT"
fi
echo "Releasing tag ${TAG} (version ${VERSION})"
- name: Extract release notes from CHANGELOG.md
run: |
VERSION='${{ steps.version.outputs.version }}'
awk -v ver="$VERSION" '
/^## \[/ {
if (in_section) { exit }
if (index($0, "[" ver "]") > 0) { in_section = 1; next }
}
in_section { print }
' CHANGELOG.md > release_notes.md
if [[ ! -s release_notes.md ]]; then
echo "::error::No section '## [${VERSION}]' found in CHANGELOG.md"
echo "Available sections:"
grep -E '^## \[' CHANGELOG.md || true
exit 1
fi
echo "--- release_notes.md preview ---"
cat release_notes.md
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "${{ steps.version.outputs.tag }}" \
--title "${{ steps.version.outputs.tag }}" \
--notes-file release_notes.md \
${{ steps.version.outputs.prerelease == 'true' && '--prerelease' || '' }} \
--verify-tag