version-bump #2
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: | |
| workflow_dispatch: | |
| inputs: | |
| release_type: | |
| description: "Release Type" | |
| type: choice | |
| required: true | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| default: patch | |
| jobs: | |
| create-version-bump-pr: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: get current version and calculate new version | |
| id: version | |
| uses: actions/github-script@v7 | |
| env: | |
| RELEASE_TYPE: ${{ inputs.release_type }} | |
| with: | |
| script: | | |
| const fs = require('fs') | |
| const cargoToml = fs.readFileSync('./Cargo.toml', 'utf8') | |
| const versionMatch = cargoToml.match(/version\s*=\s*"(\d+\.\d+\.\d+)"/) | |
| if (!versionMatch) { | |
| throw new Error('Version not found in Cargo.toml') | |
| } | |
| const version = versionMatch[1] | |
| const [major, minor, patch] = version.split('.').map(Number) | |
| let newVersion | |
| if (process.env.RELEASE_TYPE === 'major') { | |
| newVersion = `${major + 1}.0.0` | |
| } else if (process.env.RELEASE_TYPE === 'minor') { | |
| newVersion = `${major}.${minor + 1}.0` | |
| } else { | |
| newVersion = `${major}.${minor}.${patch + 1}` | |
| } | |
| core.setOutput('current_version', version) | |
| core.setOutput('new_version', newVersion) | |
| console.log(`Bumping version from ${version} to ${newVersion}`) | |
| - name: update Cargo.toml and Cargo.lock | |
| run: | | |
| sed -i 's/^version = ".*"/version = "${{ steps.version.outputs.new_version }}"/' Cargo.toml | |
| cargo update server | |
| - name: update package.json | |
| run: | | |
| npm version ${{ inputs.release_type }} --no-git-tag-version | |
| - name: create pull request | |
| uses: peter-evans/create-pull-request@v7 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| commit-message: "release(${{ inputs.release_type }}): ${{ steps.version.outputs.new_version }}" | |
| branch: release/v${{ steps.version.outputs.new_version }} | |
| delete-branch: true | |
| title: "release(${{ inputs.release_type }}): ${{ steps.version.outputs.new_version }}" | |
| body: | | |
| ## Version Bump: ${{ inputs.release_type }} | |
| This PR bumps the version from `${{ steps.version.outputs.current_version }}` to `${{ steps.version.outputs.new_version }}`. | |
| ### Next Steps | |
| Once this PR is merged, the deploy workflow will automatically trigger to publish a new image. |