|
| 1 | +name: Build and upload to PyPI |
| 2 | + |
| 3 | +# Build on every branch push, tag push, and pull request change: |
| 4 | +on: [push, pull_request] |
| 5 | + |
| 6 | +jobs: |
| 7 | + |
| 8 | + build_wheels: |
| 9 | + name: Build wheels on ${{ matrix.os }} |
| 10 | + runs-on: ${{ matrix.os }} |
| 11 | + strategy: |
| 12 | + matrix: |
| 13 | + os: [ubuntu-latest, windows-latest, macos-latest] |
| 14 | + |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + fetch-tags: true # Optional, use if you use setuptools_scm |
| 20 | + |
| 21 | + - name: Build wheels |
| 22 | + uses: pypa/cibuildwheel@v2.16.2 |
| 23 | + # to supply options, put them in 'env', like: |
| 24 | + # env: |
| 25 | + # CIBW_SOME_OPTION: value |
| 26 | + # Disable building PyPy wheels on all platforms |
| 27 | + env: |
| 28 | + CIBW_ARCHS_MACOS: "x86_64 universal2 arm64" |
| 29 | + CIBW_ARCHS_WINDOWS: "AMD64 x86" |
| 30 | + # disable aarm64 build since its too slow to build(docker + qemu) |
| 31 | + CIBW_ARCHS_LINUX: "x86_64 i686" |
| 32 | + # it looks cibuildwheel fails to add version string to wheel file for python 3.6, so skip it |
| 33 | + CIBW_SKIP: pp* |
| 34 | + |
| 35 | + - uses: actions/upload-artifact@v4 |
| 36 | + with: |
| 37 | + name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }} |
| 38 | + path: ./wheelhouse/*.whl |
| 39 | + |
| 40 | + # It looks cibuildwheels did not clean build folder(CMake), and it results to Windows arm64 build failure(trying to reuse x86 build of .obj) |
| 41 | + # So supply separated build job for Windows ARM64 build |
| 42 | + # TODO: clean build folder using CIBW_BEFORE_ALL? |
| 43 | + build_win_arm64_wheels: |
| 44 | + name: Build ARM64 wheels on Windows. |
| 45 | + runs-on: windows-latest |
| 46 | + steps: |
| 47 | + - uses: actions/checkout@v4 |
| 48 | + with: |
| 49 | + fetch-depth: 0 |
| 50 | + fetch-tags: true # Optional, use if you use setuptools_scm |
| 51 | + |
| 52 | + - name: Build wheels |
| 53 | + uses: pypa/cibuildwheel@v2.16.2 |
| 54 | + # to supply options, put them in 'env', like: |
| 55 | + # env: |
| 56 | + # CIBW_SOME_OPTION: value |
| 57 | + # Disable building PyPy wheels on all platforms |
| 58 | + env: |
| 59 | + CIBW_ARCHS_WINDOWS: "ARM64" |
| 60 | + CIBW_SKIP: pp* |
| 61 | + |
| 62 | + - uses: actions/upload-artifact@v4 |
| 63 | + with: |
| 64 | + name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }} |
| 65 | + path: ./wheelhouse/*.whl |
| 66 | + |
| 67 | + make_sdist: |
| 68 | + name: Make SDist |
| 69 | + runs-on: ubuntu-latest |
| 70 | + steps: |
| 71 | + - uses: actions/checkout@v4 |
| 72 | + with: |
| 73 | + fetch-depth: 0 # Optional, use if you use setuptools_scm |
| 74 | + fetch-tags: true # Optional, use if you use setuptools_scm |
| 75 | + |
| 76 | + - name: Build SDist |
| 77 | + run: pipx run build --sdist |
| 78 | + |
| 79 | + - uses: actions/upload-artifact@v4 |
| 80 | + with: |
| 81 | + name: cibw-sdist |
| 82 | + path: dist/*.tar.gz |
| 83 | + |
| 84 | + upload_all: |
| 85 | + needs: [build_wheels, build_wheels, make_sdist] |
| 86 | + runs-on: ubuntu-latest |
| 87 | + environment: release |
| 88 | + permissions: |
| 89 | + # IMPORTANT: this permission is mandatory for trusted publishing |
| 90 | + id-token: write |
| 91 | + # upload to PyPI on every tag starting with 'v' |
| 92 | + # NOTE: Without github.event_name & githug.ref check, `upload_all` task is still triggered on 'main' branch push. |
| 93 | + # (then get 'Branch "main" is not allowed to deploy to release due to environment protection rules.' error) |
| 94 | + # So still do event_name and github.ref check. |
| 95 | + # TODO: Make it work only using Github `environment` feature. |
| 96 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') |
| 97 | + # alternatively, to publish when a GitHub Release is created, use the following rule: |
| 98 | + # if: github.event_name == 'push' && github.event.action == 'published' |
| 99 | + steps: |
| 100 | + - uses: actions/download-artifact@v4 |
| 101 | + with: |
| 102 | + pattern: cibw-* |
| 103 | + path: dist |
| 104 | + merge-multiple: true |
| 105 | + |
| 106 | + - uses: pypa/gh-action-pypi-publish@release/v1 |
| 107 | + with: |
| 108 | + # Use Trusted Publisher feature: |
| 109 | + # https://docs.pypi.org/trusted-publishers/ |
| 110 | + # so no use of PYPI_API_TOKEN |
| 111 | + #password: ${{ secrets.PYPI_API_TOKEN }} |
| 112 | + # |
| 113 | + # Avoid race condition when using multiple CIs |
| 114 | + skip-existing: true |
| 115 | + verbose: true |
0 commit comments