This repository was archived by the owner on Apr 20, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
81 lines (70 loc) · 2.68 KB
/
auto-release.yml
File metadata and controls
81 lines (70 loc) · 2.68 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
name: Auto Release
on:
push:
branches:
- main
paths:
- 'pyproject.toml'
- 'CHANGELOG.md'
permissions:
contents: write # This is needed to create releases
jobs:
check-version-bump:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get-version.outputs.version }}
changelog: ${{ steps.get-changelog.outputs.changelog }}
should_release: ${{ steps.check-changes.outputs.should_release }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get version from pyproject.toml
id: get-version
run: |
VERSION=$(grep -m 1 "version = " pyproject.toml | sed 's/version = "\(.*\)"/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Current version: $VERSION"
- name: Get changelog entry
id: get-changelog
run: |
VERSION=$(grep -m 1 "version = " pyproject.toml | sed 's/version = "\(.*\)"/\1/')
CHANGELOG_ENTRY=$(awk -v ver="$VERSION" 'BEGIN{inSection=0} $0 ~ "^## \\["ver"\\]" {inSection=1; next} inSection==1 && $0 ~ "^## " {exit} inSection {print}' CHANGELOG.md | tr -d '\r')
echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG_ENTRY" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Check if this is a version bump commit
id: check-changes
run: |
# Check if commit message indicates a version bump
COMMIT_MSG=$(git log -1 --pretty=%B)
if [[ "$COMMIT_MSG" =~ [Bb][Uu][Mm][Pp]\ [Vv][Ee][Rr][Ss][Ii][Oo][Nn] ]]; then
echo "should_release=true" >> $GITHUB_OUTPUT
echo "Version bump detected, should create release"
else
echo "should_release=false" >> $GITHUB_OUTPUT
echo "Not a version bump commit"
fi
create-release:
needs: check-version-bump
if: needs.check-version-bump.outputs.should_release == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ needs.check-version-bump.outputs.version }}
release_name: Release v${{ needs.check-version-bump.outputs.version }}
body: ${{ needs.check-version-bump.outputs.changelog }}
draft: false
prerelease: false
- name: Output Release Status
run: echo "Release for v${{ needs.check-version-bump.outputs.version }} created successfully"