-
Notifications
You must be signed in to change notification settings - Fork 8
120 lines (102 loc) · 3.92 KB
/
release.yml
File metadata and controls
120 lines (102 loc) · 3.92 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: Release
on:
workflow_dispatch:
inputs:
prerelease:
description: "Mark as pre-release?"
required: false
default: false
type: boolean
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Read version from pyproject.toml
id: version
run: |
VERSION=$(grep -m1 '^version' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "Error: version '$VERSION' in pyproject.toml is not valid semver"
exit 1
fi
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
echo "TAG=v$VERSION" >> "$GITHUB_OUTPUT"
echo "Releasing $VERSION"
- name: Check tag does not already exist
run: |
TAG="${{ steps.version.outputs.TAG }}"
if git tag -l "$TAG" | grep -q "$TAG"; then
echo "Error: tag $TAG already exists — did you forget to bump the version in pyproject.toml?"
exit 1
fi
- name: Generate release notes
id: notes
run: |
TAG="${{ steps.version.outputs.TAG }}"
PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$PREV_TAG" ]; then
RANGE="HEAD"
SINCE_MSG="(all commits — first release)"
else
RANGE="${PREV_TAG}..HEAD"
SINCE_MSG="since $PREV_TAG"
fi
echo "Generating notes for $RANGE"
# Categorize commits by conventional commit prefix
FEATURES=$(git log $RANGE --pretty=format:"- %s (%h)" | grep -E "^- feat" | sed 's/^- feat[^:]*: /- /' || true)
FIXES=$(git log $RANGE --pretty=format:"- %s (%h)" | grep -E "^- fix" | sed 's/^- fix[^:]*: /- /' || true)
DOCS=$(git log $RANGE --pretty=format:"- %s (%h)" | grep -E "^- docs" | sed 's/^- docs[^:]*: /- /' || true)
REFACTORS=$(git log $RANGE --pretty=format:"- %s (%h)" | grep -E "^- refactor" | sed 's/^- refactor[^:]*: /- /' || true)
OTHER=$(git log $RANGE --pretty=format:"- %s (%h)" | grep -vE "^- (feat|fix|docs|refactor|chore|ci|test|style|perf|revert|Merge)" || true)
{
echo "NOTES<<EOF"
echo "## What's Changed $SINCE_MSG"
echo ""
if [ -n "$FEATURES" ]; then
echo "### Features"
echo "$FEATURES"
echo ""
fi
if [ -n "$FIXES" ]; then
echo "### Bug Fixes"
echo "$FIXES"
echo ""
fi
if [ -n "$DOCS" ]; then
echo "### Documentation"
echo "$DOCS"
echo ""
fi
if [ -n "$REFACTORS" ]; then
echo "### Refactoring"
echo "$REFACTORS"
echo ""
fi
if [ -n "$OTHER" ]; then
echo "### Other"
echo "$OTHER"
echo ""
fi
echo "**Full Changelog**: https://github.com/${{ github.repository }}/commits/$TAG"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Create and push tag
run: |
TAG="${{ steps.version.outputs.TAG }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "$TAG" -m "Release $TAG"
git push origin "$TAG"
- name: Create GitHub Release
uses: softprops/action-gh-release@b4309332981a82ec1c5618f44dd2e27cc8bfbfda # v3
with:
tag_name: "${{ steps.version.outputs.TAG }}"
name: "${{ steps.version.outputs.TAG }}"
body: ${{ steps.notes.outputs.NOTES }}
prerelease: ${{ inputs.prerelease }}