Skip to content

Commit 1155cf5

Browse files
committed
Auto-release on merge to stable branch
Adds a publish job that runs after tests pass when stable is pushed: bumps the patch version in pyproject.toml, builds the distribution, uploads to PyPI, tags v<version>, pushes the bump back to stable, and creates a GitHub Release. Tests now also gate pushes/PRs against stable. A concurrency group prevents overlapping publishes per ref.
1 parent 71b751e commit 1155cf5

1 file changed

Lines changed: 85 additions & 2 deletions

File tree

.github/workflows/stable.yml

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ name: AutoControl Stable CI
22

33
on:
44
push:
5-
branches: [ "main" ]
5+
branches: [ "main", "stable" ]
66
pull_request:
7-
branches: [ "main" ]
7+
branches: [ "main", "stable" ]
88
schedule:
99
- cron: "0 1 * * *"
1010

1111
permissions:
1212
contents: read
1313

14+
concurrency:
15+
group: stable-publish-${{ github.ref }}
16+
cancel-in-progress: false
17+
1418
jobs:
1519
test:
1620
runs-on: windows-2022
@@ -111,3 +115,82 @@ jobs:
111115
run: python ./test/unit_test/get_info/mouse_info.py
112116
- name: Test Get Keyboard Info
113117
run: python ./test/unit_test/get_info/keyboard_info.py
118+
119+
publish:
120+
needs: test
121+
if: github.event_name == 'push' && github.ref == 'refs/heads/stable'
122+
runs-on: ubuntu-latest
123+
permissions:
124+
contents: write
125+
steps:
126+
- uses: actions/checkout@v4
127+
with:
128+
fetch-depth: 0
129+
token: ${{ secrets.GITHUB_TOKEN }}
130+
131+
- name: Set up Python
132+
uses: actions/setup-python@v5
133+
with:
134+
python-version: "3.12"
135+
136+
- name: Install build tooling
137+
run: |
138+
python -m pip install --upgrade pip
139+
pip install build twine
140+
141+
- name: Bump patch version in pyproject.toml
142+
id: bump
143+
run: |
144+
python <<'PY'
145+
import os
146+
import re
147+
import pathlib
148+
149+
path = pathlib.Path("pyproject.toml")
150+
text = path.read_text(encoding="utf-8")
151+
match = re.search(r'^version\s*=\s*"(\d+)\.(\d+)\.(\d+)"', text, flags=re.M)
152+
if not match:
153+
raise SystemExit("version line not found in pyproject.toml")
154+
major, minor, patch = (int(part) for part in match.groups())
155+
new_version = f"{major}.{minor}.{patch + 1}"
156+
text = re.sub(
157+
r'^version\s*=\s*"\d+\.\d+\.\d+"',
158+
f'version = "{new_version}"',
159+
text,
160+
count=1,
161+
flags=re.M,
162+
)
163+
path.write_text(text, encoding="utf-8")
164+
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as fh:
165+
fh.write(f"new_version={new_version}\n")
166+
print(f"Bumped to {new_version}")
167+
PY
168+
169+
- name: Build distribution
170+
run: python -m build
171+
172+
- name: Publish to PyPI
173+
env:
174+
TWINE_USERNAME: __token__
175+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
176+
run: twine upload --non-interactive dist/*
177+
178+
- name: Commit and push version bump
179+
run: |
180+
git config user.name "github-actions[bot]"
181+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
182+
git add pyproject.toml
183+
git commit -m "Bump version to ${{ steps.bump.outputs.new_version }} [skip ci]"
184+
git tag "v${{ steps.bump.outputs.new_version }}"
185+
git pull --rebase origin stable
186+
git push origin stable
187+
git push origin "v${{ steps.bump.outputs.new_version }}"
188+
189+
- name: Create GitHub Release
190+
env:
191+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
192+
run: |
193+
gh release create "v${{ steps.bump.outputs.new_version }}" \
194+
dist/* \
195+
--title "v${{ steps.bump.outputs.new_version }}" \
196+
--generate-notes

0 commit comments

Comments
 (0)