-
Notifications
You must be signed in to change notification settings - Fork 2
221 lines (184 loc) · 7.3 KB
/
auto-release.yml
File metadata and controls
221 lines (184 loc) · 7.3 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
name: Auto Release
on:
push:
branches:
- main
jobs:
auto-release:
runs-on: ubuntu-latest
# 只在非 tag 推送时运行,避免循环触发
if: "!startsWith(github.ref, 'refs/tags/v') && !contains(github.event.head_commit.message, '[skip-release]')"
environment:
name: release
url: https://pypi.org/project/claude-commit/
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Run lint checks
run: |
black --check src/
echo "✅ Code formatting check passed"
- name: Run type checks
run: |
mypy src/ || echo "⚠️ Type check warnings (non-blocking)"
- name: Test installation
run: |
claude-commit --help
echo "✅ Installation test passed"
- name: Get current version
id: current_version
run: |
VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Current version: $VERSION"
- name: Analyze commits and determine version bump
id: version_bump
run: |
# 获取上一个 tag(如果存在)
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$LAST_TAG" ]; then
# 如果没有 tag,从第一个 commit 开始
COMMITS=$(git log --pretty=format:"%s")
else
# 获取自上次 tag 以来的所有 commits
COMMITS=$(git log ${LAST_TAG}..HEAD --pretty=format:"%s")
fi
echo "Analyzing commits:"
echo "$COMMITS"
# 分析 commit messages 决定版本升级类型
BUMP_TYPE="none"
# 检查是否有 BREAKING CHANGE 或 feat!: / fix!: 等(major version)
if echo "$COMMITS" | grep -qiE '^[a-z]+(\(.+\))?!:|BREAKING[- ]CHANGE'; then
BUMP_TYPE="major"
# 检查是否有 feat: (minor version)
elif echo "$COMMITS" | grep -qiE '^feat(\(.+\))?:'; then
BUMP_TYPE="minor"
# 检查是否有 fix: / perf: / refactor: 等(patch version)
elif echo "$COMMITS" | grep -qiE '^(fix|perf|refactor|docs|style|test|build|ci|chore)(\(.+\))?:'; then
BUMP_TYPE="patch"
fi
echo "bump_type=$BUMP_TYPE" >> $GITHUB_OUTPUT
echo "Determined bump type: $BUMP_TYPE"
- name: Calculate new version
id: new_version
if: steps.version_bump.outputs.bump_type != 'none'
run: |
CURRENT="${{ steps.current_version.outputs.version }}"
BUMP_TYPE="${{ steps.version_bump.outputs.bump_type }}"
# 解析当前版本
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
# 根据 bump type 计算新版本
case $BUMP_TYPE in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
patch)
PATCH=$((PATCH + 1))
;;
esac
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION (was: $CURRENT)"
- name: Update pyproject.toml
if: steps.version_bump.outputs.bump_type != 'none'
run: |
NEW_VERSION="${{ steps.new_version.outputs.version }}"
sed -i "s/^version = \".*\"/version = \"$NEW_VERSION\"/" pyproject.toml
echo "Updated pyproject.toml to version $NEW_VERSION"
- name: Format code with black
if: steps.version_bump.outputs.bump_type != 'none'
run: |
pip install black
black src/
- name: Commit and push version bump
if: steps.version_bump.outputs.bump_type != 'none'
run: |
NEW_VERSION="${{ steps.new_version.outputs.version }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add pyproject.toml src/
git commit -m "chore: bump version to $NEW_VERSION [skip-ci][skip-release]" || exit 0
git push
- name: Create and push tag
if: steps.version_bump.outputs.bump_type != 'none'
run: |
NEW_VERSION="${{ steps.new_version.outputs.version }}"
git tag -a "v$NEW_VERSION" -m "Release version $NEW_VERSION"
git push origin "v$NEW_VERSION"
- name: Generate release notes
if: steps.version_bump.outputs.bump_type != 'none'
id: release_notes
run: |
NEW_VERSION="${{ steps.new_version.outputs.version }}"
LAST_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -z "$LAST_TAG" ]; then
COMMITS=$(git log --pretty=format:"- %s (%h)" HEAD^)
else
COMMITS=$(git log ${LAST_TAG}..HEAD^ --pretty=format:"- %s (%h)")
fi
# 生成 release notes
cat > release_notes.md <<EOF
## What's Changed
$COMMITS
**Full Changelog**: https://github.com/${{ github.repository }}/compare/${LAST_TAG}...v${NEW_VERSION}
EOF
echo "Generated release notes"
cat release_notes.md
- name: Create GitHub Release
if: steps.version_bump.outputs.bump_type != 'none'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.new_version.outputs.version }}
release_name: Release v${{ steps.new_version.outputs.version }}
body_path: release_notes.md
draft: false
prerelease: false
- name: Install build tools
if: steps.version_bump.outputs.bump_type != 'none'
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build package
if: steps.version_bump.outputs.bump_type != 'none'
run: python -m build
- name: Check package
if: steps.version_bump.outputs.bump_type != 'none'
run: twine check dist/*
- name: Publish to PyPI
if: steps.version_bump.outputs.bump_type != 'none'
uses: pypa/gh-action-pypi-publish@release/v1
# Uses trusted publishing if configured, otherwise falls back to API token
# To use trusted publishing: configure it in PyPI project settings
# To use API token: add PYPI_API_TOKEN secret to GitHub repository
with:
password: ${{ secrets.PYPI_API_TOKEN }}
skip-existing: true
- name: No release needed
if: steps.version_bump.outputs.bump_type == 'none'
run: |
echo "No version bump needed - no conventional commits found"
echo "Use commit messages like:"
echo " - feat: add new feature (minor bump)"
echo " - fix: fix a bug (patch bump)"
echo " - feat!: breaking change (major bump)"