Skip to content

Commit 5e30d9a

Browse files
committed
Add PyPI publish workflow + make release targets
publish.yml fires on v* tags, builds the viewer frontend, builds the wheel, and publishes via PyPI trusted publishing (no API token). make release / release-minor / release-major bumps pyproject.toml, commits, tags, and pushes in one step.
1 parent be044b0 commit 5e30d9a

2 files changed

Lines changed: 79 additions & 1 deletion

File tree

.github/workflows/publish.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
push:
5+
tags: ['v*']
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
environment: pypi
11+
permissions:
12+
id-token: write
13+
contents: read
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- uses: actions/setup-node@v4
18+
with:
19+
node-version: '20'
20+
cache: 'npm'
21+
cache-dependency-path: frontend/package-lock.json
22+
23+
- uses: actions/setup-python@v5
24+
with:
25+
python-version: '3.12'
26+
27+
- name: Build viewer frontend
28+
run: |
29+
cd frontend
30+
npm ci
31+
npm run build:viewer
32+
33+
- name: Build Python distribution
34+
run: |
35+
python -m pip install --upgrade pip build
36+
python -m build
37+
38+
- name: Verify tag matches pyproject version
39+
run: |
40+
TAG="${GITHUB_REF#refs/tags/v}"
41+
PKG=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
42+
if [ "$TAG" != "$PKG" ]; then
43+
echo "Tag v$TAG does not match pyproject version $PKG"
44+
exit 1
45+
fi
46+
47+
- name: Publish to PyPI
48+
uses: pypa/gh-action-pypi-publish@release/v1

Makefile

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: dev stop logs restart build clean keys
1+
.PHONY: dev stop logs restart build clean keys release release-minor release-major _release
22

33
COMPOSE := docker compose -f local/compose.yaml
44

@@ -46,3 +46,33 @@ build: ## Build all images
4646

4747
clean: stop ## Stop and remove volumes
4848
@$(COMPOSE) down -v
49+
50+
release: ## Bump patch version, tag, and push (triggers PyPI publish)
51+
@$(MAKE) _release BUMP=patch
52+
53+
release-minor: ## Bump minor version, tag, and push
54+
@$(MAKE) _release BUMP=minor
55+
56+
release-major: ## Bump major version, tag, and push
57+
@$(MAKE) _release BUMP=major
58+
59+
_release:
60+
@if [ -n "$$(git status --porcelain)" ]; then \
61+
echo "Working tree is dirty. Commit or stash first."; exit 1; \
62+
fi
63+
@if [ "$$(git rev-parse --abbrev-ref HEAD)" != "main" ]; then \
64+
echo "Release must be run from main (currently on $$(git rev-parse --abbrev-ref HEAD))."; exit 1; \
65+
fi
66+
@git pull --ff-only origin main
67+
@OLD=$$(python3 -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])") && \
68+
NEW=$$(python3 -c "v='$$OLD'.split('.'); part='$(BUMP)'; \
69+
idx={'major':0,'minor':1,'patch':2}[part]; v[idx]=str(int(v[idx])+1); \
70+
[v.__setitem__(i,'0') for i in range(idx+1,3)]; print('.'.join(v))") && \
71+
echo "Bumping $$OLD -> $$NEW" && \
72+
python3 -c "import re,pathlib; p=pathlib.Path('pyproject.toml'); p.write_text(re.sub(r'^version = \".*\"', 'version = \"'+'$$NEW'+'\"', p.read_text(), count=1, flags=re.M))" && \
73+
git add pyproject.toml && \
74+
git commit -m "Release v$$NEW" && \
75+
git tag "v$$NEW" && \
76+
git push origin main && \
77+
git push origin "v$$NEW" && \
78+
echo "Pushed v$$NEW. Watch https://github.com/awslabs/llm-evaluation-system/actions"

0 commit comments

Comments
 (0)