fix: Update version bump workflow to work with branch protection rules #2
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Version Bump on PR Merge | |
| on: | |
| pull_request: | |
| types: [closed] | |
| branches: | |
| - main | |
| jobs: | |
| version-bump: | |
| if: github.event.pull_request.merged == true | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| ref: main | |
| - name: Setup Rust | |
| uses: actions-rs/toolchain@v1 | |
| with: | |
| toolchain: stable | |
| profile: minimal | |
| override: true | |
| - name: Install cargo-edit | |
| run: cargo install cargo-edit | |
| - name: Get current version | |
| id: get_version | |
| run: | | |
| CURRENT_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version') | |
| echo "current_version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT" | |
| echo "Current version: $CURRENT_VERSION" | |
| - name: Bump minor version | |
| run: | | |
| cargo set-version --bump minor | |
| NEW_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version') | |
| echo "New version: $NEW_VERSION" | |
| echo "new_version=$NEW_VERSION" >> "$GITHUB_ENV" | |
| - name: Configure Git | |
| run: | | |
| git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| - name: Create version bump branch and commit | |
| run: | | |
| git checkout -b "release/v${{ env.new_version }}" | |
| git add Cargo.toml Cargo.lock | |
| git commit -m "Release v${{ env.new_version }}" | |
| git tag "v${{ env.new_version }}" | |
| - name: Build release artifacts | |
| run: | | |
| cargo build --release | |
| cargo test --release | |
| - name: Push tag | |
| run: | | |
| git push origin "v${{ env.new_version }}" | |
| - name: Publish to crates.io | |
| run: | | |
| cargo publish | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
| - name: Create GitHub Release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: v${{ env.new_version }} | |
| release_name: Release v${{ env.new_version }} | |
| body: | | |
| ## Changes in this release | |
| This release was automatically created from PR #${{ github.event.pull_request.number }} | |
| **PR Title:** ${{ github.event.pull_request.title }} | |
| **Merged by:** @${{ github.event.pull_request.merged_by.login }} | |
| ### Published to crates.io | |
| This version has been published to [crates.io](https://crates.io/crates/gonfig) and is available for use in your projects. | |
| ```toml | |
| [dependencies] | |
| gonfig = "${{ env.new_version }}" | |
| ``` | |
| draft: false | |
| prerelease: false | |
| - name: Create version update PR | |
| run: | | |
| git push origin "release/v${{ env.new_version }}" | |
| gh pr create --title "Update version to v${{ env.new_version }}" \ | |
| --body "Automated version update following release v${{ env.new_version }}" \ | |
| --base main \ | |
| --head "release/v${{ env.new_version }}" | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |