1+ name : Auto Bump Version
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ bump_type :
7+ description : ' Type of version bump'
8+ required : false
9+ default : ' auto'
10+ type : choice
11+ options :
12+ - auto
13+ - patch
14+ - minor
15+ - major
16+
17+ jobs :
18+ check-for-changes :
19+ runs-on : ubuntu-latest
20+ outputs :
21+ should_bump : ${{ steps.check.outputs.should_bump }}
22+ bump_type : ${{ steps.check.outputs.bump_type }}
23+ steps :
24+ - name : Checkout repository
25+ uses : actions/checkout@v4
26+ with :
27+ fetch-depth : 0
28+ token : ${{ secrets.GITHUB_TOKEN }}
29+
30+ - name : Check for unreleased changes
31+ id : check
32+ run : |
33+ # Get the last tag
34+ LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
35+
36+ if [ -z "$LAST_TAG" ]; then
37+ echo "No tags found, should create initial release"
38+ echo "should_bump=true" >> $GITHUB_OUTPUT
39+ echo "bump_type=patch" >> $GITHUB_OUTPUT
40+ exit 0
41+ fi
42+
43+ # Check for commits since last tag
44+ COMMITS_SINCE_TAG=$(git rev-list --count ${LAST_TAG}..HEAD)
45+
46+ if [ "$COMMITS_SINCE_TAG" -gt 0 ]; then
47+ echo "Found $COMMITS_SINCE_TAG commits since last tag $LAST_TAG"
48+
49+ # Determine bump type based on input or commit analysis
50+ if [ "${{ inputs.bump_type }}" != "auto" ] && [ -n "${{ inputs.bump_type }}" ]; then
51+ # Use manual input if provided and not "auto"
52+ BUMP_TYPE="${{ inputs.bump_type }}"
53+ else
54+ # Analyze commit messages to determine bump type
55+ BUMP_TYPE="patch"
56+
57+ # Check for breaking changes (major bump)
58+ if git log ${LAST_TAG}..HEAD --grep="BREAKING CHANGE" --grep="!:" | grep -q .; then
59+ BUMP_TYPE="major"
60+ # Check for features (minor bump)
61+ elif git log ${LAST_TAG}..HEAD --grep="^feat" --grep="^feature" | grep -q .; then
62+ BUMP_TYPE="minor"
63+ fi
64+ fi
65+
66+ echo "should_bump=true" >> $GITHUB_OUTPUT
67+ echo "bump_type=$BUMP_TYPE" >> $GITHUB_OUTPUT
68+ else
69+ echo "No commits since last tag $LAST_TAG"
70+ echo "should_bump=false" >> $GITHUB_OUTPUT
71+ fi
72+
73+ - name : Summary
74+ run : |
75+ echo "## Auto Bump Check" >> $GITHUB_STEP_SUMMARY
76+ echo "" >> $GITHUB_STEP_SUMMARY
77+ if [ "${{ steps.check.outputs.should_bump }}" == "true" ]; then
78+ echo "✅ Version bump needed" >> $GITHUB_STEP_SUMMARY
79+ echo "- **Bump Type:** ${{ steps.check.outputs.bump_type }}" >> $GITHUB_STEP_SUMMARY
80+ else
81+ echo "⏭️ No version bump needed" >> $GITHUB_STEP_SUMMARY
82+ fi
83+
84+ create-bump-pr :
85+ needs : check-for-changes
86+ if : needs.check-for-changes.outputs.should_bump == 'true'
87+ runs-on : ubuntu-latest
88+ steps :
89+ - name : Checkout repository
90+ uses : actions/checkout@v4
91+ with :
92+ token : ${{ secrets.GITHUB_TOKEN }}
93+ fetch-depth : 0
94+
95+ - name : Set up Python
96+ uses : actions/setup-python@v5
97+ with :
98+ python-version : ' 3.11'
99+
100+ - name : Install dependencies
101+ run : |
102+ pip install packaging toml bump-my-version
103+
104+ - name : Get current version
105+ id : current_version
106+ run : |
107+ CURRENT_VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])")
108+ echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
109+ echo "Current version: $CURRENT_VERSION"
110+
111+ - name : Calculate new version
112+ id : new_version
113+ run : |
114+ python ci/calculate_version.py \
115+ --current "${{ steps.current_version.outputs.version }}" \
116+ --type "${{ needs.check-for-changes.outputs.bump_type }}" \
117+ --channel "stable"
118+
119+ - name : Create feature branch
120+ run : |
121+ BRANCH_NAME="auto-bump-${{ steps.new_version.outputs.version }}"
122+ git checkout -b $BRANCH_NAME
123+ echo "branch=$BRANCH_NAME" >> $GITHUB_ENV
124+
125+ - name : Bump version
126+ run : |
127+ python ci/bump_version.py --version "${{ steps.new_version.outputs.version }}"
128+
129+ - name : Configure git
130+ run : |
131+ git config user.name 'github-actions[bot]'
132+ git config user.email 'github-actions[bot]@users.noreply.github.com'
133+
134+ - name : Commit changes
135+ run : |
136+ git add -A
137+ git commit -m "chore: bump version to ${{ steps.new_version.outputs.version }}
138+
139+ Automated version bump from ${{ steps.current_version.outputs.version }} to ${{ steps.new_version.outputs.version }}.
140+ Bump type: ${{ needs.check-for-changes.outputs.bump_type }}"
141+
142+ - name : Push changes
143+ run : |
144+ git push origin ${{ env.branch }}
145+
146+ - name : Create Pull Request
147+ uses : peter-evans/create-pull-request@v5
148+ with :
149+ token : ${{ secrets.GITHUB_TOKEN }}
150+ branch : ${{ env.branch }}
151+ base : main
152+ title : " chore: bump version to ${{ steps.new_version.outputs.version }}"
153+ body : |
154+ ## Automated Version Bump
155+
156+ This PR automatically bumps the version from `${{ steps.current_version.outputs.version }}` to `${{ steps.new_version.outputs.version }}`.
157+
158+ ### Details
159+ - **Bump Type:** ${{ needs.check-for-changes.outputs.bump_type }}
160+ - **Triggered By:** ${{ github.event_name == 'workflow_dispatch' && 'Manual trigger' || 'Automated' }}
161+
162+ ### Checklist
163+ - [ ] Review version bump changes
164+ - [ ] Verify pyproject.toml is updated
165+ - [ ] Confirm CI checks pass
166+
167+ ### Next Steps
168+ After merging this PR, you can create a release by:
169+ 1. Going to Actions → Create Release workflow
170+ 2. Selecting the release channel (stable/preview)
171+ 3. Running the workflow
172+
173+ ---
174+ *This PR was automatically generated by the auto-bump workflow.*
175+ labels : |
176+ version-bump
177+ automated
178+ assignees : ${{ github.actor }}
179+
180+ - name : Summary
181+ run : |
182+ echo "## Version Bump PR Created" >> $GITHUB_STEP_SUMMARY
183+ echo "" >> $GITHUB_STEP_SUMMARY
184+ echo "- **Current Version:** ${{ steps.current_version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
185+ echo "- **New Version:** ${{ steps.new_version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
186+ echo "- **Bump Type:** ${{ needs.check-for-changes.outputs.bump_type }}" >> $GITHUB_STEP_SUMMARY
187+ echo "- **Branch:** ${{ env.branch }}" >> $GITHUB_STEP_SUMMARY
188+ echo "" >> $GITHUB_STEP_SUMMARY
189+ echo "✅ Pull request created successfully!" >> $GITHUB_STEP_SUMMARY
0 commit comments