Repository navigation
57 lines (51 loc) · 1.81 KB
/
Copy pathrelease.yml
File metadata and controls
57 lines (51 loc) · 1.81 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: [master]
paths:
- 'CHANGELOG.md'
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v7
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
if: steps.version.outputs.version != ''
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.version.outputs.version != '' && steps.check.outputs.exists == 'false'
id: notes
run: |
# Notes for this version: between the 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.version.outputs.version != '' && steps.check.outputs.exists == 'false'
# Notes go through an env var, never into the shell command, so changelog text cannot run as shell.
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 }}