-
Notifications
You must be signed in to change notification settings - Fork 1
72 lines (61 loc) · 1.89 KB
/
publish-to-pypi.yml
File metadata and controls
72 lines (61 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
name: Publish to PyPI
on:
push:
tags:
- 'v*.*.*' # Triggers on version tags like v0.0.21, v1.0.0, etc.
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Extract version from tag
id: get_version
run: |
# Get the tag name (e.g., v0.0.21)
TAG=${GITHUB_REF#refs/tags/v}
echo "VERSION=$TAG" >> $GITHUB_OUTPUT
echo "Publishing version: $TAG"
- name: Verify version matches setup.py
run: |
SETUP_VERSION=$(python -c "import re; content=open('setup.py').read(); print(re.search(r'version=\"([^\"]+)\"', content).group(1))")
TAG_VERSION="${{ steps.get_version.outputs.VERSION }}"
echo "setup.py version: $SETUP_VERSION"
echo "Git tag version: $TAG_VERSION"
if [ "$SETUP_VERSION" != "$TAG_VERSION" ]; then
echo "ERROR: Version mismatch!"
echo "setup.py has version $SETUP_VERSION but git tag is v$TAG_VERSION"
exit 1
fi
echo "✅ Versions match!"
- name: Build package
run: python -m build
- name: Check distribution files
run: |
ls -lh dist/
twine check dist/*
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
twine upload dist/*
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
files: |
dist/*.tar.gz
dist/*.whl