Publish Python π distribution π¦ to PyPI and TestPyPI #2
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 Python π distribution π¦ to PyPI and TestPyPI | |
| on: | |
| release: | |
| types: [published] | |
| jobs: | |
| build: | |
| name: Build distribution π¦ | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: "3.x" | |
| - name: Install Poetry | |
| uses: snok/install-poetry@v1 | |
| - name: Install dependencies | |
| run: poetry install | |
| - name: Run tests | |
| env: | |
| AUTHSIGNAL_API_URL: ${{ secrets.AUTHSIGNAL_API_URL }} | |
| AUTHSIGNAL_API_SECRET: ${{ secrets.AUTHSIGNAL_API_SECRET }} | |
| run: poetry run python -m authsignal.client_tests | |
| - name: Verify package structure | |
| run: | | |
| pip install check-manifest | |
| check-manifest | |
| - name: Build main distribution | |
| run: python3 -m build | |
| - name: Test package installation | |
| run: | | |
| python -m venv test_env | |
| source test_env/bin/activate | |
| pip install dist/*.whl | |
| # Add a basic import test here | |
| deactivate | |
| - name: Store main distribution packages | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: python-package-distributions | |
| path: dist/ | |
| # Build TestPyPI version | |
| - name: Clean build artifacts | |
| run: rm -rf dist/* | |
| - name: Extract version from version.py | |
| run: | | |
| export PYTHONPATH=${PYTHONPATH}:$(pwd)/authsignal | |
| echo "BASE_VERSION=$(python -c 'from version import VERSION; print(VERSION)')" >> $GITHUB_ENV | |
| - name: Build TestPyPI distribution | |
| run: | | |
| poetry version "${BASE_VERSION}.dev$(date +%s)" | |
| python3 -m build | |
| - name: Store test distribution packages | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: python-package-distributions-testing | |
| path: dist/ | |
| publish-to-pypi: | |
| name: >- | |
| Publish Python π distribution π¦ to PyPI | |
| if: startsWith(github.ref, 'refs/tags/') | |
| needs: | |
| - build | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: pypi | |
| url: https://pypi.org/p/authsignal | |
| permissions: | |
| id-token: write # needed for both trusted publishing and sigstore | |
| steps: | |
| - name: Download all the dists | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: python-package-distributions | |
| path: dist/ | |
| # Add signing steps before publishing | |
| - name: Set up Python environment | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: "3.x" | |
| - name: Install cryptography version 43 | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install cryptography==43.* | |
| - name: Sign the dists with Sigstore | |
| uses: sigstore/[email protected] | |
| with: | |
| inputs: >- | |
| ./dist/*.tar.gz | |
| ./dist/*.whl | |
| - name: Publish distribution π¦ to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| publish-to-testpypi: | |
| name: Publish Python π distribution π¦ to TestPyPI | |
| needs: | |
| - build | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: testpypi | |
| url: https://test.pypi.org/p/authsignal | |
| permissions: | |
| id-token: write # IMPORTANT: mandatory for trusted publishing | |
| steps: | |
| - name: Download all the test dists | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: python-package-distributions-testing | |
| path: dist/ | |
| - name: Publish distribution π¦ to TestPyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| repository-url: https://test.pypi.org/legacy/ |