Skip to content

Commit a561bc5

Browse files
committed
feat: Add version check before publishing to PyPI
1 parent 6f7f97f commit a561bc5

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

.github/workflows/publish.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,21 @@ jobs:
3030
run: |
3131
python -m build
3232
33+
- name: Check if version exists on PyPI
34+
id: check-version
35+
run: |
36+
PKG_NAME=$(python3 -c "import toml; print(toml.load('pyproject.toml')['project']['name'])")
37+
PKG_VERSION=$(python3 -c "import toml; print(toml.load('pyproject.toml')['project']['version'])")
38+
EXISTS=$(curl -s https://pypi.org/pypi/$PKG_NAME/json | grep -o "\"$PKG_VERSION\"")
39+
if [ "$EXISTS" != "" ]; then
40+
echo "Version $PKG_VERSION already exists on PyPI. Skipping upload."
41+
echo "skip_upload=true" >> $GITHUB_OUTPUT
42+
else
43+
echo "skip_upload=false" >> $GITHUB_OUTPUT
44+
fi
45+
3346
- name: Publish to PyPI
47+
if: steps.check-version.outputs.skip_upload != 'true'
3448
env:
3549
TWINE_USERNAME: __token__
3650
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}

0 commit comments

Comments
 (0)