Skip to content

Commit c8991bf

Browse files
committed
fix publish.yml
1 parent 633d8d5 commit c8991bf

File tree

1 file changed

+14
-74
lines changed

1 file changed

+14
-74
lines changed

.github/workflows/publish.yml

Lines changed: 14 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,36 @@
1-
name: Publish to PyPI
1+
name: "Publish to PyPI"
22

33
on:
44
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:
77

88
jobs:
99
release-build:
1010
runs-on: ubuntu-latest
11-
1211
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
2014
with:
2115
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
2617
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
4119
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
5621
with:
57-
name: release-dists
22+
name: dist
5823
path: dist/
5924

6025
pypi-publish:
61-
runs-on: ubuntu-latest
6226
needs: [release-build]
27+
runs-on: ubuntu-latest
6328
environment: pypi
6429
permissions:
65-
id-token: write # Required for PyPI trusted publishing
66-
30+
id-token: write
6731
steps:
68-
# Step 1: Retrieve release distributions
69-
- name: Retrieve release distributions
70-
uses: actions/download-artifact@v4
32+
- uses: actions/download-artifact@v4
7133
with:
72-
name: release-dists
34+
name: dist
7335
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

Comments
 (0)