Skip to content

Commit 186a3b7

Browse files
committed
Auto-bump patch version before twine upload and release
The stable publish job now bumps the patch in both stable.toml and dev.toml, commits the bump back to main with [skip ci], and then builds/uploads/releases using the new version. Developers no longer need to hand-edit the TOMLs before merging to main. CLAUDE.md updated to describe the new behaviour.
1 parent 6bfed5c commit 186a3b7

2 files changed

Lines changed: 38 additions & 7 deletions

File tree

.github/workflows/ci-stable.yml

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ jobs:
6767
contents: write
6868
steps:
6969
- uses: actions/checkout@v4
70+
with:
71+
token: ${{ secrets.GITHUB_TOKEN }}
7072
- name: Set up Python
7173
uses: actions/setup-python@v5
7274
with:
@@ -76,13 +78,41 @@ jobs:
7678
run: |
7779
python -m pip install --upgrade pip
7880
pip install build twine
79-
- name: Use stable.toml as pyproject.toml
80-
run: cp stable.toml pyproject.toml
81-
- name: Extract version
81+
- name: Bump patch version in stable.toml and dev.toml
8282
id: version
8383
run: |
84-
VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
85-
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
84+
python - <<'PY'
85+
import os
86+
import pathlib
87+
import re
88+
89+
def bump(path: pathlib.Path) -> str:
90+
text = path.read_text(encoding="utf-8")
91+
match = re.search(r'^version = "(\d+)\.(\d+)\.(\d+)"', text, re.MULTILINE)
92+
if match is None:
93+
raise SystemExit(f"no version line found in {path}")
94+
major, minor, patch = (int(g) for g in match.groups())
95+
new = f"{major}.{minor}.{patch + 1}"
96+
path.write_text(text.replace(match.group(0), f'version = "{new}"', 1), encoding="utf-8")
97+
return new
98+
99+
stable_version = bump(pathlib.Path("stable.toml"))
100+
dev_version = bump(pathlib.Path("dev.toml"))
101+
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as fp:
102+
fp.write(f"version={stable_version}\n")
103+
fp.write(f"dev_version={dev_version}\n")
104+
print(f"stable.toml -> {stable_version}")
105+
print(f"dev.toml -> {dev_version}")
106+
PY
107+
- name: Commit bumped versions back to main
108+
run: |
109+
git config user.name "github-actions[bot]"
110+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
111+
git add stable.toml dev.toml
112+
git commit -m "Bump version to v${{ steps.version.outputs.version }} [skip ci]"
113+
git push origin HEAD:main
114+
- name: Use stable.toml as pyproject.toml
115+
run: cp stable.toml pyproject.toml
86116
- name: Build sdist and wheel
87117
run: python -m build
88118
- name: Twine check

CLAUDE.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ automation_file/
9494

9595
- `main` branch: stable releases, publishes `automation_file` to PyPI (version in `stable.toml`).
9696
- `dev` branch: development, publishes `automation_file_dev` to PyPI (version in `dev.toml`).
97-
- Keep both TOMLs in sync when bumping. `dependencies` and `[project.optional-dependencies]` (`dev`) must also stay in sync. Backends (`boto3`, `azure-storage-blob`, `dropbox`, `paramiko`) and `PySide6` are first-class runtime deps — do not move them back under extras.
97+
- Keep `dependencies` and `[project.optional-dependencies]` (`dev`) in sync across both TOMLs. Backends (`boto3`, `azure-storage-blob`, `dropbox`, `paramiko`) and `PySide6` are first-class runtime deps — do not move them back under extras.
98+
- **Version bumping is automatic.** The stable publish job bumps the patch in both `stable.toml` and `dev.toml`, commits the bump back to `main` with `[skip ci]`, then builds and releases. Do not hand-bump before merging to `main`.
9899
- CI: GitHub Actions (Windows, Python 3.10 / 3.11 / 3.12) — one matrix workflow per branch: `.github/workflows/ci-dev.yml`, `.github/workflows/ci-stable.yml`.
99100
- CI steps: `lint` (ruff check + ruff format --check + mypy) → `pytest` with coverage → uploads `coverage.xml` as an artifact.
100-
- Stable branch additionally runs a `publish` job on push to `main`: builds the sdist + wheel, `twine check`, `twine upload` using `PYPI_API_TOKEN`, then `gh release create v<version> --generate-notes`.
101+
- Stable branch additionally runs a `publish` job on push to `main`: auto-bumps the patch in both TOMLs and commits back, then builds the sdist + wheel, `twine check`, `twine upload` using `PYPI_API_TOKEN`, then `gh release create v<version> --generate-notes`.
101102
- `pre-commit` is configured (`.pre-commit-config.yaml`): trailing-whitespace, eof-fixer, check-yaml, check-toml, check-added-large-files, ruff, ruff-format, mypy. Install with `pre-commit install` after cloning.
102103

103104
## Development

0 commit comments

Comments
 (0)