|
| 1 | +# GitHub action to bump version, update changelog, and create pull request for review. |
| 2 | + |
| 3 | +name: Bump Version |
| 4 | +run-name: Bump version (${{ inputs.bump-type }}) by @${{ github.actor }} |
| 5 | + |
| 6 | +# Note: Enable GitHub Actions to create pull requests in repository settings: |
| 7 | +# Settings -> Actions -> General -> Workflow permissions -> Allow GitHub Actions to create and approve pull requests |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + pull-requests: write |
| 12 | + |
| 13 | +on: |
| 14 | + workflow_dispatch: |
| 15 | + inputs: |
| 16 | + bump-type: |
| 17 | + description: 'Version bump type' |
| 18 | + required: true |
| 19 | + default: 'patch' |
| 20 | + type: choice |
| 21 | + options: |
| 22 | + - major |
| 23 | + - minor |
| 24 | + - patch |
| 25 | + fail-on-empty-changelog: |
| 26 | + description: 'Fail if changelog is empty' |
| 27 | + required: false |
| 28 | + default: true |
| 29 | + type: boolean |
| 30 | + |
| 31 | +jobs: |
| 32 | + bump_version: |
| 33 | + runs-on: ubuntu-latest |
| 34 | + |
| 35 | + outputs: |
| 36 | + version: ${{ steps.bump.outputs.current-version }} |
| 37 | + pr-number: ${{ steps.create_pr.outputs.pull-request-number }} |
| 38 | + |
| 39 | + steps: |
| 40 | + - name: Checkout repository |
| 41 | + uses: actions/checkout@v5 |
| 42 | + with: |
| 43 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + |
| 45 | + - name: Setup Python environment |
| 46 | + uses: astral-sh/setup-uv@v6 |
| 47 | + |
| 48 | + - name: Install bump-my-version |
| 49 | + run: uv tool install bump-my-version |
| 50 | + |
| 51 | + - name: Bump version |
| 52 | + id: bump |
| 53 | + shell: bash |
| 54 | + run: | |
| 55 | + echo "::notice::Bumping version with type: ${{ inputs.bump-type }}" |
| 56 | + bump-my-version bump ${{ inputs.bump-type }} |
| 57 | + |
| 58 | + CURRENT_VERSION=$(bump-my-version show current_version) |
| 59 | + echo "current-version=$CURRENT_VERSION" >> $GITHUB_OUTPUT |
| 60 | + echo "::notice::Current version: $CURRENT_VERSION" |
| 61 | +
|
| 62 | + - name: Update changelog |
| 63 | + id: changelog |
| 64 | + uses: release-flow/keep-a-changelog-action@v2 |
| 65 | + with: |
| 66 | + command: bump |
| 67 | + version: ${{ inputs.bump-type }} |
| 68 | + keep-unreleased-section: true |
| 69 | + fail-on-empty-release-notes: ${{ inputs.fail-on-empty-changelog }} |
| 70 | + |
| 71 | + - name: Query changelog for release notes |
| 72 | + id: query_changelog |
| 73 | + uses: release-flow/keep-a-changelog-action@v2 |
| 74 | + with: |
| 75 | + command: query |
| 76 | + version: latest |
| 77 | + |
| 78 | + - name: Configure Git |
| 79 | + id: git_setup |
| 80 | + run: | |
| 81 | + # Configure Git user |
| 82 | + git config --global user.name "${{ github.actor }}" |
| 83 | + git config --global user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com" |
| 84 | +
|
| 85 | + - name: Create version commit |
| 86 | + id: create_commit |
| 87 | + run: | |
| 88 | + git add . |
| 89 | + git commit -m "docs: Increase version to ${{ steps.bump.outputs.current-version }} (${{ inputs.bump-type }} bump)" |
| 90 | + echo "::notice::Commit created, will be pushed via pull request" |
| 91 | +
|
| 92 | + - name: Create Pull Request |
| 93 | + id: create_pr |
| 94 | + uses: peter-evans/create-pull-request@v7 |
| 95 | + with: |
| 96 | + title: "Bump version to ${{ steps.bump.outputs.current-version }} (${{ inputs.bump-type }} bump)" |
| 97 | + body: | |
| 98 | + This PR **${{ inputs.bump-type }}** bumps the version to `${{ steps.bump.outputs.current-version }}` and updates the changelog. |
| 99 | + |
| 100 | + ### Reviewer Checklist |
| 101 | + Please verify the following before merging: |
| 102 | + |
| 103 | + - [ ] **Version bump type is appropriate**: Confirm that the `${{ inputs.bump-type }}` bump matches the nature of changes since the last version: |
| 104 | + - **Major**: Breaking changes or significant API modifications |
| 105 | + - **Minor**: New features or functionality additions (backward compatible) |
| 106 | + - **Patch**: Bug fixes, documentation updates, or minor improvements |
| 107 | + - **no bump necessary**: Changes only to tests, CI, documentation, or examples. |
| 108 | + |
| 109 | + If the bump type is not appropriate, close the PR and re-run the workflow with the correct bump type. |
| 110 | + |
| 111 | + - [ ] **Changelog accuracy**: Review that the changelog entries accurately reflect the changes being released, and are understandable to end users. |
| 112 | + |
| 113 | + If not, edit the changelog before merging. |
| 114 | + |
| 115 | + ### Next Steps |
| 116 | + After merging this PR, **trigger a release** to publish version `${{ steps.bump.outputs.current-version }}`. |
| 117 | + |
| 118 | + ### Changelog (automatically extracted from Unreleased section) |
| 119 | + ${{ steps.query_changelog.outputs.release-notes }} |
| 120 | + |
| 121 | + --- |
| 122 | + *This PR was automatically created by the Bump Version workflow* |
| 123 | + branch: bumpversion-${{ steps.bump.outputs.current-version }} |
| 124 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 125 | + delete-branch: true |
| 126 | + |
| 127 | + - name: Summary |
| 128 | + if: always() |
| 129 | + run: | |
| 130 | + echo "## Workflow Summary" >> $GITHUB_STEP_SUMMARY |
| 131 | + echo "- **Bump Type:** ${{ inputs.bump-type }}" >> $GITHUB_STEP_SUMMARY |
| 132 | + echo "- **Version:** ${{ steps.bump.outputs.current-version }}" >> $GITHUB_STEP_SUMMARY |
| 133 | + |
| 134 | + if [[ "${{ steps.create_pr.outputs.pull-request-number }}" != "" ]]; then |
| 135 | + PR_NUMBER="${{ steps.create_pr.outputs.pull-request-number }}" |
| 136 | + PR_URL="https://github.com/${{ github.repository }}/pull/$PR_NUMBER" |
| 137 | + echo "- **Pull Request:** [#$PR_NUMBER]($PR_URL)" >> $GITHUB_STEP_SUMMARY |
| 138 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 139 | + echo "### Next Steps" >> $GITHUB_STEP_SUMMARY |
| 140 | + echo "1. Review and merge [Pull Request #$PR_NUMBER]($PR_URL)" >> $GITHUB_STEP_SUMMARY |
| 141 | + echo "2. **Trigger a release** to publish version \`${{ steps.bump.outputs.current-version }}\`" >> $GITHUB_STEP_SUMMARY |
| 142 | + else |
| 143 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 144 | + echo "### ⚠️ Warning" >> $GITHUB_STEP_SUMMARY |
| 145 | + echo "Pull request creation failed. Please check the workflow logs." >> $GITHUB_STEP_SUMMARY |
| 146 | + fi |
| 147 | + |
| 148 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 149 | + echo "### 📋 Workflow Details" >> $GITHUB_STEP_SUMMARY |
| 150 | + echo "- **Triggered by:** @${{ github.actor }}" >> $GITHUB_STEP_SUMMARY |
| 151 | + echo "- **Repository:** ${{ github.repository }}" >> $GITHUB_STEP_SUMMARY |
| 152 | + echo "- **Run ID:** [${{ github.run_id }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})" >> $GITHUB_STEP_SUMMARY |
0 commit comments