File tree Expand file tree Collapse file tree 2 files changed +25
-13
lines changed Expand file tree Collapse file tree 2 files changed +25
-13
lines changed Original file line number Diff line number Diff line change @@ -17,26 +17,42 @@ jobs:
1717 runs-on : ubuntu-latest
1818 environment : pypi
1919 permissions :
20- id-token : write
20+ contents : read # Required by actions/checkout
21+ id-token : write # Needed for OIDC-based Trusted Publishing
2122 # Only trigger on merges, not just closes
2223 if : github.event.pull_request.merged == true
2324 steps :
2425 - name : Check out committed code
2526 uses : actions/checkout@v4
26- - name : Set up Python ${{ env.DEFAULT_PYTHON }}
27- id : python
28- uses : actions/setup-python@v5
29- with :
30- python-version : ${{ env.DEFAULT_PYTHON }}
3127 - name : Prepare uv
3228 run : |
3329 pip install uv
3430 uv venv --seed venv
31+ . venv/bin/activate
32+ uv pip install toml
33+ - name : Check for existing package on PyPI
34+ id : check_package
35+ run : |
36+ . venv/bin/activate
37+ PACKAGE_VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])")
38+ PACKAGE_NAME=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['name'])")
39+
40+ echo "Checking for package: $PACKAGE_NAME==$PACKAGE_VERSION"
41+
42+ if curl -s "https://pypi.org/pypi/$PACKAGE_NAME/json" | jq -r '.releases | keys[]' | grep -q "^$PACKAGE_VERSION$"; then
43+ echo "Package version already exists. Skipping upload."
44+ echo "should_publish=false" >> $GITHUB_OUTPUT
45+ else
46+ echo "Package version does not exist. Proceeding with upload."
47+ echo "should_publish=true" >> $GITHUB_OUTPUT
48+ fi
3549 - name : Build
50+ if : steps.check_package.outputs.should_publish == 'true'
3651 run : |
3752 . venv/bin/activate
38- uv build
53+ uv build
3954 - name : Publish distribution 📦 to PyPI
55+ if : steps.check_package.outputs.should_publish == 'true'
4056 run : |
4157 . venv/bin/activate
42- uv publish
58+ uv publish
Original file line number Diff line number Diff line change @@ -182,13 +182,9 @@ jobs:
182182 . venv/bin/activate
183183 PACKAGE_VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])")
184184 PACKAGE_NAME=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['name'])")
185-
186- # Use jq to check for the version in the releases object
187- EXISTING_VERSIONS=$(curl -s "https://test.pypi.org/pypi/$PACKAGE_NAME/json" | jq '.releases | keys[]')
188-
189185 echo "Checking for package: $PACKAGE_NAME==$PACKAGE_VERSION"
190186
191- if [[ "$EXISTING_VERSIONS" =~ " $PACKAGE_VERSION" ]] ; then
187+ if curl -s "https://test.pypi.org/pypi/$PACKAGE_NAME/json" | jq -r '.releases | keys[]' | grep -q "^ $PACKAGE_VERSION$" ; then
192188 echo "Package version already exists. Skipping upload."
193189 echo "should_publish=false" >> $GITHUB_OUTPUT
194190 else
You can’t perform that action at this time.
0 commit comments