Skip to content

Commit 7312cb4

Browse files
committed
feat: add PyPI publish workflow and Makefile changes
Add a GitHub Actions workflow (publish-to-pypi.yml) to publish releases on tag pushes (vX.Y.Z). The workflow validates the tag format, checks out the repo, sets up Python 3.11 via astral-sh/setup-uv, runs `make build` with VERSION derived from the tag, publishes using a PYPI_TOKEN, copies the built wheel and creates a GitHub release with the wheel attached. Update Makefile: the build target will update swanlab/package.json.version with the provided VERSION (using jq) when VERSION is set, and a new publish target ensures PYPI_TOKEN is present and calls `uv publish`. Also preserved existing clean target.
1 parent 9b50db1 commit 7312cb4

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
push:
5+
tags:
6+
- "v[0-9]*"
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Validate tag format
14+
run: |
15+
TAG=${GITHUB_REF#refs/tags/}
16+
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+([-.]?[a-zA-Z0-9.]+)?$ ]]; then
17+
echo "Invalid tag format: $TAG"
18+
exit 1
19+
fi
20+
echo "Tag format valid: $TAG"
21+
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
- name: Install uv and set up Python
26+
uses: astral-sh/setup-uv@v7
27+
with:
28+
python-version: "3.11"
29+
enable-cache: true
30+
31+
- name: Build
32+
run: make build VERSION=${GITHUB_REF#refs/tags/v}
33+
34+
- name: Publish
35+
env:
36+
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
37+
run: make publish
38+
39+
- run: cp dist/*.whl .
40+
41+
- name: Release
42+
uses: softprops/action-gh-release@v2
43+
if: startsWith(github.ref, 'refs/tags/')
44+
with:
45+
files: |
46+
*.whl

‎Makefile‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,20 @@ bench:
2121
uv run pytest tests/benchmark
2222

2323
build:
24+
@if [ -n "$(VERSION)" ]; then \
25+
python -c "import json; data=json.load(open('swanlab/package.json')); data['version']='$(VERSION)'; json.dump(data,open('swanlab/package.json','w'),indent=2)" && \
26+
echo "Updated swanlab/package.json version to $(VERSION)"; \
27+
else \
28+
echo "VERSION not set, using default version in swanlab/package.json"; \
29+
fi
2430
uv build
2531

32+
publish:
33+
@if [ -z "$$PYPI_TOKEN" ]; then \
34+
echo "PYPI_TOKEN not set"; \
35+
exit 1; \
36+
fi
37+
UV_PUBLISH_TOKEN="$$PYPI_TOKEN" uv publish
38+
2639
clean:
2740
@bash scripts/clean_pycache.sh .

0 commit comments

Comments
 (0)