name: Version Bump
on:
workflow_dispatch:
inputs:
bump_type:
description: 'Version bump type'
required: true
type: choice
options:
- auto
- patch
- minor
- major
default: 'auto'
permissions:
contents: write
pull-requests: write
jobs:
bump-version:
name: Bump Version
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/trunk'
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install cargo-edit
run: cargo install cargo-edit
- name: Determine bump type
id: determine_bump
run: |
BUMP_TYPE="${{ github.event.inputs.bump_type }}"
if [ "$BUMP_TYPE" = "auto" ]; then
# Get commits since last tag
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$LAST_TAG" ]; then
echo "No previous tag found, defaulting to minor bump"
BUMP_TYPE="minor"
else
# Check for breaking changes
if git log ${LAST_TAG}..HEAD --grep="BREAKING CHANGE" --grep="!:" | grep -q .; then
BUMP_TYPE="major"
# Check for new features
elif git log ${LAST_TAG}..HEAD --grep="^feat" | grep -q .; then
BUMP_TYPE="minor"
# Otherwise patch
else
BUMP_TYPE="patch"
fi
fi
fi
echo "bump_type=$BUMP_TYPE" >> $GITHUB_OUTPUT
echo "Determined bump type: $BUMP_TYPE"
- name: Get current version
id: current_version
run: |
CURRENT_VERSION=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[0].version')
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "Current version: $CURRENT_VERSION"
- name: Bump version
id: bump
run: |
BUMP_TYPE="${{ steps.determine_bump.outputs.bump_type }}"
cargo set-version --bump $BUMP_TYPE
NEW_VERSION=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[0].version')
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "Bumped to version: $NEW_VERSION"
- name: Install git-cliff
uses: taiki-e/install-action@v2
with:
tool: git-cliff
- name: Update CHANGELOG.md
run: |
# Generate updated CHANGELOG.md with the new version
git-cliff --config cliff.toml --output CHANGELOG.md
echo "Generated CHANGELOG.md for v${{ steps.bump.outputs.new_version }}"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "chore(release): Bump version to ${{ steps.bump.outputs.new_version }} and update CHANGELOG"
branch: release/v${{ steps.bump.outputs.new_version }}
delete-branch: true
title: "Release v${{ steps.bump.outputs.new_version }}"
body: |
## 🚀 Version Bump: v${{ steps.bump.outputs.new_version }}
**Bump type:** ${{ steps.determine_bump.outputs.bump_type }}
**Previous version:** v${{ steps.current_version.outputs.version }}
**New version:** v${{ steps.bump.outputs.new_version }}
### What's Changed
This PR bumps the version number in preparation for release.
### Next Steps
1. Review and merge this PR
2. After merge, create and push the release tag:
```bash
git checkout trunk
git pull
git tag v${{ steps.bump.outputs.new_version }}
git push origin v${{ steps.bump.outputs.new_version }}
```
3. The release workflow will automatically:
- Generate changelog
- Build release artifacts
- Publish to crates.io
- Create GitHub release
---
_Auto-generated by version-bump workflow_
labels: |
release
auto-merge-candidate
reviewers: ${{ github.actor }}
- name: Comment with instructions
uses: actions/github-script@v7
with:
script: |
const newVersion = '${{ steps.bump.outputs.new_version }}';
const bumpType = '${{ steps.determine_bump.outputs.bump_type }}';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `### 📦 Version Bump Ready
Version has been bumped from **v${{ steps.current_version.outputs.version }}** to **v${newVersion}** (${bumpType} bump).
**After merging this PR**, create the release tag:
\`\`\`bash
git checkout trunk && git pull
git tag v${newVersion}
git push origin v${newVersion}
\`\`\`
The release workflow will handle the rest! 🎉`
})