ok better version handling

This commit is contained in:
dal 2025-02-26 07:51:04 -07:00
parent a70389b4e8
commit 89e92cf81f
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
3 changed files with 123 additions and 2 deletions

View File

@ -101,14 +101,20 @@ jobs:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download all artifacts
uses: actions/download-artifact@v4
- name: Get version
- name: Extract version from Cargo.toml
id: get_version
run: |
VERSION=0.0.7
VERSION=$(grep '^version =' cli/Cargo.toml | sed 's/version = "\(.*\)"/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION"
- name: Create Release
uses: softprops/action-gh-release@v1

63
.github/workflows/version-bump.yml vendored Normal file
View File

@ -0,0 +1,63 @@
name: Version Bump
on:
pull_request:
types: [closed]
branches:
- main
paths:
- 'cli/**'
jobs:
bump-version:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Git
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
- name: Determine version bump type
id: bump_type
run: |
PR_TITLE="${{ github.event.pull_request.title }}"
PR_BODY="${{ github.event.pull_request.body }}"
PR_LABELS="${{ toJson(github.event.pull_request.labels.*.name) }}"
if [[ "$PR_TITLE" == *"BREAKING CHANGE"* || "$PR_TITLE" == *"major"* || "$PR_BODY" == *"BREAKING CHANGE"* || "$PR_LABELS" == *"major"* ]]; then
echo "type=major" >> $GITHUB_OUTPUT
echo "Detected major version bump"
elif [[ "$PR_TITLE" == *"feat"* || "$PR_TITLE" == *"feature"* || "$PR_TITLE" == *"minor"* || "$PR_LABELS" == *"minor"* || "$PR_LABELS" == *"feature"* ]]; then
echo "type=minor" >> $GITHUB_OUTPUT
echo "Detected minor version bump"
else
echo "type=patch" >> $GITHUB_OUTPUT
echo "Detected patch version bump"
fi
- name: Install cargo-bump
run: cargo install cargo-bump
- name: Bump version
working-directory: ./cli
run: |
BUMP_TYPE="${{ steps.bump_type.outputs.type }}"
cargo bump $BUMP_TYPE
NEW_VERSION=$(grep '^version =' Cargo.toml | sed 's/version = "\(.*\)"/\1/')
echo "New version: $NEW_VERSION"
echo "new_version=$NEW_VERSION" >> $GITHUB_ENV
- name: Commit and push version bump
run: |
git add cli/Cargo.toml
git commit -m "Bump version to ${{ env.new_version }} [skip ci]"
git push

52
cli/VERSIONING.md Normal file
View File

@ -0,0 +1,52 @@
# Semantic Versioning for Buster CLI
This project uses automated semantic versioning based on pull request metadata. The version is automatically bumped when a pull request is merged into the main branch.
## How It Works
1. When a pull request is merged into the main branch, a GitHub Action workflow automatically determines the type of version bump needed.
2. The version in `Cargo.toml` is updated accordingly.
3. The changes are committed back to the repository.
4. When a release is created, the version is extracted directly from `Cargo.toml`.
## Version Bump Rules
The type of version bump is determined by the following rules:
### Major Version Bump (X.y.z → X+1.0.0)
A major version bump occurs when:
- The PR title contains "BREAKING CHANGE" or "major"
- The PR body contains "BREAKING CHANGE"
- The PR has a "major" label
### Minor Version Bump (x.Y.z → x.Y+1.0)
A minor version bump occurs when:
- The PR title contains "feat", "feature", or "minor"
- The PR has a "minor" or "feature" label
### Patch Version Bump (x.y.Z → x.y.Z+1)
A patch version bump occurs by default when:
- The PR doesn't match any of the above criteria
## Manual Version Control
If you need to manually control the version:
1. You can add specific labels to your PR:
- `major` for a major version bump
- `minor` or `feature` for a minor version bump
- Any other label will result in a patch version bump
2. You can include specific keywords in your PR title:
- "BREAKING CHANGE" or "major" for a major version bump
- "feat", "feature", or "minor" for a minor version bump
## Example PR Titles
- `feat: add new command for user management` → Minor version bump
- `fix: resolve issue with file uploads` → Patch version bump
- `BREAKING CHANGE: change API response format` → Major version bump
- `chore: update dependencies` → Patch version bump