Skip to content

Commit 897629f

Browse files
authored
Add GitHub Actions workflow for PyPI publishing on tag (#61)
Uses PyPI trusted publishing (no API tokens needed). Triggers on version tags (v*.*.*). setuptools_scm derives the version from the git tag automatically. After merging, configure trusted publishing on pypi.org: Project: cryptoadvance.spectrum → Publishing → Add a new publisher → Owner: cryptoadvance, Repo: spectrum → Workflow: pypi-publish.yml, Environment: (blank) Co-authored-by: Nazim <al-munazzim@users.noreply.github.com>
1 parent 407f694 commit 897629f

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

.github/workflows/pypi-publish.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
push:
5+
tags:
6+
- v[0-9]+.[0-9]+.[0-9]+
7+
- v[0-9]+.[0-9]+.[0-9]+-*
8+
9+
jobs:
10+
publish:
11+
name: Build and publish to PyPI
12+
runs-on: ubuntu-latest
13+
permissions:
14+
id-token: write # Required for trusted publishing
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0 # setuptools_scm needs full history for version
19+
20+
- uses: actions/setup-python@v5
21+
with:
22+
python-version: "3.10"
23+
24+
- name: Install build tools
25+
run: pip install build
26+
27+
- name: Build package
28+
run: python -m build
29+
30+
- name: Verify version matches tag
31+
run: |
32+
TAG=${GITHUB_REF#refs/tags/v}
33+
PKG_VERSION=$(python -c "from importlib.metadata import version; print(version('cryptoadvance.spectrum'))" 2>/dev/null || \
34+
python -c "import re; print(re.search(r'Version: (.+)', open('src/cryptoadvance_spectrum.egg-info/PKG-INFO').read()).group(1))" 2>/dev/null || \
35+
ls dist/*.tar.gz | grep -oP '\d+\.\d+\.\d+')
36+
echo "Tag version: $TAG"
37+
echo "Package version: $PKG_VERSION"
38+
39+
- name: Publish to PyPI
40+
uses: pypa/gh-action-pypi-publish@release/v1

0 commit comments

Comments
 (0)