-
Notifications
You must be signed in to change notification settings - Fork 27
54 lines (45 loc) · 1.6 KB
/
create-release.yml
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
name: Create Release
on:
push:
branches: [main]
jobs:
create_release:
if: startsWith(github.event.head_commit.message, 'new version')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract version from commit message
run: |
# Get the version from the commit message using a regex
if [[ "${{ github.event.head_commit.message }}" =~ new\ version\ ([0-9]+\.[0-9]+\.[0-9]+) ]]; then
echo "version=${BASH_REMATCH[1]}" >> $GITHUB_ENV
else
echo "Commit message does not match 'new version *.*.*' format."
exit 1
fi
- name: Get previous tag
run: |
previous_tag=$(git describe --tags --abbrev=0 HEAD^)
echo "previous_tag=$previous_tag" >> $GITHUB_ENV
- name: Generate release notes with commit messages
run: |
commits=$(git log "${{ env.previous_tag }}..HEAD" --oneline)
echo "release_body<<EOF" >> $GITHUB_ENV
echo "### Changelog from version ${{ env.previous_tag }} to ${{ env.version }}:" >> $GITHUB_ENV
echo "$commits" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Create GitHub release
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: "${{ env.version }}"
release_name: "${{ env.version }}"
body: "${{ env.release_body }}"
draft: false
prerelease: false