Skip to content

Commit cdd7496

Browse files
committed
auto push a new python version on bumps
1 parent 73eb995 commit cdd7496

2 files changed

Lines changed: 59 additions & 7 deletions

File tree

.github/workflows/auto-tag-py.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Auto-tag Python release
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- 'bonsai-py/Cargo.toml'
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
tag:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
token: ${{ secrets.RELEASE_TAG_PAT }}
19+
fetch-depth: 0 # need full history so `git rev-parse` can see existing tags
20+
21+
- name: Extract version from Cargo.toml
22+
id: version
23+
run: |
24+
version=$(grep -m1 '^version' bonsai-py/Cargo.toml | sed -E 's/.*"([^"]+)".*/\1/')
25+
if [ -z "$version" ]; then
26+
echo "::error::Could not parse version from bonsai-py/Cargo.toml"
27+
exit 1
28+
fi
29+
echo "version=$version" >> "$GITHUB_OUTPUT"
30+
echo "Detected version: $version"
31+
32+
- name: Check if py-v tag already exists
33+
id: check
34+
run: |
35+
v="${{ steps.version.outputs.version }}"
36+
if git rev-parse "py-v$v" >/dev/null 2>&1; then
37+
echo "py-v$v already exists — no-op."
38+
echo "skip=true" >> "$GITHUB_OUTPUT"
39+
else
40+
echo "py-v$v does not exist — will tag."
41+
echo "skip=false" >> "$GITHUB_OUTPUT"
42+
fi
43+
44+
- name: Configure git
45+
if: steps.check.outputs.skip == 'false'
46+
run: |
47+
git config user.name "github-actions[bot]"
48+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
49+
50+
- name: Push py-v-X.Y.Z (real PyPI release)
51+
if: steps.check.outputs.skip == 'false'
52+
run: |
53+
v="${{ steps.version.outputs.version }}"
54+
git tag "py-v$v"
55+
git push origin "py-v$v"

.github/workflows/python-wheels.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Python wheels
33
on:
44
push:
55
branches: [main]
6-
tags: ["py-v*", "py-test-*"]
6+
tags: ["py-v*"]
77
pull_request:
88
branches: [main]
99
workflow_dispatch: # manual ad-hoc builds from any branch
@@ -63,7 +63,6 @@ jobs:
6363
run: |
6464
tag="${GITHUB_REF#refs/tags/}"
6565
version="${tag#py-v}"
66-
version="${version#py-test-}"
6766
cargo_version=$(grep -m1 '^version' bonsai-py/Cargo.toml | sed -E 's/.*"([^"]+)".*/\1/')
6867
if [ "$version" != "$cargo_version" ]; then
6968
echo "::error::Tag version '$version' does not match Cargo.toml version '$cargo_version'."
@@ -149,12 +148,12 @@ jobs:
149148
python -c "import bonsai_bt; print(bonsai_bt.__version__)"
150149
151150
publish:
152-
name: Publish to PyPI / TestPyPI
151+
name: Publish to PyPI
153152
needs: [build, sdist, verify-sdist]
154-
if: startsWith(github.ref, 'refs/tags/py-v') || startsWith(github.ref, 'refs/tags/py-test-')
153+
if: startsWith(github.ref, 'refs/tags/py-v')
155154
runs-on: ubuntu-latest
156155
environment:
157-
name: ${{ startsWith(github.ref, 'refs/tags/py-test-') && 'testpypi' || 'pypi' }}
156+
name: pypi
158157
permissions:
159158
id-token: write # OIDC for Trusted Publishing
160159
steps:
@@ -174,7 +173,5 @@ jobs:
174173

175174
- uses: pypa/gh-action-pypi-publish@release/v1
176175
with:
177-
repository-url: >-
178-
${{ startsWith(github.ref, 'refs/tags/py-test-') && 'https://test.pypi.org/legacy/' || 'https://upload.pypi.org/legacy/' }}
179176
packages-dir: dist
180177
skip-existing: true

0 commit comments

Comments
 (0)