|
1 |
| -name: Publish to PyPI |
| 1 | +name: "Publish to PyPI" |
2 | 2 |
|
3 | 3 | on:
|
4 | 4 | release:
|
5 |
| - types: [created] # Trigger only when a release is created |
6 |
| - workflow_dispatch: # Allows manual triggering of the workflow |
| 5 | + types: [created] |
| 6 | + workflow_dispatch: |
7 | 7 |
|
8 | 8 | jobs:
|
9 | 9 | release-build:
|
10 | 10 | runs-on: ubuntu-latest
|
11 |
| - |
12 | 11 | steps:
|
13 |
| - # Step 1: Check out the code |
14 |
| - - name: Checkout code |
15 |
| - uses: actions/checkout@v4 |
16 |
| - |
17 |
| - # Step 2: Set up Python |
18 |
| - - name: Set up Python |
19 |
| - uses: actions/setup-python@v5 |
| 12 | + - uses: actions/checkout@v4 |
| 13 | + - uses: actions/setup-python@v5 |
20 | 14 | with:
|
21 | 15 | python-version: "3.13"
|
22 |
| - |
23 |
| - # Verify version matches the release tag |
24 |
| - - name: Verify version |
25 |
| - if: github.event_name == 'release' |
| 16 | + - name: Build package |
26 | 17 | run: |
|
27 |
| - PROJECT_VERSION=$(grep "^version = " pyproject.toml | cut -d'"' -f2) |
28 |
| - TAG_VERSION=${GITHUB_REF#refs/tags/} |
29 |
| - TAG_VERSION=${TAG_VERSION#v} |
30 |
| -
|
31 |
| - if [ "$PROJECT_VERSION" != "$TAG_VERSION" ]; then |
32 |
| - echo "Version mismatch: pyproject.toml version ($PROJECT_VERSION) doesn't match release tag ($TAG_VERSION)" |
33 |
| - exit 1 |
34 |
| - fi |
35 |
| -
|
36 |
| - # Step 3: Build the package |
37 |
| - - name: Build release distributions |
38 |
| - run: | |
39 |
| - python -m pip install --upgrade pip |
40 |
| - python -m pip install build |
| 18 | + pip install build |
41 | 19 | python -m build
|
42 |
| -
|
43 |
| - # Step 4: Verify the built package |
44 |
| - - name: Verify package |
45 |
| - run: | |
46 |
| - python -m pip install twine |
47 |
| - if [ ! -f "dist/*.whl" ] || [ ! -f "dist/*.tar.gz" ]; then |
48 |
| - echo "Expected wheel and source distribution files not found in dist/" |
49 |
| - exit 1 |
50 |
| - fi |
51 |
| - python -m twine check dist/* |
52 |
| -
|
53 |
| - # Step 5: Upload release artifacts |
54 |
| - - name: Upload release artifacts |
55 |
| - uses: actions/upload-artifact@v4 |
| 20 | + - uses: actions/upload-artifact@v4 |
56 | 21 | with:
|
57 |
| - name: release-dists |
| 22 | + name: dist |
58 | 23 | path: dist/
|
59 | 24 |
|
60 | 25 | pypi-publish:
|
61 |
| - runs-on: ubuntu-latest |
62 | 26 | needs: [release-build]
|
| 27 | + runs-on: ubuntu-latest |
63 | 28 | environment: pypi
|
64 | 29 | permissions:
|
65 |
| - id-token: write # Required for PyPI trusted publishing |
66 |
| - |
| 30 | + id-token: write |
67 | 31 | steps:
|
68 |
| - # Step 1: Retrieve release distributions |
69 |
| - - name: Retrieve release distributions |
70 |
| - uses: actions/download-artifact@v4 |
| 32 | + - uses: actions/download-artifact@v4 |
71 | 33 | with:
|
72 |
| - name: release-dists |
| 34 | + name: dist |
73 | 35 | path: dist/
|
74 |
| - |
75 |
| - # Step 2: Publish to PyPI using OIDC |
76 |
| - - name: Publish package distributions to PyPI |
77 |
| - uses: pypa/gh-action-pypi-publish@release/v1 |
78 |
| - with: |
79 |
| - verbose: true |
80 |
| - print-hash: true |
81 |
| - |
82 |
| - # Step 3: Verify package is available on PyPI |
83 |
| - - name: Verify PyPI upload |
84 |
| - run: | |
85 |
| - # Wait a bit for PyPI to process the upload |
86 |
| - sleep 30 |
87 |
| -
|
88 |
| - # Extract package name from the wheel file (assuming it exists) |
89 |
| - WHEEL_FILE=$(ls dist/*.whl | head -n 1) |
90 |
| - PACKAGE_NAME=$(basename "$WHEEL_FILE" | cut -d'-' -f1) |
91 |
| - PACKAGE_VERSION=$(basename "$WHEEL_FILE" | cut -d'-' -f2) |
92 |
| -
|
93 |
| - if ! pip install $PACKAGE_NAME==$PACKAGE_VERSION --no-deps --dry-run; then |
94 |
| - echo "Failed to verify package on PyPI" |
95 |
| - exit 1 |
96 |
| - fi |
| 36 | + - uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments