fix publish action #9
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: CI (Build universal wheel + Test + Publish) | |
| on: | |
| push: | |
| branches: [ master ] | |
| pull_request: | |
| branches: [ master ] | |
| release: | |
| types: [ published ] | |
| workflow_dispatch: | |
| jobs: | |
| # 1) Build sdist + universal wheel (pure Python) | |
| build_dist: | |
| name: Build distributions | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| cache: "pip" | |
| - name: Install build tooling | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build | |
| - name: Build sdist and wheel | |
| run: python -m build --sdist --wheel --outdir dist | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: dist | |
| path: dist/* | |
| # 2) Test from source on all OS/Python | |
| test_source: | |
| name: Test (source) py${{ matrix.python-version }} on ${{ matrix.os }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ ubuntu-latest, macos-latest, windows-latest ] | |
| python-version: [ '3.10', '3.11', '3.12', '3.13', '3.14' ] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| allow-prereleases: true | |
| cache: "pip" | |
| - uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'zulu' | |
| java-version: '11' | |
| - name: Install package (from source) | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install . | |
| - name: Install test deps | |
| run: pip install pytest==8.3.3 | |
| - name: Run tests (unittest) | |
| run: python -m unittest discover tests | |
| # 3) Test the built wheel on all OS/Python | |
| test_wheel: | |
| name: Test (wheel) py${{ matrix.python-version }} on ${{ matrix.os }} | |
| needs: [ build_dist ] | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ ubuntu-latest, macos-latest, windows-latest ] | |
| python-version: [ '3.10', '3.11', '3.12', '3.13', '3.14' ] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| allow-prereleases: true | |
| cache: "pip" | |
| - uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'zulu' | |
| java-version: '11' | |
| - name: Download built dists | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: dist | |
| path: dist | |
| - name: Install built wheel | |
| shell: bash | |
| run: | | |
| python -m pip install --upgrade pip | |
| # Prefer wheel; fall back to sdist if needed | |
| WHEEL=$(ls dist/*.whl | head -n 1 || true) | |
| if [ -n "$WHEEL" ]; then | |
| pip install "$WHEEL" | |
| else | |
| pip install dist/*.tar.gz | |
| fi | |
| - name: Install test deps | |
| run: pip install pytest==8.3.3 | |
| - name: Run tests (against installed wheel) | |
| run: python -m unittest discover tests | |
| # 4) Publish to PyPI on Release (tag publish event) | |
| publish-to-pypi: | |
| name: Publish to PyPI | |
| needs: [ build_dist, test_source, test_wheel ] | |
| if: github.event_name == 'release' && github.event.action == 'published' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write # Required for Trusted Publishers (OIDC) | |
| contents: read | |
| steps: | |
| - name: Download built artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: dist | |
| path: dist | |
| # A) Trusted Publisher / OIDC (recommended) | |
| - name: Publish (PyPI via OIDC) | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| packages-dir: dist/ | |
| verify-metadata: true | |
| skip-existing: false | |
| # If you prefer token auth (not recomended) instead of OIDC, replace the step above with: | |
| # - name: Publish (PyPI via API token) | |
| # uses: pypa/gh-action-pypi-publish@release/v1 | |
| # with: | |
| # user: __token__ | |
| # password: ${{ secrets.PYPI_API_TOKEN }} | |
| # packages-dir: dist/ | |
| # verify-metadata: true | |
| # skip-existing: false |