From 072786393f261551055956e471b732bd78d51d80 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Oct 2024 23:59:33 +0000 Subject: [PATCH] Attempt to build wheels in parallel --- .github/workflows/python-distributions.yml | 50 ++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-distributions.yml b/.github/workflows/python-distributions.yml index dc1b1abd1..972a4fb80 100644 --- a/.github/workflows/python-distributions.yml +++ b/.github/workflows/python-distributions.yml @@ -7,12 +7,56 @@ on: - cron: "0 6 * * *" # Daily 6AM UTC build jobs: + define-matrix: + runs-on: ubuntu-latest + outputs: + # output all build identifiers when running on the default branch or a + # tag, otherwise just the latest Python version + linux-build-identifiers: ${{ steps.build-identifiers.outputs.linux-build-identifiers }} + macos-build-identifiers: ${{ steps.build-identifiers.outputs.macos-build-identifiers }} + windows-build-identifiers: ${{ steps.build-identifiers.outputs.windows-build-identifiers }} + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.x + cache: pip + - name: Install jq + run: sudo apt-get update && sudo apt-get install -y jq + - name: Install cibuildwheel + run: pip install cibuildwheel + - name: Find build identifiers using cibuildwheel --print-build-identifiers + id: all-build-identifiers + run: + echo "linux-build-identifiers=$(cibuildwheel --platform linux --print-build-identifiers | jq -R -s -c 'split("\n") | map(select(length > 0))')" >> $GITHUB_OUTPUT + echo "macos-build-identifiers=$(cibuildwheel --platform macos --print-build-identifiers | jq -R -s -c 'split("\n") | map(select(length > 0))')" >> $GITHUB_OUTPUT + echo "windows-build-identifiers=$(cibuildwheel --platform windows --print-build-identifiers | jq -R -s -c 'split("\n") | map(select(length > 0))')" >> $GITHUB_OUTPUT + - name: Set build identifiers output + id: build-identifiers + run: | + if [ "$GITHUB_REF" = "refs/heads/main" ] || [ "$GITHUB_REF" = "refs/heads/master" ] || [ "$GITHUB_REF" = "refs/tags/"* ]; then + echo 'linux-build-identifiers=${{ steps.all-build-identifiers.outputs.linux-build-identifiers }}' >> $GITHUB_OUTPUT + echo 'windows-build-identifiers=${{ steps.all-build-identifiers.outputs.windows-build-identifiers }}' >> $GITHUB_OUTPUT + echo 'macos-build-identifiers=${{ steps.all-build-identifiers.outputs.macos-build-identifiers }}' >> $GITHUB_OUTPUT + else + echo 'linux-build-identifiers=$(echo -n ${{ steps.all-build-identifiers.outputs.latest-build-identifiers }} | jq -c "[.[-1]]")' >> $GITHUB_OUTPUT + echo 'macos-build-identifiers=$(echo -n ${{ steps.all-build-identifiers.outputs.macos-build-identifiers }} | jq -c "[.[-1]]")' >> $GITHUB_OUTPUT + echo 'windows-build-identifiers=$(echo -n ${{ steps.all-build-identifiers.outputs.windows-build-identifiers }} | jq -c "[.[-1]]")' >> $GITHUB_OUTPUT + fi + build-wheels: runs-on: ${{ matrix.os }} + needs: define-matrix strategy: matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - python-prefix: [pp, cp] + include: + - os: ubuntu-latest + build-identifier: ${{ fromJSON(needs.define-matrix.outputs.linux-build-identifiers) }} + - os: macos-latest + build-identifier: ${{ fromJSON(needs.define-matrix.outputs.macos-build-identifiers) }} + - os: windows-latest + build-identifier: ${{ fromJSON(needs.define-matrix.outputs.windows-build-identifiers) }} fail-fast: true steps: @@ -30,7 +74,7 @@ jobs: - name: Build wheels run: python -m cibuildwheel --output-dir wheelhouse env: - CIBW_BUILD: "${{ matrix.python-prefix }}*" + CIBW_BUILD: "${{ matrix.build-identifier }}*" - name: Upload wheels uses: actions/upload-artifact@v4 with: