|
| 1 | +name: Wheels |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + tags: |
| 7 | + - "v*" |
| 8 | + release: |
| 9 | + types: |
| 10 | + - published |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + |
| 15 | +jobs: |
| 16 | + |
| 17 | + build_sdist: |
| 18 | + name: Build source distribution |
| 19 | + runs-on: ubuntu-22.04 |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + |
| 25 | + - uses: actions/setup-python@v4 |
| 26 | + name: Install Python |
| 27 | + with: |
| 28 | + python-version: 3.x |
| 29 | + |
| 30 | + - name: Install APT packages |
| 31 | + if: contains(${{ matrix.os }}, 'ubuntu') |
| 32 | + run: | |
| 33 | + sudo apt update |
| 34 | + sudo apt install libhdf5-dev libnetcdf-dev |
| 35 | +
|
| 36 | + - name: Build sdist |
| 37 | + run: > |
| 38 | + pip install build |
| 39 | + && python -m build --sdist . --outdir dist |
| 40 | +
|
| 41 | + - uses: actions/upload-artifact@v4 |
| 42 | + with: |
| 43 | + name: pypi-artifacts |
| 44 | + path: ${{ github.workspace }}/dist/*.tar.gz |
| 45 | + |
| 46 | + |
| 47 | + build_bdist: |
| 48 | + name: "Build ${{ matrix.os }} (${{ matrix.arch }}) wheels" |
| 49 | + runs-on: ${{ matrix.os }} |
| 50 | + strategy: |
| 51 | + fail-fast: false |
| 52 | + matrix: |
| 53 | + include: |
| 54 | + - os: ubuntu-22.04 |
| 55 | + arch: x86_64 |
| 56 | + # - os: ubuntu-22.04 |
| 57 | + # arch: aarch64 |
| 58 | + - os: macos-14 |
| 59 | + arch: arm64 |
| 60 | + CIBW_ENVIRONMENT: MACOSX_DEPLOYMENT_TARGET=14.0 |
| 61 | + - os: macos-11 |
| 62 | + arch: x86_64 |
| 63 | + CIBW_ENVIRONMENT: MACOSX_DEPLOYMENT_TARGET=11.0 |
| 64 | + |
| 65 | + steps: |
| 66 | + - uses: actions/checkout@v4 |
| 67 | + with: |
| 68 | + fetch-depth: 0 |
| 69 | + submodules: 'true' |
| 70 | + |
| 71 | + - name: Build oldest and newest Python |
| 72 | + shell: bash |
| 73 | + # On PRs we run only oldest and newest Python versions to reduce CI load. |
| 74 | + # Skips pypy and musllinux everywhere. |
| 75 | + # We are buiding 38 and 312 for now. |
| 76 | + # These needs to rotate every new Python release. |
| 77 | + run: | |
| 78 | + if [[ "${{ github.event_name }}" == "pull_request" ]]; then |
| 79 | + CIBW_SKIP="pp* cp36-* cp37-* *-musllinux* cp39-* cp310-* cp311-*" |
| 80 | + else |
| 81 | + CIBW_SKIP="pp* cp36-* cp37-* *-musllinux*" |
| 82 | + fi |
| 83 | + echo "CIBW_SKIP=$CIBW_SKIP" >> $GITHUB_ENV |
| 84 | + echo "Setting CIBW_SKIP=$CIBW_SKIP" |
| 85 | +
|
| 86 | + - name: "Building ${{ matrix.os }} (${{ matrix.arch }}) wheels" |
| 87 | + uses: pypa/cibuildwheel@v2.18.1 |
| 88 | + env: |
| 89 | + CIBW_SKIP: ${{ env.CIBW_SKIP }} |
| 90 | + CIBW_ARCHS: ${{ matrix.arch }} |
| 91 | + CIBW_BUILD_FRONTEND: build |
| 92 | + CIBW_MANYLINUX_X86_64_IMAGE: manylinux_2_28 |
| 93 | + CIBW_BEFORE_BUILD_LINUX: > |
| 94 | + dnf install -y epel-release |
| 95 | + && dnf install -y hdf5-devel libcurl-devel |
| 96 | + && sh .ci/build_deps.sh |
| 97 | + CIBW_ENVIRONMENT: ${{ matrix.CIBW_ENVIRONMENT }} |
| 98 | + CIBW_BEFORE_BUILD_MACOS: brew install hdf5 netcdf |
| 99 | + CIBW_TEST_REQUIRES: pytest cython packaging |
| 100 | + CIBW_TEST_COMMAND: > |
| 101 | + python -c "import netCDF4; print(f'netCDF4 v{netCDF4.__version__}')" |
| 102 | + && pytest -s -rxs -v {project}/test |
| 103 | +
|
| 104 | + - uses: actions/upload-artifact@v4 |
| 105 | + with: |
| 106 | + name: pypi-artifacts-${{ matrix.os }}-${{ matrix.arch }} |
| 107 | + path: ${{ github.workspace }}/wheelhouse/*.whl |
| 108 | + |
| 109 | + |
| 110 | + build_wheels_windows: |
| 111 | + name: Build wheels for ${{matrix.arch}} on ${{ matrix.os }} |
| 112 | + runs-on: ${{ matrix.os }} |
| 113 | + strategy: |
| 114 | + matrix: |
| 115 | + os: [windows-latest] |
| 116 | + arch: [win_amd64] |
| 117 | + |
| 118 | + steps: |
| 119 | + - uses: actions/checkout@v4 |
| 120 | + with: |
| 121 | + fetch-depth: 0 |
| 122 | + submodules: 'true' |
| 123 | + |
| 124 | + - uses: actions/setup-python@v4 |
| 125 | + name: Install Python |
| 126 | + with: |
| 127 | + python-version: 3.x |
| 128 | + |
| 129 | + - name: Setup Micromamba Python ${{ matrix.python-version }} |
| 130 | + uses: mamba-org/setup-micromamba@v1 |
| 131 | + with: |
| 132 | + environment-name: build |
| 133 | + init-shell: bash |
| 134 | + create-args: >- |
| 135 | + python=${{ matrix.python-version }} libnetcdf=4.9.2 --channel conda-forge |
| 136 | +
|
| 137 | + - name: Install cibuildwheel |
| 138 | + run: | |
| 139 | + python -m pip install --upgrade cibuildwheel delvewheel |
| 140 | +
|
| 141 | + - name: Build wheels for Windows (${{ matrix.arch }}) |
| 142 | + run: cibuildwheel --output-dir wheelhouse |
| 143 | + env: |
| 144 | + CIBW_BUILD: "cp39-${{ matrix.arch }} cp310-${{ matrix.arch }} cp311-${{ matrix.arch }} cp312-${{ matrix.arch }}" |
| 145 | + CIBW_ENVIRONMENT_WINDOWS: > |
| 146 | + HDF5_DIR="C:\\Users\\runneradmin\\micromamba\\envs\\build\\Library" |
| 147 | + netCDF4_DIR="C:\\Users\\runneradmin\\micromamba\\envs\\build\\Library" |
| 148 | + PATH="C:\\Users\\runneradmin\\micromamba\\envs\\build\\Library\\bin;${PATH}" |
| 149 | + CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: > |
| 150 | + delvewheel show {wheel} |
| 151 | + && delvewheel repair -w {dest_dir} {wheel} |
| 152 | + CIBW_TEST_REQUIRES: pytest cython packaging |
| 153 | + CIBW_TEST_COMMAND: > |
| 154 | + python -c "import netCDF4; print(f'netCDF4 v{netCDF4.__version__}')" |
| 155 | + && pytest -s -rxs -v {project}\\test |
| 156 | +
|
| 157 | + - uses: actions/upload-artifact@v4 |
| 158 | + with: |
| 159 | + name: pypi-artifacts-${{ matrix.os }}-${{ matrix.arch }} |
| 160 | + path: ${{ github.workspace }}/wheelhouse/*.whl |
| 161 | + |
| 162 | + |
| 163 | + show-artifacts: |
| 164 | + needs: [build_bdist, build_sdist, build_wheels_windows] |
| 165 | + name: "Show artifacts" |
| 166 | + runs-on: ubuntu-22.04 |
| 167 | + steps: |
| 168 | + - uses: actions/download-artifact@v4 |
| 169 | + with: |
| 170 | + pattern: pypi-artifacts* |
| 171 | + path: ${{ github.workspace }}/dist |
| 172 | + merge-multiple: true |
| 173 | + |
| 174 | + - shell: bash |
| 175 | + run: | |
| 176 | + ls -lh ${{ github.workspace }}/dist |
| 177 | +
|
| 178 | +
|
| 179 | + publish-artifacts-pypi: |
| 180 | + needs: [build_bdist, build_sdist, build_wheels_windows] |
| 181 | + name: "Publish to PyPI" |
| 182 | + runs-on: ubuntu-22.04 |
| 183 | + # upload to PyPI for every tag starting with 'v' |
| 184 | + if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v') |
| 185 | + steps: |
| 186 | + - uses: actions/download-artifact@v3 |
| 187 | + with: |
| 188 | + name: pypi-artifacts |
| 189 | + path: ${{ github.workspace }}/dist |
| 190 | + |
| 191 | + - uses: pypa/gh-action-pypi-publish@release/v1 |
| 192 | + with: |
| 193 | + user: __token__ |
| 194 | + password: ${{ secrets.PYPI_PASSWORD }} |
| 195 | + print_hash: true |
0 commit comments