Skip to content

Commit d9669c5

Browse files
committed
ci: add release workflow
1 parent ae815f9 commit d9669c5

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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') }}

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Changelog
2+
3+
All notable changes to this project are documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## v1.0.0-rc.1
9+
10+
Initial release candidate for version 1.0.0.

0 commit comments

Comments
 (0)