-
Notifications
You must be signed in to change notification settings - Fork 10
222 lines (186 loc) · 6.56 KB
/
Copy pathrelease.yml
File metadata and controls
222 lines (186 loc) · 6.56 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
222
name: Automated Release
on:
push:
branches:
- main
permissions:
contents: write
pull-requests: write
jobs:
release:
runs-on: ubuntu-latest
outputs:
released: ${{ steps.release.outputs.released }}
version: ${{ steps.release.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.BYPASS_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: "latest"
- name: Install dependencies
run: |
uv sync --group dev
- name: Run tests
continue-on-error: true
run: |
uv run pytest
- name: Run linting
continue-on-error: true
run: |
uv run ruff check
- name: Run formatting check
continue-on-error: true
run: |
uv run ruff format --check
- name: Determine version bump
id: version_bump
run: |
# Get the latest tag
LATEST_TAG=$(git tag -l 'v*' --sort=-version:refname | head -n1)
if [ -z "$LATEST_TAG" ]; then
LATEST_TAG="v0.0.0"
fi
echo "Latest tag: $LATEST_TAG"
# Get commits since last tag
if [ "$LATEST_TAG" = "v0.0.0" ]; then
# No tags exist, get all commits
COMMITS=$(git log --oneline --pretty=format:"%s")
else
# Get commits since last tag
COMMITS=$(git log ${LATEST_TAG}..HEAD --oneline --pretty=format:"%s")
fi
echo "Commits since last tag:"
echo "$COMMITS"
# Check if there are any commits since last tag
if [ -z "$COMMITS" ]; then
echo "No commits since last tag, skipping release"
echo "should_release=false" >> $GITHUB_OUTPUT
exit 0
fi
# Determine version bump type based on commit messages
BUMP_TYPE="patch"
if echo "$COMMITS" | grep -qi "BREAKING CHANGE\|breaking:"; then
BUMP_TYPE="major"
elif echo "$COMMITS" | grep -qi "feat\|feature:"; then
BUMP_TYPE="minor"
elif echo "$COMMITS" | grep -qi "fix\|bug\|patch:"; then
BUMP_TYPE="patch"
fi
echo "Version bump type: $BUMP_TYPE"
echo "bump_type=$BUMP_TYPE" >> $GITHUB_OUTPUT
# Calculate new version
CURRENT_VERSION=$(echo $LATEST_TAG | sed 's/v//')
if [ "$CURRENT_VERSION" = "0.0.0" ]; then
# No existing tags, get current version from pyproject.toml
CURRENT_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\([^"]*\)"/\1/')
echo "Current version from pyproject.toml: $CURRENT_VERSION"
# Bump based on commit type
IFS='.' read -r major minor patch <<< "$CURRENT_VERSION"
case $BUMP_TYPE in
major)
NEW_VERSION="$((major + 1)).0.0"
;;
minor)
NEW_VERSION="$major.$((minor + 1)).0"
;;
patch)
NEW_VERSION="$major.$minor.$((patch + 1))"
;;
esac
else
IFS='.' read -r major minor patch <<< "$CURRENT_VERSION"
case $BUMP_TYPE in
major)
NEW_VERSION="$((major + 1)).0.0"
;;
minor)
NEW_VERSION="$major.$((minor + 1)).0"
;;
patch)
NEW_VERSION="$major.$minor.$((patch + 1))"
;;
esac
fi
echo "New version: $NEW_VERSION"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "should_release=true" >> $GITHUB_OUTPUT
- name: Update version in pyproject.toml
id: update_version
if: steps.version_bump.outputs.should_release == 'true'
run: |
NEW_VERSION="${{ steps.version_bump.outputs.new_version }}"
sed -i "s/version = \"[^\"]*\"/version = \"$NEW_VERSION\"/" pyproject.toml
echo "Updated pyproject.toml version to $NEW_VERSION"
# Check if there are any changes to commit
if git diff --quiet pyproject.toml; then
echo "No version changes to commit"
else
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add pyproject.toml
git commit -m "chore: bump version to $NEW_VERSION"
git push
fi
- name: Create GitHub Release
id: release
if: steps.version_bump.outputs.should_release == 'true'
env:
GITHUB_TOKEN: ${{ secrets.BYPASS_TOKEN }}
run: |
NEW_VERSION="${{ steps.version_bump.outputs.new_version }}"
BUMP_TYPE="${{ steps.version_bump.outputs.bump_type }}"
# Create tag
git tag "v$NEW_VERSION"
git push origin "v$NEW_VERSION"
# Create release
gh release create "v$NEW_VERSION" \
--title "Release v$NEW_VERSION" \
--notes "## Changes in this release
This release was automatically generated based on commit messages.
Version bump type: $BUMP_TYPE
### Recent commits:
$(git log --oneline --since="1 day ago" --pretty=format:"- %s")" \
--latest
echo "released=true" >> $GITHUB_OUTPUT
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
publish:
needs: release
if: needs.release.outputs.released == 'true'
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: "latest"
- name: Update version for PyPI build
run: |
NEW_VERSION="${{ needs.release.outputs.version }}"
sed -i "s/version = \"[^\"]*\"/version = \"$NEW_VERSION\"/" pyproject.toml
echo "Updated pyproject.toml version to $NEW_VERSION for PyPI build"
grep "version = " pyproject.toml
- name: Build package
run: |
uv build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true