-
Notifications
You must be signed in to change notification settings - Fork 1
57 lines (51 loc) · 1.74 KB
/
Copy pathrelease.yml
File metadata and controls
57 lines (51 loc) · 1.74 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
name: Release
on:
push:
branches: [main]
paths:
- 'CHANGELOG.md'
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get version from CHANGELOG
id: version
run: |
VERSION=$(grep -m1 '^### ' CHANGELOG.md | sed 's/### \([0-9.]*\).*/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Found version: $VERSION"
- name: Check if release exists
id: check
run: |
if gh release view "v${{ steps.version.outputs.version }}" > /dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
env:
GH_TOKEN: ${{ github.token }}
- name: Extract release notes
if: steps.check.outputs.exists == 'false'
id: notes
run: |
# Extract notes for this version (between first and second ### headers)
NOTES=$(awk '/^### [0-9]/{if(p) exit; p=1; next} p' CHANGELOG.md)
echo "notes<<EOF" >> $GITHUB_OUTPUT
echo "$NOTES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create release
if: steps.check.outputs.exists == 'false'
# Notes are passed through an env var, not interpolated into the shell command, so
# changelog content can never be executed as shell syntax.
run: |
gh release create "v${{ steps.version.outputs.version }}" \
--title "v${{ steps.version.outputs.version }}" \
--notes "$RELEASE_NOTES"
env:
GH_TOKEN: ${{ github.token }}
RELEASE_NOTES: ${{ steps.notes.outputs.notes }}