-
Notifications
You must be signed in to change notification settings - Fork 0
67 lines (58 loc) · 1.97 KB
/
release.yml
File metadata and controls
67 lines (58 loc) · 1.97 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
name: Release on Tag Push
on:
push:
tags:
- 'v*'
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Extract version from tag
id: version
run: echo "tag=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT"
- name: Extract changelog for this version
id: changelog
run: |
TAG="${{ steps.version.outputs.tag }}"
# Extract the section for this tag from changelog
# Matches from "## vX.Y.Z" (with optional suffix) to the next "## " or EOF
BODY=$(awk -v tag="$TAG" '
BEGIN { found=0 }
/^## / {
if (found) exit
# Match the tag, allowing optional suffix after version (e.g. "- Breaking change")
header=$2
# Remove trailing characters after version pattern
gsub(/[^v0-9.].*/, "", header)
if (header == tag) { found=1; next }
}
found { print }
' docs/changelog.md)
# Fail if no changelog found
if [ -z "$BODY" ]; then
echo "::warning::No changelog entry found for $TAG, using default message"
BODY="Release $TAG"
fi
# Write to file to preserve multiline content
echo "$BODY" > /tmp/release-body.md
- name: Delete existing release if present
run: |
TAG="${{ steps.version.outputs.tag }}"
if gh release view "$TAG" &>/dev/null; then
echo "Deleting existing release for $TAG"
gh release delete "$TAG" --yes
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create GitHub Release
run: |
TAG="${{ steps.version.outputs.tag }}"
gh release create "$TAG" \
--title "$TAG" \
--notes-file /tmp/release-body.md
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}