Skip to content

Commit 4c088b0

Browse files
ci: add bumpversion github workflow
1 parent 60e113c commit 4c088b0

File tree

1 file changed

+154
-0
lines changed

1 file changed

+154
-0
lines changed

.github/workflows/bumpversion.yml

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
name: Bump Version
2+
run-name: Bump version (${{ inputs.bump-type }}) by @${{ github.actor }}
3+
4+
# Note: need to allow GitHub Actions to create pull requests in repository
5+
# settings (Actions -> General - > Workflow permissions).
6+
# Optional secrets:
7+
# - GPG_PRIVATE_KEY: The private GPG key for signing commits and tags
8+
# - GPG_KEY_ID: The GPG key ID for signing commits and tags
9+
10+
permissions:
11+
contents: write
12+
pull-requests: write
13+
14+
on:
15+
workflow_dispatch:
16+
inputs:
17+
bump-type:
18+
description: 'Bump type'
19+
required: true
20+
default: 'patch'
21+
type: choice
22+
options:
23+
- major
24+
- minor
25+
- patch
26+
- post-review-release # Do not bump version, just create tag & release based on latest changelog
27+
fail-on-empty-changelog:
28+
description: 'Fail if changelog is empty'
29+
required: false
30+
default: true
31+
type: boolean
32+
create-pull-request:
33+
description: 'Create pull request for review'
34+
required: false
35+
default: true
36+
type: boolean
37+
gpg-signing:
38+
description: 'Sign commits and tags with GPG'
39+
required: false
40+
default: true
41+
type: boolean
42+
43+
jobs:
44+
bump_version:
45+
runs-on: ubuntu-latest
46+
steps:
47+
- name: Checkout the code
48+
uses: actions/checkout@v5
49+
with:
50+
token: ${{ secrets.GITHUB_TOKEN }}
51+
52+
- name: Install uv
53+
uses: astral-sh/setup-uv@v6
54+
55+
- name: Install bump-my-version
56+
run: |
57+
uv tool install bump-my-version
58+
59+
# Bump version in source files (if necessary) and output current version
60+
- name: Bump version
61+
id: bump
62+
shell: bash
63+
run: |
64+
if [[ "${{ inputs.bump-type }}" == "post-review-release" ]]; then
65+
echo "Post-review-release selected, not bumping version"
66+
else
67+
bump-my-version bump ${{ inputs.bump-type }}
68+
fi
69+
echo "current-version=$(bump-my-version show current_version)" >> $GITHUB_OUTPUT
70+
71+
# Update changelog with new release section and tag links
72+
- name: Update changelog
73+
id: changelog
74+
uses: release-flow/keep-a-changelog-action@v2
75+
if: ${{ inputs.bump-type != 'post-review-release' }}
76+
with:
77+
command: bump
78+
version: ${{ inputs.bump-type }}
79+
keep-unreleased-section: true
80+
fail-on-empty-release-notes: ${{ inputs.fail-on-empty-changelog }}
81+
82+
# Query the changelog for the latest release notes, specifically for the case inputs.bump-type == 'post-review-release'
83+
- name: Query latest changelog
84+
id: query_changelog
85+
uses: release-flow/keep-a-changelog-action@v2
86+
with:
87+
command: query
88+
version: latest
89+
90+
- name: git config and GPG setup
91+
id: git_setup
92+
run: |
93+
if ${{ inputs.gpg-signing }}; then
94+
echo "${{ secrets.GPG_PRIVATE_KEY }}" | gpg --import --batch --yes
95+
echo "use-agent" >> ~/.gnupg/gpg.conf
96+
echo "default-cache-ttl 600" >> ~/.gnupg/gpg-agent.conf
97+
echo "max-cache-ttl 7200" >> ~/.gnupg/gpg-agent.conf
98+
echo "GPG setup complete"
99+
100+
git config --global commit.gpgSign true
101+
git config --global tag.gpgSign true
102+
git config --global user.signingkey "${{ secrets.GPG_KEY_ID }}"
103+
else
104+
echo "GPG signing disabled"
105+
git config --global commit.gpgSign false
106+
git config --global tag.gpgSign false
107+
fi
108+
109+
git config --global user.name "${{ github.actor }}"
110+
git config --global user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>"
111+
112+
- name: Create commit
113+
id: create_commit
114+
if: ${{ inputs.bump-type != 'post-review-release' }}
115+
run: |
116+
git add .
117+
git commit -m "docs: Increase version to ${{ steps.bump.outputs.current-version }}"
118+
119+
if ${{ inputs.create-pull-request }}; then
120+
echo "Not pushing commit, creating pull request instead"
121+
else
122+
git push
123+
fi
124+
125+
- name: Create Pull Request
126+
id: create_pr
127+
uses: peter-evans/create-pull-request@v7
128+
if: ${{ inputs.create-pull-request && inputs.bump-type != 'post-review-release' }}
129+
with:
130+
title: "Bump version to ${{ steps.bump.outputs.current-version }}"
131+
body: |
132+
This PR bumps the version to ${{ steps.bump.outputs.current-version }} and updates the changelog.
133+
After merging this PR, remember to re-trigger this action with the 'post-review-release' option to create the tag & release.
134+
branch: bumpversion-${{ steps.bump.outputs.current-version }}
135+
token: ${{ secrets.GITHUB_TOKEN }}
136+
137+
- name: Create tag
138+
id: create_tag
139+
if: ${{ ! inputs.create-pull-request || inputs.bump-type == 'post-review-release' }}
140+
run: |
141+
git tag v${{ steps.bump.outputs.current-version }} -m "Version ${{ steps.bump.outputs.current-version }}"
142+
git push origin v${{ steps.bump.outputs.current-version }}
143+
144+
- name: Create GitHub release
145+
id: create_release
146+
if: ${{ ! inputs.create-pull-request || inputs.bump-type == 'post-review-release' }}
147+
uses: ncipollo/release-action@v1
148+
with:
149+
tag: v${{ steps.bump.outputs.current-version }}
150+
name: v${{ steps.bump.outputs.current-version }}
151+
body: ${{ steps.query_changelog.outputs.release-notes }}
152+
draft: false
153+
prerelease: false
154+
token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)