Skip to content

Commit 01396dd

Browse files
committed
upd
1 parent 8ffab81 commit 01396dd

File tree

2 files changed

+650
-0
lines changed

2 files changed

+650
-0
lines changed

.github/workflows/bump-version.yml

Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
name: Bump Version
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
force_bump_type:
7+
description: 'Force a specific bump type (leave empty for AI auto-detection)'
8+
required: false
9+
type: choice
10+
options:
11+
- ''
12+
- major
13+
- minor
14+
- patch
15+
schedule:
16+
# Run weekly on Monday at 9:00 AM UTC
17+
- cron: '0 9 * * 1'
18+
19+
jobs:
20+
analyze-and-bump:
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: write
24+
pull-requests: write
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0 # Need full history to analyze commits
30+
submodules: false
31+
32+
- name: Set up Python
33+
uses: actions/setup-python@v5
34+
with:
35+
python-version: '3.10'
36+
37+
- name: Install dependencies
38+
run: |
39+
python -m pip install --upgrade pip
40+
pip install google-generativeai
41+
42+
- name: Get current version
43+
id: current-version
44+
run: |
45+
CURRENT_VERSION=$(cat version.txt | tr -d '[:space:]')
46+
echo "version=${CURRENT_VERSION}" >> $GITHUB_OUTPUT
47+
echo "Current version: ${CURRENT_VERSION}"
48+
49+
- name: Check for existing bump PR
50+
id: check-existing-pr
51+
env:
52+
GH_TOKEN: ${{ github.token }}
53+
run: |
54+
# Check if there's already an open PR for version bump
55+
EXISTING_PR=$(gh pr list --state open --label "version-bump" --json number --jq '.[0].number' || echo "")
56+
if [ -n "$EXISTING_PR" ]; then
57+
echo "has_existing_pr=true" >> $GITHUB_OUTPUT
58+
echo "existing_pr_number=${EXISTING_PR}" >> $GITHUB_OUTPUT
59+
echo "⚠️ Existing version bump PR found: #${EXISTING_PR}"
60+
else
61+
echo "has_existing_pr=false" >> $GITHUB_OUTPUT
62+
echo "✓ No existing version bump PR found"
63+
fi
64+
65+
- name: Analyze commits with AI
66+
id: analyze
67+
if: steps.check-existing-pr.outputs.has_existing_pr == 'false'
68+
env:
69+
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
70+
run: |
71+
echo "Analyzing commits to determine version bump..."
72+
73+
# Run AI analysis
74+
python scripts/ai_determine_version_bump.py \
75+
--output-format json \
76+
--verbose > /tmp/analysis.json 2>&1
77+
78+
# Extract results
79+
BUMP_TYPE=$(jq -r '.bump_type' /tmp/analysis.json)
80+
NEW_VERSION=$(jq -r '.new_version' /tmp/analysis.json)
81+
REASONING=$(jq -r '.reasoning' /tmp/analysis.json)
82+
83+
echo "bump_type=${BUMP_TYPE}" >> $GITHUB_OUTPUT
84+
echo "new_version=${NEW_VERSION}" >> $GITHUB_OUTPUT
85+
86+
# Save reasoning and key changes for PR body
87+
jq -r '.reasoning' /tmp/analysis.json > /tmp/reasoning.txt
88+
jq -r '.key_changes[]' /tmp/analysis.json > /tmp/key_changes.txt || echo "" > /tmp/key_changes.txt
89+
90+
echo "AI Analysis Result:"
91+
echo " Bump type: ${BUMP_TYPE}"
92+
echo " New version: ${NEW_VERSION}"
93+
echo " Reasoning: ${REASONING}"
94+
95+
- name: Override with manual input
96+
id: final-decision
97+
if: steps.check-existing-pr.outputs.has_existing_pr == 'false'
98+
run: |
99+
# Use manual input if provided, otherwise use AI result
100+
if [ -n "${{ inputs.force_bump_type }}" ]; then
101+
BUMP_TYPE="${{ inputs.force_bump_type }}"
102+
echo "Using manual bump type: ${BUMP_TYPE}"
103+
104+
# Calculate new version
105+
CURRENT_VERSION="${{ steps.current-version.outputs.version }}"
106+
if [ "$BUMP_TYPE" = "major" ]; then
107+
MAJOR=$(echo $CURRENT_VERSION | cut -d'.' -f1)
108+
NEW_VERSION="$((MAJOR + 1)).0.0"
109+
elif [ "$BUMP_TYPE" = "minor" ]; then
110+
MAJOR=$(echo $CURRENT_VERSION | cut -d'.' -f1)
111+
MINOR=$(echo $CURRENT_VERSION | cut -d'.' -f2)
112+
NEW_VERSION="${MAJOR}.$((MINOR + 1)).0"
113+
elif [ "$BUMP_TYPE" = "patch" ]; then
114+
MAJOR=$(echo $CURRENT_VERSION | cut -d'.' -f1)
115+
MINOR=$(echo $CURRENT_VERSION | cut -d'.' -f2)
116+
PATCH=$(echo $CURRENT_VERSION | cut -d'.' -f3 | sed 's/[^0-9].*//')
117+
NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
118+
fi
119+
120+
echo "Manual override - reasoning" > /tmp/reasoning.txt
121+
else
122+
BUMP_TYPE="${{ steps.analyze.outputs.bump_type }}"
123+
NEW_VERSION="${{ steps.analyze.outputs.new_version }}"
124+
echo "Using AI-determined bump type: ${BUMP_TYPE}"
125+
fi
126+
127+
echo "bump_type=${BUMP_TYPE}" >> $GITHUB_OUTPUT
128+
echo "new_version=${NEW_VERSION}" >> $GITHUB_OUTPUT
129+
130+
echo "Final decision:"
131+
echo " Bump type: ${BUMP_TYPE}"
132+
echo " New version: ${NEW_VERSION}"
133+
134+
- name: Check if bump needed
135+
id: check-bump
136+
if: steps.check-existing-pr.outputs.has_existing_pr == 'false'
137+
run: |
138+
BUMP_TYPE="${{ steps.final-decision.outputs.bump_type }}"
139+
140+
if [ "$BUMP_TYPE" = "none" ]; then
141+
echo "needs_bump=false" >> $GITHUB_OUTPUT
142+
echo "ℹ️ No version bump needed"
143+
else
144+
echo "needs_bump=true" >> $GITHUB_OUTPUT
145+
echo "✓ Version bump needed: ${BUMP_TYPE}"
146+
fi
147+
148+
- name: Update version.txt
149+
if: steps.check-existing-pr.outputs.has_existing_pr == 'false' && steps.check-bump.outputs.needs_bump == 'true'
150+
run: |
151+
NEW_VERSION="${{ steps.final-decision.outputs.new_version }}"
152+
echo "${NEW_VERSION}" > version.txt
153+
echo "✓ Updated version.txt to ${NEW_VERSION}"
154+
155+
- name: Generate PR body
156+
id: pr-body
157+
if: steps.check-existing-pr.outputs.has_existing_pr == 'false' && steps.check-bump.outputs.needs_bump == 'true'
158+
run: |
159+
BUMP_TYPE="${{ steps.final-decision.outputs.bump_type }}"
160+
NEW_VERSION="${{ steps.final-decision.outputs.new_version }}"
161+
CURRENT_VERSION="${{ steps.current-version.outputs.version }}"
162+
163+
# Read AI reasoning
164+
REASONING=$(cat /tmp/reasoning.txt || echo "Manual version bump")
165+
166+
# Read key changes
167+
KEY_CHANGES=$(cat /tmp/key_changes.txt || echo "")
168+
169+
# Generate PR body
170+
cat > /tmp/pr_body.md << 'EOF'
171+
## Version Bump: v$CURRENT_VERSION → v$NEW_VERSION
172+
173+
This PR bumps the version from **v$CURRENT_VERSION** to **v$NEW_VERSION** ($BUMP_TYPE_UPPER bump).
174+
175+
### AI Analysis
176+
177+
$REASONING
178+
179+
EOF
180+
181+
if [ -n "$KEY_CHANGES" ]; then
182+
echo "" >> /tmp/pr_body.md
183+
echo "### Key Changes" >> /tmp/pr_body.md
184+
echo "" >> /tmp/pr_body.md
185+
while IFS= read -r change; do
186+
echo "- $change" >> /tmp/pr_body.md
187+
done < /tmp/key_changes.txt
188+
fi
189+
190+
cat >> /tmp/pr_body.md << 'EOF'
191+
192+
### Semantic Versioning Rules
193+
194+
According to our [CONTRIBUTING.md](../blob/main/CONTRIBUTING.md):
195+
196+
- **Major**: Incompatible API changes
197+
- **Minor**: Added functionality that is backwards-compatible
198+
- **Patch**: Backwards-compatible bug fixes
199+
200+
### Next Steps
201+
202+
After merging this PR:
203+
1. Create a git tag: `git tag v$NEW_VERSION`
204+
2. Run the [release workflow](../actions/workflows/release.yml) with tag `v$NEW_VERSION`
205+
206+
---
207+
208+
🤖 Auto-generated by [bump-version workflow](../actions/runs/$RUN_ID)
209+
EOF
210+
211+
# Replace variables
212+
sed -i "s/\$CURRENT_VERSION/$CURRENT_VERSION/g" /tmp/pr_body.md
213+
sed -i "s/\$NEW_VERSION/$NEW_VERSION/g" /tmp/pr_body.md
214+
sed -i "s/\$BUMP_TYPE_UPPER/$(echo $BUMP_TYPE | tr '[:lower:]' '[:upper:]')/g" /tmp/pr_body.md
215+
sed -i "s|\$REASONING|$REASONING|g" /tmp/pr_body.md
216+
sed -i "s/\$RUN_ID/${{ github.run_id }}/g" /tmp/pr_body.md
217+
218+
cat /tmp/pr_body.md
219+
220+
- name: Create Pull Request
221+
if: steps.check-existing-pr.outputs.has_existing_pr == 'false' && steps.check-bump.outputs.needs_bump == 'true'
222+
uses: peter-evans/create-pull-request@v6
223+
with:
224+
token: ${{ secrets.FLASHINFER_BOT_TOKEN }}
225+
commit-message: "release: bump version to ${{ steps.final-decision.outputs.new_version }}"
226+
title: "Release: Bump version to v${{ steps.final-decision.outputs.new_version }}"
227+
body-path: /tmp/pr_body.md
228+
branch: bump-version-${{ steps.final-decision.outputs.new_version }}
229+
delete-branch: true
230+
labels: |
231+
version-bump
232+
automated
233+
release
234+
committer: flashinfer-bot <[email protected]>
235+
author: flashinfer-bot <[email protected]>
236+
237+
- name: Summary
238+
if: steps.check-existing-pr.outputs.has_existing_pr == 'false'
239+
run: |
240+
echo "## Version Bump Summary" >> $GITHUB_STEP_SUMMARY
241+
echo "" >> $GITHUB_STEP_SUMMARY
242+
243+
if [ "${{ steps.check-bump.outputs.needs_bump }}" = "true" ]; then
244+
echo "✅ Version bump PR created" >> $GITHUB_STEP_SUMMARY
245+
echo "" >> $GITHUB_STEP_SUMMARY
246+
echo "- **Current version**: ${{ steps.current-version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
247+
echo "- **New version**: ${{ steps.final-decision.outputs.new_version }}" >> $GITHUB_STEP_SUMMARY
248+
echo "- **Bump type**: ${{ steps.final-decision.outputs.bump_type }}" >> $GITHUB_STEP_SUMMARY
249+
else
250+
echo "ℹ️ No version bump needed" >> $GITHUB_STEP_SUMMARY
251+
echo "" >> $GITHUB_STEP_SUMMARY
252+
echo "No significant changes detected since the last release." >> $GITHUB_STEP_SUMMARY
253+
fi
254+
255+
- name: Already has open PR
256+
if: steps.check-existing-pr.outputs.has_existing_pr == 'true'
257+
run: |
258+
echo "## Version Bump Summary" >> $GITHUB_STEP_SUMMARY
259+
echo "" >> $GITHUB_STEP_SUMMARY
260+
echo "⚠️ A version bump PR already exists: #${{ steps.check-existing-pr.outputs.existing_pr_number }}" >> $GITHUB_STEP_SUMMARY
261+
echo "" >> $GITHUB_STEP_SUMMARY
262+
echo "Please review and merge the existing PR before creating a new one." >> $GITHUB_STEP_SUMMARY
263+
264+
exit 0

0 commit comments

Comments
 (0)