v0.0.5 #8
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish to PyPI | |
| on: | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| jobs: | |
| build-and-publish: | |
| name: Build and publish to PyPI | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Extract version from setup.py | |
| id: get_version | |
| run: | | |
| VERSION=$(grep -oP '(?<=version=")[^\"]+' setup.py) | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Package version: $VERSION" | |
| - name: Check if version exists on PyPI | |
| id: check_version | |
| run: | | |
| VERSION="${{ steps.get_version.outputs.version }}" | |
| PACKAGE_NAME="dtor" | |
| RESPONSE=$(curl -s https://pypi.org/pypi/$PACKAGE_NAME/json) | |
| if echo "$RESPONSE" | jq -e ".releases | has(\"$VERSION\")" > /dev/null; then | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| echo "Version $VERSION already exists on PyPI" | |
| else | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| echo "Version $VERSION does not exist on PyPI" | |
| fi | |
| - name: Install dependencies | |
| if: steps.check_version.outputs.exists == 'false' | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build twine | |
| - name: Build package | |
| if: steps.check_version.outputs.exists == 'false' | |
| run: python -m build | |
| - name: Check package | |
| if: steps.check_version.outputs.exists == 'false' | |
| run: twine check dist/* | |
| - name: Publish to PyPI | |
| if: steps.check_version.outputs.exists == 'false' | |
| env: | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
| run: twine upload dist/* | |
| - name: Skip - Version exists | |
| if: steps.check_version.outputs.exists == 'true' | |
| run: | | |
| echo "==========================================" | |
| echo "Version ${{ steps.get_version.outputs.version }} already exists on PyPI" | |
| echo "Skipping upload to prevent error" | |
| echo "==========================================" | |
| echo "" | |
| echo "To publish a new version:" | |
| echo "1. Update version in setup.py and dtor/__init__.py" | |
| echo "2. Create a new release with matching tag" | |
| echo "==========================================" |