Skip to content

Commit 43c7f8d

Browse files
Bucknallaclaude
andauthored
Add auto version bump workflow on tagged releases (#149)
New update-version.yml workflow triggers on v* tag pushes and updates pyproject.toml on main to match the tag version. The publish workflow now sets the version from the tag in-place before building, replacing the old version mismatch check. Also bumps action versions to v4/v5. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 698f335 commit 43c7f8d

2 files changed

Lines changed: 37 additions & 14 deletions

File tree

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This workflows will upload a Python Package using Twine when a release is created
1+
# This workflow will upload a Python Package using Twine when a release is created
22
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
33

44
name: Upload Python Package
@@ -12,27 +12,23 @@ jobs:
1212
deploy:
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v4
16+
- name: Extract version from tag
17+
run: echo "TAG_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
18+
- name: Set version from tag
19+
run: sed -i "s/^version = \".*\"/version = \"$TAG_VERSION\"/" pyproject.toml
1620
- name: Set up Python
17-
uses: actions/setup-python@v2
21+
uses: actions/setup-python@v5
1822
with:
1923
python-version: '3.x'
2024
- name: Install dependencies
2125
run: |
2226
python -m pip install --upgrade pip
2327
pip install build twine
24-
- name: Check version matches
28+
- name: Verify version
2529
run: |
26-
# Extract version from pyproject.toml using Python
2730
PACKAGE_VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
28-
# Extract version from git tag (remove 'v' prefix)
29-
GIT_TAG_VERSION=${GITHUB_REF#refs/tags/v}
30-
# Compare versions
31-
if [ "$PACKAGE_VERSION" != "$GIT_TAG_VERSION" ]; then
32-
echo "Error: Version mismatch between pyproject.toml ($PACKAGE_VERSION) and git tag ($GIT_TAG_VERSION)"
33-
exit 1
34-
fi
35-
echo "Version check passed: $PACKAGE_VERSION"
31+
echo "Publishing version: $PACKAGE_VERSION"
3632
- name: Build and publish
3733
env:
3834
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
@@ -48,4 +44,3 @@ jobs:
4844
--header 'Content-Type: application/json' \
4945
--header 'X-Session-Token: ${{ secrets.NOTEHUB_SESSION_TOKEN }}' \
5046
--data '{"req":"note.add","file":"build_results.qi","body":{"result":"upload_failed"}}'
51-
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Update Version
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
8+
jobs:
9+
update-version:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
steps:
14+
- uses: actions/checkout@v4
15+
with:
16+
ref: main
17+
- name: Extract version from tag
18+
run: echo "TAG_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
19+
- name: Update pyproject.toml version
20+
run: sed -i "s/^version = \".*\"/version = \"$TAG_VERSION\"/" pyproject.toml
21+
- name: Commit and push version update
22+
run: |
23+
git config user.name "github-actions[bot]"
24+
git config user.email "github-actions[bot]@users.noreply.github.com"
25+
git diff --exit-code pyproject.toml && echo "Version already up to date" && exit 0
26+
git add pyproject.toml
27+
git commit -m "Bump version to $TAG_VERSION"
28+
git push origin main

0 commit comments

Comments
 (0)