Skip to content

Commit a2933bd

Browse files
ci: add tag-based GitHub release workflow
1 parent 87ec9ed commit a2933bd

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
workflow_dispatch:
8+
inputs:
9+
tag:
10+
description: "Existing tag to release, for example v1.4.0"
11+
required: true
12+
type: string
13+
14+
permissions:
15+
contents: write
16+
17+
jobs:
18+
github-release:
19+
runs-on: ubuntu-latest
20+
env:
21+
RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}
22+
steps:
23+
- name: Checkout repo
24+
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
28+
- name: Extract release notes
29+
run: |
30+
TAG="${RELEASE_TAG}"
31+
git rev-parse "$TAG" >/dev/null
32+
awk -v tag="$TAG" '
33+
index($0, "## [" tag "]") == 1 { found = 1; next }
34+
found && /^## \[/ { exit }
35+
found { print }
36+
' changelog.md > release_notes.md
37+
38+
if [ ! -s release_notes.md ]; then
39+
echo "Release $TAG" > release_notes.md
40+
fi
41+
42+
- name: Create or update GitHub release
43+
env:
44+
GH_TOKEN: ${{ github.token }}
45+
run: |
46+
TAG="${RELEASE_TAG}"
47+
if gh release view "$TAG" >/dev/null 2>&1; then
48+
gh release edit "$TAG" --title "$TAG" --notes-file release_notes.md
49+
else
50+
gh release create "$TAG" --title "$TAG" --notes-file release_notes.md
51+
fi

0 commit comments

Comments
 (0)