Release: Python package #475
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
| # Use Trusted Publishing to stage Python packages through GitHub Actions (GHA) to the Python Package Index (PyPI). | |
| name: "Release: Python package" | |
| on: | |
| # Build and publish packages when running a release. | |
| push: | |
| tags: | |
| - '*' | |
| # Build packages on each pull request for validation purposes. | |
| pull_request: | |
| # Build packages each night for validation purposes. | |
| schedule: | |
| - cron: '0 4 * * *' | |
| # Allow the job to be triggered manually. | |
| workflow_dispatch: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| build-and-publish: | |
| name: "Build and publish to PyPI" | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: ["ubuntu-latest"] | |
| python-version: ["3.14"] | |
| env: | |
| OS_TYPE: ${{ matrix.os }} | |
| PYTHON_VERSION: ${{ matrix.python-version }} | |
| # Trusted publishing. | |
| # Specifying a GitHub environment is optional, but strongly encouraged. | |
| environment: pypi | |
| # IMPORTANT: This permission is mandatory for Trusted Publishing. | |
| permissions: | |
| id-token: write | |
| steps: | |
| - name: Acquire sources | |
| uses: actions/checkout@v7 | |
| with: | |
| fetch-depth: 0 | |
| fetch-tags: true | |
| persist-credentials: false | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v7 | |
| with: | |
| activate-environment: true | |
| cache-suffix: ${{ matrix.python-version }} | |
| enable-cache: true | |
| python-version: ${{ matrix.python-version }} | |
| - name: Build package | |
| run: | | |
| uv build | |
| uvx twine check dist/* | |
| - name: Publish package to TestPyPI | |
| if: ${{ ! github.event.pull_request.head.repo.fork }} | |
| run: | | |
| uv publish --publish-url https://test.pypi.org/legacy/ | |
| - name: Publish package to PyPI | |
| if: startsWith(github.event.ref, 'refs/tags') | |
| run: | | |
| uv publish |