diff --git a/.github/workflows/deploy-to-pypi.yml b/.github/workflows/deploy-to-pypi.yml index 20938ee..67ad224 100644 --- a/.github/workflows/deploy-to-pypi.yml +++ b/.github/workflows/deploy-to-pypi.yml @@ -4,16 +4,28 @@ name: Build distributions and upload to PyPI on: [push, pull_request] jobs: + + calculate_wheels_to_build: + name: Calculate OS/archs to build wheels on + runs-on: ubuntu-20.04 + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + macos_archs: ${{ startsWith(github.event.ref, 'refs/tags/v') && 'x86_64 arm64 universal2' || 'auto' }} + steps: + - name: Calculate strategy matrix + id: set-matrix + env: + MATRIX_INCLUDES: ${{ startsWith(github.event.ref, 'refs/tags/v') && '[{"os": "ubuntu-20.04", "arch_linux": "aarch64"}]' || '[]' }} + run: echo "matrix={\"os\": [\"ubuntu-20.04\", \"windows-2019\", \"macos-12\"], \"arch_linux\": [\"auto\"], \"include\": $MATRIX_INCLUDES}" >> "$GITHUB_OUTPUT" + build_wheels: name: Build wheels on ${{matrix.arch}} for ${{ matrix.os }} + needs: calculate_wheels_to_build runs-on: ${{ matrix.os }} strategy: - matrix: - os: [ubuntu-20.04, windows-2019, macos-12] - arch: [auto] - include: - - os: ubuntu-20.04 - arch: aarch64 + matrix: ${{ fromJson(needs.calculate_wheels_to_build.outputs.matrix) }} + env: + ARCHS_MACOS: ${{ needs.calculate_wheels_to_build.outputs.macos_archs }} steps: - uses: actions/checkout@v3 @@ -37,8 +49,8 @@ jobs: run: | python -m cibuildwheel --output-dir wheelhouse env: - CIBW_ARCHS_LINUX: ${{matrix.arch}} - CIBW_ARCHS_MACOS: "x86_64 arm64 universal2" + CIBW_ARCHS_LINUX: ${{ matrix.arch_linux }} + CIBW_ARCHS_MACOS: ${{ env.ARCHS_MACOS }} CIBW_BEFORE_ALL: "bash -c 'cd \"{project}\"; sh .github/tools/install_yajl.sh'" CIBW_BUILD_VERBOSITY: 1 CIBW_ENVIRONMENT_MACOS: "IJSON_EMBED_YAJL=1"