Skip to content

Commit b9e6110

Browse files
authored
Enhance publish workflow for PyPI deployment
Updated the publish workflow to set up Python and validate distribution metadata before publishing to PyPI.
1 parent bdcb435 commit b9e6110

1 file changed

Lines changed: 31 additions & 4 deletions

File tree

.github/workflows/publish.yml

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ jobs:
7070
needs: [build_wheels, build_sdist]
7171
runs-on: ubuntu-latest
7272
permissions:
73-
id-token: write
7473
contents: read
7574

7675
steps:
@@ -80,7 +79,35 @@ jobs:
8079
path: dist
8180
merge-multiple: true
8281

83-
- name: Publish to PyPI
84-
uses: pypa/gh-action-pypi-publish@release/v1
82+
- name: Set up Python
83+
uses: actions/setup-python@v5
8584
with:
86-
packages-dir: dist
85+
python-version: "3.12"
86+
87+
- name: Inspect distributions
88+
run: |
89+
set -euo pipefail
90+
find dist -type f -print
91+
92+
- name: Install packaging tools
93+
run: |
94+
python -m pip install --upgrade pip build twine
95+
96+
- name: Validate distribution metadata
97+
run: |
98+
set -euo pipefail
99+
mapfile -t ARTIFACTS < <(find dist -type f \( -name "*.whl" -o -name "*.tar.gz" -o -name "*.zip" \) | sort)
100+
if [ ${#ARTIFACTS[@]} -eq 0 ]; then
101+
echo "No distributions found under dist/"
102+
exit 1
103+
fi
104+
python -m twine check "${ARTIFACTS[@]}"
105+
106+
- name: Publish to PyPI
107+
env:
108+
TWINE_USERNAME: __token__
109+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
110+
run: |
111+
set -euo pipefail
112+
mapfile -t ARTIFACTS < <(find dist -type f \( -name "*.whl" -o -name "*.tar.gz" -o -name "*.zip" \) | sort)
113+
python -m twine upload --non-interactive --skip-existing "${ARTIFACTS[@]}"

0 commit comments

Comments
 (0)