-
Notifications
You must be signed in to change notification settings - Fork 2
184 lines (147 loc) · 6.09 KB
/
release.yml
File metadata and controls
184 lines (147 loc) · 6.09 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
name: Release
on:
push:
branches: [master]
permissions:
contents: write
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
# Skip release for commits that only update version (avoid infinite loop)
if: "!contains(github.event.head_commit.message, 'chore(release):')"
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for changelog generation
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"
- name: Set up Python
run: uv python install 3.13
- name: Install dependencies
run: uv sync --dev
- name: Run tests
run: |
uv run pytest tests/ -v --tb=short -x --ignore=tests/test_smoke.py
- name: Get current version
id: current_version
run: |
VERSION=$(grep -oP 'version = "\K[^"]+' pyproject.toml)
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Determine version bump
id: bump
run: |
# Get commits since last tag (or all commits if no tags exist)
if git describe --tags --abbrev=0 2>/dev/null; then
LAST_TAG=$(git describe --tags --abbrev=0)
COMMITS=$(git log ${LAST_TAG}..HEAD --pretty=format:"%s")
else
# No tags yet - analyze the current commit only
COMMITS=$(git log -1 --pretty=format:"%s")
fi
echo "Analyzing commits for version bump..."
echo "$COMMITS"
# Determine bump type based on conventional commits
BUMP="none"
if echo "$COMMITS" | grep -qiE "^BREAKING CHANGE:|^[a-z]+(\(.+\))?!:"; then
BUMP="major"
elif echo "$COMMITS" | grep -qiE "^feat(\(.+\))?:"; then
BUMP="minor"
elif echo "$COMMITS" | grep -qiE "^fix(\(.+\))?:|^perf(\(.+\))?:|^refactor(\(.+\))?:"; then
BUMP="patch"
fi
echo "bump=$BUMP" >> $GITHUB_OUTPUT
- name: Calculate new version
id: new_version
if: steps.bump.outputs.bump != 'none'
run: |
CURRENT="${{ steps.current_version.outputs.version }}"
BUMP="${{ steps.bump.outputs.bump }}"
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
case $BUMP in
major)
NEW_VERSION="$((MAJOR + 1)).0.0"
;;
minor)
NEW_VERSION="${MAJOR}.$((MINOR + 1)).0"
;;
patch)
NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
;;
esac
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "Bumping from $CURRENT to $NEW_VERSION ($BUMP)"
- name: Generate changelog
id: changelog
if: steps.bump.outputs.bump != 'none'
run: |
# Get commits since last tag
if git describe --tags --abbrev=0 2>/dev/null; then
LAST_TAG=$(git describe --tags --abbrev=0)
COMMITS=$(git log ${LAST_TAG}..HEAD --pretty=format:"- %s (%h)" --reverse)
else
COMMITS=$(git log -1 --pretty=format:"- %s (%h)")
fi
# Create changelog grouped by type
FEATURES=$(echo "$COMMITS" | grep -iE "^- feat" || true)
FIXES=$(echo "$COMMITS" | grep -iE "^- fix" || true)
PERF=$(echo "$COMMITS" | grep -iE "^- perf" || true)
REFACTOR=$(echo "$COMMITS" | grep -iE "^- refactor" || true)
OTHER=$(echo "$COMMITS" | grep -viE "^- (feat|fix|perf|refactor|chore|docs|style|test|ci|build)" || true)
CHANGELOG=""
if [ -n "$FEATURES" ]; then
CHANGELOG="${CHANGELOG}### ✨ Features\n${FEATURES}\n\n"
fi
if [ -n "$FIXES" ]; then
CHANGELOG="${CHANGELOG}### 🐛 Bug Fixes\n${FIXES}\n\n"
fi
if [ -n "$PERF" ]; then
CHANGELOG="${CHANGELOG}### ⚡ Performance\n${PERF}\n\n"
fi
if [ -n "$REFACTOR" ]; then
CHANGELOG="${CHANGELOG}### ♻️ Refactoring\n${REFACTOR}\n\n"
fi
if [ -n "$OTHER" ]; then
CHANGELOG="${CHANGELOG}### 📝 Other Changes\n${OTHER}\n\n"
fi
# Write to file for multiline handling
echo -e "$CHANGELOG" > /tmp/changelog.md
# Also output for debugging
echo "Generated changelog:"
cat /tmp/changelog.md
- name: Update version in pyproject.toml and uv.lock
if: steps.bump.outputs.bump != 'none'
run: |
NEW_VERSION="${{ steps.new_version.outputs.new_version }}"
sed -i "s/version = \".*\"/version = \"$NEW_VERSION\"/" pyproject.toml
# Update uv.lock to reflect the new version
uv lock
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add pyproject.toml uv.lock
git commit -m "chore(release): v$NEW_VERSION"
git push
- name: Create Git tag
if: steps.bump.outputs.bump != 'none'
run: |
NEW_VERSION="${{ steps.new_version.outputs.new_version }}"
git tag "v$NEW_VERSION"
git push origin "v$NEW_VERSION"
- name: Create GitHub Release
if: steps.bump.outputs.bump != 'none'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.new_version.outputs.new_version }}
name: v${{ steps.new_version.outputs.new_version }}
body_path: /tmp/changelog.md
generate_release_notes: true # Adds contributors and full changelog link
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Skip release
if: steps.bump.outputs.bump == 'none'
run: |
echo "No version bump needed. Commit message does not follow conventional commits format."
echo "Use prefixes like: feat:, fix:, perf:, refactor:, or BREAKING CHANGE:"