|
1 | 1 | name: Build/publish Python Package |
2 | 2 |
|
3 | | -on: push |
| 3 | +# Adopted from gh:pybind/scikit_build_example |
| 4 | +# Read more on https://cibuildwheel.pypa.io/en/stable |
| 5 | + |
| 6 | +on: |
| 7 | + workflow_dispatch: |
| 8 | + pull_request: |
| 9 | + push: |
| 10 | + branches: |
| 11 | + - main |
| 12 | + release: |
| 13 | + types: |
| 14 | + - published |
| 15 | + |
| 16 | +env: |
| 17 | + FORCE_COLOR: 3 |
| 18 | + |
| 19 | +concurrency: |
| 20 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 21 | + cancel-in-progress: true |
4 | 22 |
|
5 | 23 | jobs: |
6 | | - build: |
| 24 | + build_sdist: |
| 25 | + name: Build SDist |
7 | 26 | runs-on: ubuntu-latest |
8 | 27 | steps: |
9 | | - - uses: actions/checkout@v4 |
10 | | - with: |
11 | | - fetch-depth: 0 |
12 | | - - name: Set up Python |
13 | | - uses: actions/setup-python@v5 |
14 | | - with: |
15 | | - python-version: '3.x' |
16 | | - - name: Install dependencies |
17 | | - run: | |
18 | | - python -m pip install --upgrade pip |
19 | | - python -m pip install build twine |
20 | | - - name: Build package |
21 | | - run: | |
22 | | - python -m build --sdist --wheel |
23 | | - - name: Check package |
24 | | - run: | |
25 | | - python -m twine check dist/* |
26 | | - - name: Store the distribution packages |
27 | | - uses: actions/upload-artifact@v4 |
28 | | - with: |
29 | | - name: python-package-distributions |
30 | | - path: dist/ |
31 | | - |
32 | | - publish-to-pypi: |
33 | | - if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes |
34 | | - needs: |
35 | | - - build |
| 28 | + - uses: actions/checkout@v4 |
| 29 | + |
| 30 | + - name: Build SDist |
| 31 | + run: pipx run build --sdist |
| 32 | + |
| 33 | + - name: Check metadata |
| 34 | + run: pipx run twine check dist/* |
| 35 | + |
| 36 | + - uses: actions/upload-artifact@v4 |
| 37 | + with: |
| 38 | + name: cibw-sdist |
| 39 | + path: dist/*.tar.gz |
| 40 | + |
| 41 | + |
| 42 | + build_wheels: |
| 43 | + name: Build wheels on ${{ matrix.os }} |
| 44 | + runs-on: ${{ matrix.os }} |
| 45 | + strategy: |
| 46 | + fail-fast: false |
| 47 | + matrix: |
| 48 | + os: [windows-latest, macos-latest, ubuntu-latest] |
| 49 | + |
| 50 | + steps: |
| 51 | + - uses: actions/checkout@v4 |
| 52 | + |
| 53 | + - uses: astral-sh/setup-uv@v4 |
| 54 | + |
| 55 | + - name: Build wheels |
| 56 | + uses: pypa/cibuildwheel@v3.0.0 |
| 57 | + env: |
| 58 | + CIBW_ARCHS_WINDOWS: auto64 |
| 59 | + CIBW_ENVIRONMENT_MACOS: CXX="g++-13" MACOSX_DEPLOYMENT_TARGET="14.0" |
| 60 | + with: |
| 61 | + package-dir: . |
| 62 | + output-dir: wheelhouse |
| 63 | + config-file: "{package}/pyproject.toml" |
| 64 | + |
| 65 | + - name: Verify clean directory |
| 66 | + run: git diff --exit-code |
| 67 | + shell: bash |
| 68 | + |
| 69 | + - uses: actions/upload-artifact@v4 |
| 70 | + with: |
| 71 | + name: cibw-wheels-${{ matrix.os }} |
| 72 | + path: wheelhouse/*.whl |
| 73 | + |
| 74 | + |
| 75 | + upload_all: |
| 76 | + name: Upload if release |
| 77 | + needs: [build_wheels, build_sdist] |
36 | 78 | runs-on: ubuntu-latest |
37 | | - environment: |
38 | | - name: pypi |
| 79 | + if: github.event_name == 'release' && github.event.action == 'published' |
| 80 | + environment: pypi |
39 | 81 | permissions: |
40 | | - id-token: write # IMPORTANT: mandatory for trusted publishing |
| 82 | + id-token: write |
| 83 | + attestations: write |
| 84 | + |
41 | 85 | steps: |
42 | | - - name: Download distribution packages |
43 | | - uses: actions/download-artifact@v4 |
44 | | - with: |
45 | | - name: python-package-distributions |
46 | | - path: dist/ |
47 | | - - name: Publish to PyPI |
48 | | - uses: pypa/gh-action-pypi-publish@release/v1 |
| 86 | + - uses: actions/setup-python@v5 |
| 87 | + with: |
| 88 | + python-version: "3.x" |
| 89 | + |
| 90 | + - uses: actions/download-artifact@v4 |
| 91 | + with: |
| 92 | + pattern: cibw-* |
| 93 | + merge-multiple: true |
| 94 | + path: dist |
| 95 | + |
| 96 | + - name: Generate artifact attestation for sdist and wheels |
| 97 | + uses: actions/attest-build-provenance@v1 |
| 98 | + with: |
| 99 | + subject-path: "dist/*" |
| 100 | + |
| 101 | + - uses: pypa/gh-action-pypi-publish@release/v1 |
| 102 | + with: |
| 103 | + attestations: true |
0 commit comments