Merge pull request #114 from ElioNeto/feature/issue-106 #41
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: Auto Release | |
| # Triggers on push to 'main' (i.e., when a PR is merged) | |
| on: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: write # Required to commit version bump, create tags, and releases | |
| jobs: | |
| release: | |
| name: Bump version and create release | |
| runs-on: ubuntu-latest | |
| # Skip if commit was made by github-actions bot (avoid infinite loop) | |
| if: github.actor != 'github-actions[bot]' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup Rust toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Configure Git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Read current version from Cargo.toml | |
| id: current_version | |
| run: | | |
| CURRENT_VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') | |
| echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT | |
| echo "Current version: $CURRENT_VERSION" | |
| - name: Bump patch version | |
| id: new_version | |
| run: | | |
| CURRENT="${{ steps.current_version.outputs.current }}" | |
| IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT" | |
| NEW_PATCH=$((PATCH + 1)) | |
| NEW_VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}" | |
| echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| echo "New version: $NEW_VERSION" | |
| - name: Update Cargo.toml with new version | |
| run: | | |
| sed -i 's/^version = ".*"/version = "${{ steps.new_version.outputs.version }}"/' Cargo.toml | |
| cat Cargo.toml | grep '^version =' | |
| - name: Update Cargo.lock | |
| run: cargo update --workspace | |
| - name: Commit version bump | |
| run: | | |
| git add Cargo.toml Cargo.lock | |
| git commit -m "chore: bump version to ${{ steps.new_version.outputs.version }} [skip ci]" | |
| git push origin main | |
| - name: Create and push tag | |
| run: | | |
| TAG="v${{ steps.new_version.outputs.version }}" | |
| git tag "$TAG" | |
| git push origin "$TAG" | |
| echo "Created tag: $TAG" | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ steps.new_version.outputs.version }} | |
| name: Release v${{ steps.new_version.outputs.version }} | |
| generate_release_notes: true | |
| draft: false | |
| prerelease: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |