Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,42 @@ jobs:
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
contents: read # Required by actions/checkout
id-token: write # Needed for OIDC-based Trusted Publishing
# Only trigger on merges, not just closes
if: github.event.pull_request.merged == true
steps:
- name: Check out committed code
uses: actions/checkout@v4
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
id: python
uses: actions/setup-python@v5
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Prepare uv
run: |
pip install uv
uv venv --seed venv
. venv/bin/activate
uv pip install toml
- name: Check for existing package on PyPI
id: check_package
run: |
. venv/bin/activate
PACKAGE_VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])")
PACKAGE_NAME=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['name'])")

echo "Checking for package: $PACKAGE_NAME==$PACKAGE_VERSION"

if curl -s "https://pypi.org/pypi/$PACKAGE_NAME/json" | jq -r '.releases | keys[]' | grep -q "^$PACKAGE_VERSION$"; then
echo "Package version already exists. Skipping upload."
echo "should_publish=false" >> $GITHUB_OUTPUT
else
echo "Package version does not exist. Proceeding with upload."
echo "should_publish=true" >> $GITHUB_OUTPUT
fi
- name: Build
if: steps.check_package.outputs.should_publish == 'true'
run: |
. venv/bin/activate
uv build
uv build
- name: Publish distribution 📦 to PyPI
if: steps.check_package.outputs.should_publish == 'true'
run: |
. venv/bin/activate
uv publish
uv publish
6 changes: 1 addition & 5 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,9 @@ jobs:
. venv/bin/activate
PACKAGE_VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])")
PACKAGE_NAME=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['name'])")

# Use jq to check for the version in the releases object
EXISTING_VERSIONS=$(curl -s "https://test.pypi.org/pypi/$PACKAGE_NAME/json" | jq '.releases | keys[]')

echo "Checking for package: $PACKAGE_NAME==$PACKAGE_VERSION"

if [[ "$EXISTING_VERSIONS" =~ "$PACKAGE_VERSION" ]]; then
if curl -s "https://test.pypi.org/pypi/$PACKAGE_NAME/json" | jq -r '.releases | keys[]' | grep -q "^$PACKAGE_VERSION$"; then
echo "Package version already exists. Skipping upload."
echo "should_publish=false" >> $GITHUB_OUTPUT
else
Expand Down