Skip to content

Commit 1ad5696

Browse files
committed
add script
1 parent 659515f commit 1ad5696

File tree

4 files changed

+640
-0
lines changed

4 files changed

+640
-0
lines changed

.github/workflows/version.yaml

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
name: Version Management
2+
3+
on:
4+
push:
5+
# uncomment when we're ready for alpha pre-releases
6+
# branches:
7+
# - main
8+
9+
workflow_dispatch:
10+
inputs:
11+
version_type:
12+
description: "Type of version bump to perform"
13+
required: true
14+
type: choice
15+
options:
16+
- beta
17+
- rc
18+
- release
19+
- major
20+
- minor
21+
- patch
22+
23+
permissions:
24+
contents: write
25+
pull-requests: write
26+
27+
jobs:
28+
check-commit-message:
29+
runs-on: ubuntu-latest
30+
outputs:
31+
should_run: ${{ steps.check.outputs.should_run }}
32+
steps:
33+
- uses: actions/checkout@v4
34+
with:
35+
fetch-depth: 2
36+
37+
- name: Check trigger event or commit message
38+
id: check
39+
run: |
40+
echo "Event: ${{ github.event_name }}"
41+
42+
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
43+
echo "Manual trigger — always run."
44+
echo "should_run=true" >> $GITHUB_OUTPUT
45+
exit 0
46+
fi
47+
48+
COMMIT_MSG=$(git log -1 --pretty=%B | tr -d '\n')
49+
echo "Commit message: '$COMMIT_MSG'"
50+
51+
# Skip version bump if commit is a known non-code change
52+
if echo "$COMMIT_MSG" | grep -Eq '^(chore|docs|style|test|ci)(\([^)]+\))?:'; then
53+
echo "Skipping: commit is non-code change."
54+
echo "should_run=false" >> $GITHUB_OUTPUT
55+
elif echo "$COMMIT_MSG" | grep -iq 'bump version'; then
56+
echo "Skipping: self-referential version bump."
57+
echo "should_run=false" >> $GITHUB_OUTPUT
58+
else
59+
echo "Commit is code-related — triggering version bump."
60+
echo "should_run=true" >> $GITHUB_OUTPUT
61+
fi
62+
63+
bump-version:
64+
needs: check-commit-message
65+
if: needs.check-commit-message.outputs.should_run == 'true' && github.ref == 'refs/heads/main'
66+
runs-on: ubuntu-latest
67+
68+
steps:
69+
- uses: actions/checkout@v4
70+
with:
71+
fetch-depth: 0
72+
token: ${{ secrets.GITHUB_TOKEN }}
73+
74+
- name: Project setup
75+
uses: ./.github/actions/project-setup
76+
77+
- name: Configure Git
78+
run: |
79+
git config --global user.name "github-actions[bot]"
80+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
81+
82+
- name: Get current version
83+
id: current_version
84+
run: |
85+
echo "version=$(cat pyproject.toml | grep '^version = ".*"' | cut -d'"' -f2)" >> $GITHUB_OUTPUT
86+
87+
# Create a new branch for version bump
88+
# - name: Create version bump branch
89+
# id: create_branch
90+
# run: |
91+
# BRANCH_NAME="version-bump-$(date +%Y%m%d-%H%M%S)"
92+
# git checkout -b $BRANCH_NAME
93+
# echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
94+
95+
# Handle automatic alpha bump on push to dev
96+
- name: Get git hash
97+
id: git_hash
98+
run: echo "hash=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
99+
100+
- name: Bump alpha version (on push)
101+
if: github.event_name == 'push'
102+
run: uv run scripts/bump_version.py alpha --git-hash ${{ steps.git_hash.outputs.hash }}
103+
104+
# Handle workflow dispatch for beta/rc/release
105+
- name: Bump version (beta/rc/release)
106+
if: |
107+
github.event_name == 'workflow_dispatch' &&
108+
(github.event.inputs.version_type == 'beta' ||
109+
github.event.inputs.version_type == 'rc' ||
110+
github.event.inputs.version_type == 'release')
111+
run: uv run scripts/bump_version.py ${{ github.event.inputs.version_type }}
112+
113+
# Handle workflow dispatch for major/minor/patch
114+
- name: Bump version (major/minor/patch)
115+
if: |
116+
github.event_name == 'workflow_dispatch' &&
117+
(github.event.inputs.version_type == 'major' ||
118+
github.event.inputs.version_type == 'minor' ||
119+
github.event.inputs.version_type == 'patch')
120+
run: |
121+
if [ "${{ github.event.inputs.version_type }}" = "major" ]; then
122+
uv run bump_version.py mjr
123+
elif [ "${{ github.event.inputs.version_type }}" = "minor" ]; then
124+
uv run bump_version.py mnr
125+
else
126+
uv run bump_version.py patch
127+
fi
128+
129+
# Get new version after bump
130+
- name: Get new version
131+
id: new_version
132+
run: |
133+
echo "version=$(cat pyproject.toml | grep '^version = ".*"' | cut -d'"' -f2)" >> $GITHUB_OUTPUT
134+
135+
# Update Cargo.lock
136+
- name: Update Cargo.lock
137+
run: cargo update ptolemy --precise ${{ steps.new_version.outputs.version }}
138+
139+
# Update uv.lock
140+
- name: Update uv.lock
141+
run: uv lock
142+
143+
# Generate appropriate labels based on release type
144+
- name: Generate PR labels
145+
id: generate_labels
146+
run: |
147+
# Start with the standard labels
148+
LABELS="auto-generated\nversion-bump"
149+
150+
# Add release type label
151+
if [ "${{ github.event_name }}" = "push" ]; then
152+
RELEASE_TYPE="alpha"
153+
else
154+
RELEASE_TYPE="${{ github.event.inputs.version_type }}"
155+
fi
156+
157+
LABELS="$LABELS\n$RELEASE_TYPE"
158+
159+
# Add prerelease label for alpha/beta/rc
160+
if [ "$RELEASE_TYPE" = "alpha" ] || [ "$RELEASE_TYPE" = "beta" ] || [ "$RELEASE_TYPE" = "rc" ]; then
161+
LABELS="$LABELS\nprerelease"
162+
fi
163+
164+
echo "labels<<EOF" >> $GITHUB_OUTPUT
165+
echo -e "$LABELS" >> $GITHUB_OUTPUT
166+
echo "EOF" >> $GITHUB_OUTPUT
167+
168+
# Create PR
169+
- name: Create Pull Request
170+
id: create_pr
171+
uses: peter-evans/create-pull-request@v5
172+
with:
173+
token: ${{ secrets.GITHUB_TOKEN }}
174+
commit-message: "version: bump version 🚀 ${{ steps.current_version.outputs.version }} → ${{ steps.new_version.outputs.version }}"
175+
title: "version: Version Bump 🚀 ${{ steps.current_version.outputs.version }} → ${{ steps.new_version.outputs.version }}"
176+
body: |
177+
## 🎉 Version Bump 🎉
178+
179+
This PR bumps the version from ${{ steps.current_version.outputs.version }} to ${{ steps.new_version.outputs.version }}.
180+
181+
### 🔄 Changes
182+
- 📝 Updated version in pyproject.toml
183+
- 🔒 Updated Cargo.lock
184+
185+
✨ This PR was automatically generated by the Version Management workflow ✨
186+
187+
![version bump](https://media0.giphy.com/media/v1.Y2lkPTc5MGI3NjExNjJmOXBxbGh2Z3BiYXM1NnJhMHdtbmNoaTFxN2xjOGZjZnd1ZGhuMiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/3oEjI53nBYOOEQgDcY/giphy.gif)
188+
branch: version/bump-${{ github.run_id }}
189+
base: main
190+
delete-branch: true
191+
add-paths: |
192+
pyproject.toml
193+
Cargo.lock
194+
uv.lock
195+
**/pyproject.toml
196+
**/Cargo.toml
197+
labels: ${{ steps.generate_labels.outputs.labels }}

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ dependencies = [
99
"optimum[onnxruntime]>=2.0.0",
1010
"pip>=25.2",
1111
"protobuf>=6.33.0",
12+
"pydantic>=2.12.4",
13+
"toml>=0.10.2",
1214
"transformers>=4.55.0",
1315
]
1416

0 commit comments

Comments
 (0)