|
| 1 | +name: Automated Version Bump |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + part: |
| 9 | + description: Version segment to bump |
| 10 | + required: true |
| 11 | + default: patch |
| 12 | + type: choice |
| 13 | + options: |
| 14 | + - patch |
| 15 | + - minor |
| 16 | + - major |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: write |
| 20 | + |
| 21 | +jobs: |
| 22 | + bump: |
| 23 | + if: ${{ github.actor != 'github-actions[bot]' && (github.event_name == 'workflow_dispatch' || !contains(github.event.head_commit.message, '[skip bump]')) }} |
| 24 | + runs-on: ubuntu-latest |
| 25 | + timeout-minutes: 10 |
| 26 | + steps: |
| 27 | + - name: Checkout repository |
| 28 | + uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + fetch-depth: 0 |
| 31 | + |
| 32 | + - name: Setup Python |
| 33 | + uses: actions/setup-python@v5 |
| 34 | + with: |
| 35 | + python-version: "3.12" |
| 36 | + |
| 37 | + - name: Choose bump part |
| 38 | + id: bump_part |
| 39 | + run: | |
| 40 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 41 | + echo "value=${{ inputs.part }}" >> "$GITHUB_OUTPUT" |
| 42 | + else |
| 43 | + echo "value=patch" >> "$GITHUB_OUTPUT" |
| 44 | + fi |
| 45 | +
|
| 46 | + - name: Bump version in pyproject.toml |
| 47 | + id: bump |
| 48 | + run: | |
| 49 | + NEW_VERSION=$(python scripts/bump_version.py --part "${{ steps.bump_part.outputs.value }}" --file pyproject.toml) |
| 50 | + echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT" |
| 51 | +
|
| 52 | + - name: Commit and tag version bump |
| 53 | + env: |
| 54 | + NEW_VERSION: ${{ steps.bump.outputs.new_version }} |
| 55 | + GIT_AUTHOR_NAME: github-actions[bot] |
| 56 | + GIT_AUTHOR_EMAIL: github-actions[bot]@users.noreply.github.com |
| 57 | + GIT_COMMITTER_NAME: github-actions[bot] |
| 58 | + GIT_COMMITTER_EMAIL: github-actions[bot]@users.noreply.github.com |
| 59 | + run: | |
| 60 | + if [ -z "$NEW_VERSION" ]; then |
| 61 | + echo "No new version produced; exiting." |
| 62 | + exit 1 |
| 63 | + fi |
| 64 | + git add pyproject.toml |
| 65 | + git commit -m "chore: bump version to $NEW_VERSION [skip ci][skip bump]" || exit 0 |
| 66 | + git tag "v$NEW_VERSION" |
| 67 | + git push origin main |
| 68 | + git push origin "v$NEW_VERSION" |
0 commit comments