Bump Version and Publish #8
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: Bump Version and Publish | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version_type: | |
| description: "Version bump type" | |
| required: true | |
| default: "patch" | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| permissions: | |
| contents: write | |
| id-token: write | |
| jobs: | |
| bump-and-publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Get current version | |
| id: current | |
| run: | | |
| VERSION=$(grep '^version:' codemod.yaml | sed 's/version: *"//' | sed 's/"//') | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Calculate new version | |
| id: new | |
| run: | | |
| VERSION="${{ steps.current.outputs.version }}" | |
| IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION" | |
| case "${{ inputs.version_type }}" in | |
| major) | |
| MAJOR=$((MAJOR + 1)) | |
| MINOR=0 | |
| PATCH=0 | |
| ;; | |
| minor) | |
| MINOR=$((MINOR + 1)) | |
| PATCH=0 | |
| ;; | |
| patch) | |
| PATCH=$((PATCH + 1)) | |
| ;; | |
| esac | |
| NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}" | |
| echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| - name: Update codemod.yaml | |
| run: | | |
| sed -i 's/^version: *".*"/version: "${{ steps.new.outputs.version }}"/' codemod.yaml | |
| # This does not trigger the release.yml workflow because GitHub Actions does not support triggering workflows from within a workflow. | |
| - name: Commit and tag | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add codemod.yaml | |
| git commit -m "chore: bump version to ${{ steps.new.outputs.version }}" | |
| git tag "v${{ steps.new.outputs.version }}" | |
| git push origin main --tags | |
| - name: Publish codemod | |
| uses: codemod/publish-action@v1 |