add wdws and macos runs to main pushes, simplify #165
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
| # ported and adapted from: | |
| # - https://github.com/stardist/stardist/blob/main/.github/workflows/cibuildwheel.yaml | |
| name: tests | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - wheels | |
| release: | |
| types: | |
| - published | |
| pull_request: | |
| branches: [ "main" ] | |
| jobs: | |
| build_wheels: | |
| name: Build cp${{ matrix.python }}-${{ matrix.platform_id }} on ${{ matrix.os }} | |
| runs-on: ${{ matrix.os }} | |
| if: (github.event_name == 'release' && github.event.action == 'published') || (github.event_name == 'push' && contains(github.ref, 'wheels')) || github.event_name == 'pull_request' | |
| # for conda-incubator/setup-miniconda to work | |
| defaults: | |
| run: | |
| shell: bash -el {0} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| # push/PR events (subset, 3 py versions for ubuntu and 1 each for windows and macos) | |
| - os: ubuntu-latest | |
| python: 312 | |
| platform_id: manylinux_x86_64 | |
| manylinux_image: manylinux_2_28 | |
| build_condition: reduced | |
| - os: ubuntu-latest | |
| python: 313 | |
| platform_id: manylinux_x86_64 | |
| manylinux_image: manylinux_2_28 | |
| build_condition: reduced | |
| - os: ubuntu-latest | |
| python: 314 | |
| platform_id: manylinux_x86_64 | |
| manylinux_image: manylinux_2_28 | |
| build_condition: reduced | |
| - os: windows-latest | |
| python: 312 | |
| platform_id: win_amd64 | |
| build_condition: reduced | |
| - os: macos-14 | |
| python: 312 | |
| platform_id: macosx_arm64 | |
| build_condition: reduced | |
| # For releases and PR events (full matrix) | |
| # Linux | |
| - os: ubuntu-latest | |
| python: 39 | |
| platform_id: manylinux_x86_64 | |
| manylinux_image: manylinux_2_28 | |
| build_condition: full | |
| - os: ubuntu-latest | |
| python: 310 | |
| platform_id: manylinux_x86_64 | |
| manylinux_image: manylinux_2_28 | |
| build_condition: full | |
| - os: ubuntu-latest | |
| python: 311 | |
| platform_id: manylinux_x86_64 | |
| manylinux_image: manylinux_2_28 | |
| build_condition: full | |
| - os: ubuntu-latest | |
| python: 312 | |
| platform_id: manylinux_x86_64 | |
| manylinux_image: manylinux_2_28 | |
| build_condition: full | |
| - os: ubuntu-latest | |
| python: 313 | |
| platform_id: manylinux_x86_64 | |
| manylinux_image: manylinux_2_28 | |
| build_condition: full | |
| - os: ubuntu-latest | |
| python: 314 | |
| platform_id: manylinux_x86_64 | |
| manylinux_image: manylinux_2_28 | |
| build_condition: full | |
| # Windows | |
| - os: windows-latest | |
| python: 39 | |
| platform_id: win_amd64 | |
| build_condition: full | |
| - os: windows-latest | |
| python: 310 | |
| platform_id: win_amd64 | |
| build_condition: full | |
| - os: windows-latest | |
| python: 311 | |
| platform_id: win_amd64 | |
| build_condition: full | |
| - os: windows-latest | |
| python: 312 | |
| platform_id: win_amd64 | |
| build_condition: full | |
| - os: windows-latest | |
| python: 313 | |
| platform_id: win_amd64 | |
| build_condition: full | |
| - os: windows-latest | |
| python: 314 | |
| platform_id: win_amd64 | |
| build_condition: full | |
| # macOS x86_64 (py314 not supported due to missing torchvision wheels) | |
| - os: macos-15-intel | |
| python: 39 | |
| platform_id: macosx_x86_64 | |
| build_condition: full | |
| - os: macos-15-intel | |
| python: 310 | |
| platform_id: macosx_x86_64 | |
| build_condition: full | |
| - os: macos-15-intel | |
| python: 311 | |
| platform_id: macosx_x86_64 | |
| build_condition: full | |
| - os: macos-15-intel | |
| python: 312 | |
| platform_id: macosx_x86_64 | |
| build_condition: full | |
| - os: macos-15-intel | |
| python: 313 | |
| platform_id: macosx_x86_64 | |
| build_condition: full | |
| # macOS arm64 | |
| - os: macos-14 | |
| python: 39 | |
| platform_id: macosx_arm64 | |
| build_condition: full | |
| - os: macos-14 | |
| python: 310 | |
| platform_id: macosx_arm64 | |
| build_condition: full | |
| - os: macos-14 | |
| python: 311 | |
| platform_id: macosx_arm64 | |
| build_condition: full | |
| - os: macos-14 | |
| python: 312 | |
| platform_id: macosx_arm64 | |
| build_condition: full | |
| - os: macos-14 | |
| python: 313 | |
| platform_id: macosx_arm64 | |
| build_condition: full | |
| - os: macos-14 | |
| python: 314 | |
| platform_id: macosx_arm64 | |
| build_condition: full | |
| steps: | |
| # skip based on event type and build condition | |
| - name: Skip build check | |
| id: skip_check | |
| run: | | |
| SKIP=false | |
| # run reduced builds for pushes to main | |
| if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" != *"wheels"* ]]; then | |
| if [[ "${{ matrix.build_condition }}" == "full" ]]; then | |
| SKIP=true | |
| fi | |
| fi | |
| # run full builds for releases and PRs | |
| if [[ ("${{ github.event_name }}" == "release" || "${{ github.event_name }}" == "pull_request") && "${{ matrix.build_condition }}" == "reduced" ]]; then | |
| SKIP=true | |
| fi | |
| # run full builds for pushes to wheels branch | |
| if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == *"wheels"* && "${{ matrix.build_condition }}" == "reduced" ]]; then | |
| SKIP=true | |
| fi | |
| echo "skip=$SKIP" >> $GITHUB_OUTPUT | |
| if [[ "$SKIP" == "true" ]]; then | |
| echo "Skipping build for ${{ matrix.build_condition }} on ${{ github.event_name }}" | |
| fi | |
| - name: Checkout repository | |
| if: steps.skip_check.outputs.skip != 'true' | |
| uses: actions/checkout@v5 | |
| - name: Setup Python | |
| if: steps.skip_check.outputs.skip != 'true' | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.13' | |
| - name: Setup Miniconda | |
| uses: conda-incubator/setup-miniconda@v3 | |
| if: ${{ steps.skip_check.outputs.skip != 'true' && startsWith(matrix.platform_id, 'macosx') }} | |
| with: | |
| miniforge-version: latest | |
| - name: Build and test wheels | |
| if: steps.skip_check.outputs.skip != 'true' | |
| run: | | |
| set -ex | |
| # follow approach of scikit-learn: https://github.com/scikit-learn/scikit-learn/blob/7f0900c265936eac9a89bba37eb19ee66208d46a/build_tools/wheels/build_wheels.sh | |
| if [[ $(uname) == "Darwin" ]]; then | |
| if [[ "$CIBW_BUILD" == *-macosx_arm64 ]]; then | |
| # SciPy requires 12.0 on arm to prevent kernel panics | |
| # https://github.com/scipy/scipy/issues/14688 | |
| export MACOSX_DEPLOYMENT_TARGET=12.0 | |
| OPENMP_URL="https://anaconda.org/conda-forge/llvm-openmp/11.1.0/download/osx-arm64/llvm-openmp-11.1.0-hf3c4609_1.tar.bz2" | |
| else | |
| export MACOSX_DEPLOYMENT_TARGET=10.9 | |
| OPENMP_URL="https://anaconda.org/conda-forge/llvm-openmp/11.1.0/download/osx-64/llvm-openmp-11.1.0-hda6cdc1_1.tar.bz2" | |
| fi | |
| echo MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET} | |
| conda create -n build $OPENMP_URL | |
| PREFIX="$HOME/miniconda3/envs/build" | |
| export CC=/usr/bin/clang | |
| export CXX=/usr/bin/clang++ | |
| export CFLAGS="$CFLAGS -I$PREFIX/include" | |
| export CXXFLAGS="$CXXFLAGS -I$PREFIX/include" | |
| export LDFLAGS="$LDFLAGS -Wl,-rpath,$PREFIX/lib -L$PREFIX/lib -lomp" | |
| fi | |
| python -m pip install cibuildwheel | |
| python -m cibuildwheel --output-dir dist | |
| env: | |
| CIBW_BUILD: cp${{ matrix.python }}-${{ matrix.platform_id }} | |
| CIBW_ARCHS: all | |
| CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.manylinux_image }} | |
| CIBW_BUILD_VERBOSITY: 1 | |
| CIBW_TEST_REQUIRES: pytest pytest-cov | |
| CIBW_TEST_COMMAND: pytest -v --cov=spotiflow {project} | |
| - name: Upload wheels | |
| if: steps.skip_check.outputs.skip != 'true' | |
| uses: actions/upload-artifact@v5 | |
| with: | |
| name: cibw-wheels-cp${{ matrix.python }}-${{ matrix.platform_id }} | |
| path: dist/*.whl | |
| build_sdist: | |
| name: Build source distribution | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v5 | |
| - name: Build sdist | |
| run: pipx run build --sdist | |
| - name: Upload sdist | |
| uses: actions/upload-artifact@v5 | |
| with: | |
| name: cibw-sdist | |
| path: dist/*.tar.gz | |
| upload_pypi: | |
| name: Upload to PyPI | |
| needs: [build_wheels, build_sdist] | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'release' && github.event.action == 'published' | |
| steps: | |
| - name: Download wheels and sdist | |
| uses: actions/download-artifact@v6 | |
| with: | |
| pattern: cibw-* | |
| path: dist | |
| merge-multiple: true | |
| - name: Check that package version matches git tag ${{ github.ref_name }} | |
| shell: bash | |
| run: | | |
| ls -l dist | |
| test -f "dist/stardist-${{ github.ref_name }}.tar.gz" | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| user: __token__ | |
| password: ${{ secrets.PYPI_API_TOKEN }} | |
| verbose: true | |
| # password: ${{ secrets.TESTPYPI_API_TOKEN }} | |
| # repository-url: https://test.pypi.org/legacy/ |