|
| 1 | +name: Build wheels |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + tags: ["*"] |
| 7 | + pull_request: |
| 8 | + # Check all PR |
| 9 | + |
| 10 | + |
| 11 | +concurrency: |
| 12 | + group: python-wheels-${{ github.ref }} |
| 13 | + cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} |
| 14 | + |
| 15 | + |
| 16 | +jobs: |
| 17 | + build-wheels: |
| 18 | + runs-on: ${{ matrix.os }} |
| 19 | + name: ${{ matrix.name }} (torch v${{ matrix.torch-version }}) |
| 20 | + strategy: |
| 21 | + matrix: |
| 22 | + torch-version: ["2.3", "2.4", "2.5", "2.6"] |
| 23 | + arch: ["arm64", "x86_64"] |
| 24 | + os: ["ubuntu-22.04", "ubuntu-22.04-arm", "macos-14"] |
| 25 | + exclude: |
| 26 | + # remove mismatched arch/os pairs |
| 27 | + - {os: macos-14, arch: x86_64} |
| 28 | + - {os: ubuntu-22.04, arch: arm64} |
| 29 | + - {os: ubuntu-22.04-arm, arch: x86_64} |
| 30 | + include: |
| 31 | + - name: x86_64 Linux |
| 32 | + os: ubuntu-22.04 |
| 33 | + arch: x86_64 |
| 34 | + cibw-arch: x86_64 |
| 35 | + - name: arm64 Linux |
| 36 | + os: ubuntu-22.04-arm |
| 37 | + arch: arm64 |
| 38 | + cibw-arch: aarch64 |
| 39 | + - name: arm64 macOS |
| 40 | + os: macos-14 |
| 41 | + arch: arm64 |
| 42 | + cibw-arch: arm64 |
| 43 | + |
| 44 | + steps: |
| 45 | + - uses: actions/checkout@v4 |
| 46 | + with: |
| 47 | + fetch-depth: 0 |
| 48 | + |
| 49 | + - name: Set up Python |
| 50 | + uses: actions/setup-python@v5 |
| 51 | + with: |
| 52 | + python-version: "3.13" |
| 53 | + |
| 54 | + - name: install dependencies |
| 55 | + run: python -m pip install cibuildwheel |
| 56 | + |
| 57 | + - name: build wheel |
| 58 | + run: python -m cibuildwheel --output-dir ./wheelhouse |
| 59 | + env: |
| 60 | + CIBW_BUILD: cp312-* |
| 61 | + CIBW_SKIP: "*musllinux*" |
| 62 | + CIBW_ARCHS: "${{ matrix.cibw-arch }}" |
| 63 | + CIBW_BUILD_VERBOSITY: 1 |
| 64 | + CIBW_ENVIRONMENT: > |
| 65 | + PIP_EXTRA_INDEX_URL=https://download.pytorch.org/whl/cpu |
| 66 | + MACOSX_DEPLOYMENT_TARGET=11 |
| 67 | + PETNC_BUILD_WITH_TORCH_VERSION=${{ matrix.torch-version }}.* |
| 68 | + # do not complain for missing libtorch.so |
| 69 | + CIBW_REPAIR_WHEEL_COMMAND_MACOS: | |
| 70 | + delocate-wheel --ignore-missing-dependencies --require-archs {delocate_archs} -w {dest_dir} -v {wheel} |
| 71 | + CIBW_REPAIR_WHEEL_COMMAND_LINUX: | |
| 72 | + auditwheel repair --exclude libtorch.so --exclude libtorch_cpu.so --exclude libc10.so -w {dest_dir} {wheel} |
| 73 | +
|
| 74 | + - uses: actions/upload-artifact@v4 |
| 75 | + with: |
| 76 | + name: single-version-wheel-${{ matrix.torch-version }}-${{ matrix.os }}-${{ matrix.arch }} |
| 77 | + path: ./wheelhouse/*.whl |
| 78 | + |
| 79 | + merge-wheels: |
| 80 | + needs: build-wheels |
| 81 | + runs-on: ubuntu-22.04 |
| 82 | + name: merge wheels for ${{ matrix.name }} |
| 83 | + strategy: |
| 84 | + matrix: |
| 85 | + include: |
| 86 | + - name: x86_64 Linux |
| 87 | + os: ubuntu-22.04 |
| 88 | + arch: x86_64 |
| 89 | + - name: arm64 Linux |
| 90 | + os: ubuntu-22.04-arm |
| 91 | + arch: arm64 |
| 92 | + - name: arm64 macOS |
| 93 | + os: macos-14 |
| 94 | + arch: arm64 |
| 95 | + steps: |
| 96 | + - uses: actions/checkout@v4 |
| 97 | + |
| 98 | + - name: Download wheels |
| 99 | + uses: actions/download-artifact@v4 |
| 100 | + with: |
| 101 | + pattern: single-version-wheel-*-${{ matrix.os }}-${{ matrix.arch }} |
| 102 | + merge-multiple: false |
| 103 | + path: dist |
| 104 | + |
| 105 | + - name: Set up Python |
| 106 | + uses: actions/setup-python@v5 |
| 107 | + with: |
| 108 | + python-version: "3.13" |
| 109 | + |
| 110 | + - name: install dependencies |
| 111 | + run: python -m pip install twine wheel |
| 112 | + |
| 113 | + - name: merge wheels |
| 114 | + run: | |
| 115 | + # collect all torch versions used for the build |
| 116 | + REQUIRES_TORCH=$(find dist -name "*.whl" -exec unzip -p {} "pet_neighbors_convert-*.dist-info/METADATA" \; | grep "Requires-Dist: torch") |
| 117 | + MERGED_TORCH_REQUIRE=$(python scripts/create-torch-versions-range.py "$REQUIRES_TORCH") |
| 118 | +
|
| 119 | + echo MERGED_TORCH_REQUIRE=$MERGED_TORCH_REQUIRE |
| 120 | +
|
| 121 | + # unpack all single torch versions wheels in the same directory |
| 122 | + mkdir dist/unpacked |
| 123 | + find dist -name "*.whl" -print -exec python -m wheel unpack --dest dist/unpacked/ {} ';' |
| 124 | +
|
| 125 | + sed -i "s/Requires-Dist: torch.*/$MERGED_TORCH_REQUIRE/" dist/unpacked/pet_neighbors_convert-*/pet_neighbors_convert-*.dist-info/METADATA |
| 126 | +
|
| 127 | + echo "\n\n METADATA = \n\n" |
| 128 | + cat dist/unpacked/pet_neighbors_convert-*/pet_neighbors_convert-*.dist-info/METADATA |
| 129 | +
|
| 130 | + # check the right metadata was added to the file. grep will exit with |
| 131 | + # code `1` if the line is not found, which will stop CI |
| 132 | + grep "$MERGED_TORCH_REQUIRE" dist/unpacked/pet_neighbors_convert-*/pet_neighbors_convert-*.dist-info/METADATA |
| 133 | +
|
| 134 | + # repack the directory as a new wheel |
| 135 | + mkdir wheelhouse |
| 136 | + python -m wheel pack --dest wheelhouse/ dist/unpacked/* |
| 137 | +
|
| 138 | + - name: check wheels with twine |
| 139 | + run: twine check wheelhouse/* |
| 140 | + |
| 141 | + - uses: actions/upload-artifact@v4 |
| 142 | + with: |
| 143 | + name: wheel-${{ matrix.os }}-${{ matrix.arch }} |
| 144 | + path: ./wheelhouse/*.whl |
| 145 | + |
| 146 | + build-sdist: |
| 147 | + name: sdist |
| 148 | + runs-on: ubuntu-22.04 |
| 149 | + steps: |
| 150 | + - uses: actions/checkout@v4 |
| 151 | + with: |
| 152 | + fetch-depth: 0 |
| 153 | + |
| 154 | + - name: Set up Python |
| 155 | + uses: actions/setup-python@v5 |
| 156 | + with: |
| 157 | + python-version: "3.13" |
| 158 | + |
| 159 | + - name: install dependencies |
| 160 | + run: python -m pip install build |
| 161 | + |
| 162 | + - name: build sdist |
| 163 | + env: |
| 164 | + PIP_EXTRA_INDEX_URL: "https://download.pytorch.org/whl/cpu" |
| 165 | + run: python -m build . --outdir=dist/ |
| 166 | + |
| 167 | + - uses: actions/upload-artifact@v4 |
| 168 | + with: |
| 169 | + name: sdist |
| 170 | + path: dist/*.tar.gz |
| 171 | + |
| 172 | + merge-and-release: |
| 173 | + name: Merge and release wheels/sdists |
| 174 | + needs: [merge-wheels, build-sdist] |
| 175 | + runs-on: ubuntu-22.04 |
| 176 | + permissions: |
| 177 | + contents: write |
| 178 | + id-token: write |
| 179 | + pull-requests: write |
| 180 | + environment: |
| 181 | + name: pypi |
| 182 | + url: https://pypi.org/project/pet-neighbors-convert |
| 183 | + steps: |
| 184 | + - name: Download wheels |
| 185 | + uses: actions/download-artifact@v4 |
| 186 | + with: |
| 187 | + path: wheels |
| 188 | + pattern: wheel-* |
| 189 | + merge-multiple: true |
| 190 | + |
| 191 | + - name: Download sdist |
| 192 | + uses: actions/download-artifact@v4 |
| 193 | + with: |
| 194 | + path: wheels |
| 195 | + name: sdist |
| 196 | + |
| 197 | + - name: Re-upload a single wheels artifact |
| 198 | + uses: actions/upload-artifact@v4 |
| 199 | + with: |
| 200 | + name: wheels |
| 201 | + path: wheels/* |
| 202 | + |
| 203 | + - name: Comment with download link |
| 204 | + uses: PicoCentauri/comment-artifact@v1 |
| 205 | + if: github.event.pull_request.head.repo.fork == false |
| 206 | + with: |
| 207 | + name: wheels |
| 208 | + description: ⚙️ Download Python wheels for this pull-request (you can install these with pip) |
| 209 | + |
| 210 | + - name: Publish distribution to PyPI |
| 211 | + if: startsWith(github.ref, 'refs/tags/v') |
| 212 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 213 | + with: |
| 214 | + packages-dir: wheels |
| 215 | + |
| 216 | + - name: upload to GitHub release |
| 217 | + if: startsWith(github.ref, 'refs/tags/v') |
| 218 | + uses: softprops/action-gh-release@v2 |
| 219 | + with: |
| 220 | + files: | |
| 221 | + wheels/*.tar.gz |
| 222 | + wheels/*.whl |
| 223 | + prerelease: ${{ contains(github.ref, '-rc') }} |
| 224 | + env: |
| 225 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 226 | + |
0 commit comments