Skip to content

Commit bb0dd25

Browse files
committed
Add publish workflow
1 parent 50cd840 commit bb0dd25

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

.github/workflows/publish.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
name: Publish to PyPI
3+
4+
on:
5+
push:
6+
tags:
7+
- 'v*.*.*' # e.g. v1.2.3
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-python@v5
15+
with:
16+
python-version: '3.x'
17+
- name: Install build tools
18+
run: pip install build tomli
19+
- name: Verify tag matches pyproject.toml version
20+
run: |
21+
TAG="${GITHUB_REF#refs/tags/v}"
22+
FILE_VER=$(python -c "import tomli;print(tomli.load(open('pyproject.toml'))['project']['version'])")
23+
[ "$TAG" = "$FILE_VER" ] || { echo "Tag $TAG != pyproject $FILE_VER"; exit 1; }
24+
- name: Build dists
25+
run: python -m build
26+
- name: Upload artifacts
27+
uses: actions/upload-artifact@v4
28+
with:
29+
name: dist
30+
path: dist/*
31+
32+
publish:
33+
needs: build
34+
runs-on: ubuntu-latest
35+
environment: pypi
36+
permissions:
37+
id-token: write
38+
contents: read
39+
steps:
40+
- uses: actions/download-artifact@v4
41+
with:
42+
name: dist
43+
path: dist
44+
- name: Publish to PyPI via OIDC
45+
uses: pypa/gh-action-pypi-publish@release/v1

0 commit comments

Comments
 (0)