Skip to content

Commit 1f6006f

Browse files
Add release workflow triggered on version tags
1 parent 56cb04b commit 1f6006f

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

.github/workflows/release.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags: ["v*"]
6+
7+
jobs:
8+
create-release:
9+
name: Create Release
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
steps:
14+
- uses: actions/checkout@v6
15+
16+
- name: Create Release
17+
env:
18+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19+
run: |
20+
TAG="${{ github.ref_name }}"
21+
22+
# Extract changelog section for this version
23+
CHANGELOG=$(awk -v tag="$TAG" '
24+
BEGIN { found=0 }
25+
/^# / {
26+
if (found) exit
27+
if ($0 == "# " tag) { found=1; next }
28+
}
29+
found { print }
30+
' CHANGELOG.md | sed '/./,$!d' | sed -e :a -e '/^\n*$/{$d;N;ba}')
31+
32+
if [ -z "$CHANGELOG" ]; then
33+
echo "::error::No changelog entry found for $TAG in CHANGELOG.md"
34+
exit 1
35+
fi
36+
37+
if gh release view "$TAG" > /dev/null 2>&1; then
38+
echo "Release $TAG already exists. Updating with changelog."
39+
printf '%s\n' "$CHANGELOG" > /tmp/release_body.md
40+
gh release edit "$TAG" --title "$TAG" --notes-file /tmp/release_body.md
41+
else
42+
printf '%s\n' "$CHANGELOG" > /tmp/release_body.md
43+
gh release create "$TAG" --verify-tag --title "$TAG" --notes-file /tmp/release_body.md
44+
fi

0 commit comments

Comments
 (0)