Skip to content

Commit 040def9

Browse files
committed
Add bump-version workflow and simplify publish
Add a new workflow (.github/workflows/bump-version.yml) that bumps the package version, generates changelog/HISTORY.rst, and commits changes when a release label (release:major/minor/patch) is added to an open PR. Simplify .github/workflows/publish.yml to only run publish steps on PR close/merge, remove the prior in-publish version-bump/update job, and keep a single publish job that creates a GitHub Release and uploads to TestPyPI then PyPI. Also update the bump-my-version call to use `show current_version` and make minor permission/formatting adjustments.
1 parent b6a360f commit 040def9

File tree

2 files changed

+114
-93
lines changed

2 files changed

+114
-93
lines changed

.github/workflows/bump-version.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: Bump Version on Release Label
2+
3+
on:
4+
pull_request:
5+
types: [labeled]
6+
branches:
7+
- master
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
jobs:
14+
bump-version:
15+
# Run only when a release label is added to an open PR
16+
if: |
17+
github.event.pull_request.state == 'open' && (
18+
github.event.label.name == 'release:major' ||
19+
github.event.label.name == 'release:minor' ||
20+
github.event.label.name == 'release:patch'
21+
)
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- name: Check out PR branch
26+
uses: actions/checkout@v4
27+
with:
28+
ref: ${{ github.head_ref }}
29+
fetch-depth: 0
30+
token: ${{ secrets.GITHUB_TOKEN }}
31+
32+
- name: Set up Python
33+
uses: actions/setup-python@v5
34+
with:
35+
python-version: "3.13"
36+
37+
- name: Install tools
38+
run: |
39+
pip install bump-my-version pandoc
40+
sudo apt-get update
41+
sudo apt-get install -y pandoc
42+
cargo install git-cliff
43+
44+
- name: Set up Git user
45+
run: |
46+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
47+
git config --local user.name "github-actions[bot]"
48+
49+
- name: Determine version bump type
50+
id: bump
51+
run: |
52+
if [[ "${{ github.event.label.name }}" == "release:major" ]]; then
53+
echo "type=major" >> $GITHUB_OUTPUT
54+
elif [[ "${{ github.event.label.name }}" == "release:minor" ]]; then
55+
echo "type=minor" >> $GITHUB_OUTPUT
56+
else
57+
echo "type=patch" >> $GITHUB_OUTPUT
58+
fi
59+
60+
- name: Bump version
61+
run: bump-my-version bump ${{ steps.bump.outputs.type }}
62+
env:
63+
BMV_ALLOW_DIRTY: "true"
64+
65+
- name: Extract version
66+
id: version
67+
run: |
68+
VERSION=$(bump-my-version show current)
69+
echo "Extracted version: $VERSION"
70+
echo "version=$VERSION" >> $GITHUB_OUTPUT
71+
72+
- name: Generate changelog
73+
run: |
74+
git cliff --unreleased --tag v${{ steps.version.outputs.version }} -o CHANGELOG.md
75+
echo "Generated changelog for version ${{ steps.version.outputs.version }}"
76+
77+
- name: Update HISTORY.rst
78+
run: |
79+
# Convert CHANGELOG.md to rst and prepend to HISTORY.rst
80+
if [ -f CHANGELOG.md ]; then
81+
pandoc CHANGELOG.md -f markdown -t rst -o CHANGELOG.rst
82+
# Prepend new changelog to HISTORY.rst
83+
if [ -f HISTORY.rst ]; then
84+
cat CHANGELOG.rst HISTORY.rst > HISTORY_temp.rst
85+
mv HISTORY_temp.rst HISTORY.rst
86+
echo "Updated HISTORY.rst with version ${{ steps.version.outputs.version }}"
87+
else
88+
mv CHANGELOG.rst HISTORY.rst
89+
echo "Created HISTORY.rst"
90+
fi
91+
fi
92+
93+
- name: Commit and push changes to PR branch
94+
run: |
95+
git add .
96+
git commit -m "chore: bump version to ${{ steps.version.outputs.version }} and update changelog [skip ci]" || echo "No changes to commit"
97+
git push origin HEAD:${{ github.head_ref }}
98+
99+
- name: Add comment to PR
100+
uses: actions/github-script@v7
101+
with:
102+
script: |
103+
github.rest.issues.createComment({
104+
issue_number: context.issue.number,
105+
owner: context.repo.owner,
106+
repo: context.repo.repo,
107+
body: '🚀 Version bumped to **v${{ steps.version.outputs.version }}** and changelog updated. Ready to merge!'
108+
})

.github/workflows/publish.yml

Lines changed: 6 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,17 @@
1-
name: Publish on PR merge
1+
name: Publish to PyPI
22

33
on:
44
pull_request:
5-
types: [opened, synchronize, reopened, labeled, closed]
5+
types: [closed]
66
branches:
77
- master
88

99
permissions:
1010
contents: write
1111
id-token: write
12-
pull-requests: write
1312

1413
jobs:
15-
update-version-and-changelog:
16-
# Run only when a release label is added (not on every push)
17-
if: |
18-
github.event.action == 'labeled' &&
19-
github.event.pull_request.merged == false && (
20-
contains(github.event.pull_request.labels.*.name, 'release:major') ||
21-
contains(github.event.pull_request.labels.*.name, 'release:minor') ||
22-
contains(github.event.pull_request.labels.*.name, 'release:patch')
23-
)
24-
runs-on: ubuntu-latest
25-
26-
steps:
27-
- name: Check out PR branch
28-
uses: actions/checkout@v4
29-
with:
30-
ref: ${{ github.head_ref }}
31-
fetch-depth: 0
32-
token: ${{ secrets.GITHUB_TOKEN }}
33-
34-
- name: Set up Python
35-
uses: actions/setup-python@v5
36-
with:
37-
python-version: "3.13"
38-
39-
- name: Install tools
40-
run: |
41-
pip install bump-my-version build pandoc
42-
sudo apt-get update
43-
sudo apt-get install -y pandoc
44-
cargo install git-cliff
45-
46-
- name: Set up Git user
47-
run: |
48-
git config --local user.email "github-actions[bot]@users.noreply.github.com"
49-
git config --local user.name "github-actions[bot]"
50-
51-
- name: Determine version bump type
52-
id: bump
53-
run: |
54-
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'release:major') }}" == "true" ]]; then
55-
echo "type=major" >> $GITHUB_OUTPUT
56-
elif [[ "${{ contains(github.event.pull_request.labels.*.name, 'release:minor') }}" == "true" ]]; then
57-
echo "type=minor" >> $GITHUB_OUTPUT
58-
else
59-
echo "type=patch" >> $GITHUB_OUTPUT
60-
fi
61-
62-
- name: Bump version
63-
run: bump-my-version bump ${{ steps.bump.outputs.type }}
64-
env:
65-
BMV_ALLOW_DIRTY: "true"
66-
67-
- name: Extract version
68-
id: version
69-
run: |
70-
VERSION=$(bump-my-version show current)
71-
echo "Extracted version: $VERSION"
72-
echo "version=$VERSION" >> $GITHUB_OUTPUT
73-
74-
- name: Generate changelog
75-
run: |
76-
git cliff --unreleased --tag ${{ steps.version.outputs.version }} -o CHANGELOG.md
77-
echo "Generated changelog for version ${{ steps.version.outputs.version }}"
78-
79-
- name: Update HISTORY.rst
80-
run: |
81-
# Convert CHANGELOG.md to rst and prepend to HISTORY.rst
82-
if [ -f CHANGELOG.md ]; then
83-
pandoc CHANGELOG.md -f markdown -t rst -o CHANGELOG.rst
84-
# Prepend new changelog to HISTORY.rst
85-
if [ -f HISTORY.rst ]; then
86-
cat HISTORY.rst CHANGELOG.rst > HISTORY_temp.rst
87-
mv HISTORY_temp.rst HISTORY.rst
88-
echo "Updated HISTORY.rst with version ${{ steps.version.outputs.version }}"
89-
else
90-
mv CHANGELOG.rst HISTORY.rst
91-
echo "Created HISTORY.rst"
92-
fi
93-
fi
94-
95-
- name: Commit and push changes to PR branch
96-
run: |
97-
git add .
98-
git commit -m "chore: bump version to ${{ steps.version.outputs.version }} and update changelog [skip ci]" || echo "No changes to commit"
99-
git push origin HEAD:${{ github.head_ref }}
100-
101-
publish-after-merge:
14+
publish:
10215
# Run only after PR is merged with release labels
10316
if: |
10417
github.event.pull_request.merged == true && (
@@ -125,7 +38,7 @@ jobs:
12538
- name: Extract version
12639
id: version
12740
run: |
128-
VERSION=$(bump-my-version show current)
41+
VERSION=$(bump-my-version show current_version)
12942
echo "version=$VERSION" >> $GITHUB_OUTPUT
13043
13144
- name: Create GitHub Release
@@ -146,9 +59,9 @@ jobs:
14659
repository-url: https://test.pypi.org/legacy/
14760
skip-existing: true
14861
attestations: false
149-
62+
15063
- name: Publish to PyPI
15164
if: steps.test-pypi.outcome == 'success'
15265
uses: pypa/gh-action-pypi-publish@v1.13.0
15366
with:
154-
skip-existing: true
67+
skip-existing: true

0 commit comments

Comments
 (0)