Skip to content

Generate the matrix for building the pythonbuild crate #673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 27 additions & 22 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ env:
FORCE_COLOR: 1

jobs:
pythonbuild:
if: ${{ needs.generate-matrix.outputs.pythonbuild_changed == 'true' || needs.generate-matrix.outputs.any_builds == 'true' || github.ref == 'refs/heads/main' }}
crate-build:
needs:
- generate-matrix
runs-on: depot-ubuntu-22.04
runs-on: ${{ matrix.runner }}
strategy:
matrix: ${{ fromJson(needs.generate-matrix.outputs.crate-build-matrix) }}
fail-fast: false
name: crate / ${{ matrix.arch }}
steps:
- name: Install System Dependencies
run: |
Expand Down Expand Up @@ -45,7 +48,7 @@ jobs:
- name: Upload pythonbuild Executable
uses: actions/upload-artifact@v4
with:
name: pythonbuild
name: ${{ matrix.crate_artifact_name }}
path: target/release/pythonbuild

image:
Expand All @@ -55,7 +58,7 @@ jobs:
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.generate-matrix.outputs.docker-build-matrix) }}
name: ${{ matrix.name }}
name: image / ${{ matrix.name }}
runs-on: ${{ matrix.runner }}
permissions:
packages: write
Expand Down Expand Up @@ -122,8 +125,8 @@ jobs:
python-build-matrix-0: ${{ steps.set-matrix.outputs.python-build-matrix-0 }}
python-build-matrix-1: ${{ steps.set-matrix.outputs.python-build-matrix-1 }}
docker-build-matrix: ${{ steps.set-matrix.outputs.docker-build-matrix }}
crate-build-matrix: ${{ steps.set-matrix.outputs.crate-build-matrix }}
any_builds: ${{ steps.set-matrix.outputs.any_builds }}
pythonbuild_changed: ${{ steps.check-pythonbuild.outputs.changed }}
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -139,18 +142,32 @@ jobs:
LABELS=$(echo '${{ toJson(github.event.pull_request.labels.*.name) }}' | jq -r 'join(",")')
echo "labels=$LABELS" >> $GITHUB_OUTPUT

- name: Check if the `pythonbuild` crate changed
id: check-pythonbuild
env:
BASE_REF: ${{ github.event.pull_request.base.ref || 'main' }}
run: |
merge_base=$(git merge-base HEAD "origin/${BASE_REF}")
if git diff --quiet "${merge_base}...HEAD" -- ':src/*.rs'; then
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
fi

- name: Generate build matrix
id: set-matrix
run: |
uv run ci-matrix.py \
--platform linux \
--labels '${{ steps.get-labels.outputs.labels }}' \
--max-shards 2 \
${{ (steps.check-pythonbuild.outputs.changed == 'true' || github.ref == 'refs/heads/main') && '--force-crate-build' || '' }} \
> matrix.json

echo "python-build-matrix-0=$(jq -c '."python-build"["0"]' matrix.json)" >> $GITHUB_OUTPUT
echo "python-build-matrix-1=$(jq -c '."python-build"["1"]' matrix.json)" >> $GITHUB_OUTPUT
echo "docker-build-matrix=$(jq -c '."docker-build"' matrix.json)" >> $GITHUB_OUTPUT
echo "crate-build-matrix=$(jq -c '."crate-build"' matrix.json)" >> $GITHUB_OUTPUT

# Display the matrix for debugging too
cat matrix.json | jq
Expand All @@ -163,22 +180,10 @@ jobs:
echo "any_builds=false" >> $GITHUB_OUTPUT
fi

- name: Check if the `pythonbuild` crate changed
id: check-pythonbuild
env:
BASE_REF: ${{ github.event.pull_request.base.ref || 'main' }}
run: |
merge_base=$(git merge-base HEAD "origin/${BASE_REF}")
if git diff --quiet "${merge_base}...HEAD" -- ':src/*.rs'; then
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
fi

build-0:
needs:
- generate-matrix
- pythonbuild
- crate-build
- image
# Permissions used for actions/attest-build-provenance
permissions:
Expand All @@ -202,7 +207,7 @@ jobs:
- name: Download pythonbuild
uses: actions/download-artifact@v4
with:
name: pythonbuild
name: ${{ matrix.crate_artifact_name }}
path: build

- name: Download images
Expand Down Expand Up @@ -278,7 +283,7 @@ jobs:
build-1:
needs:
- generate-matrix
- pythonbuild
- crate-build
- image
# Permissions used for actions/attest-build-provenance
permissions:
Expand All @@ -302,7 +307,7 @@ jobs:
- name: Download pythonbuild
uses: actions/download-artifact@v4
with:
name: pythonbuild
name: ${{ matrix.crate_artifact_name }}
path: build

- name: Download images
Expand Down
44 changes: 24 additions & 20 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ env:
FORCE_COLOR: 1

jobs:
pythonbuild:
if: ${{ needs.generate-matrix.outputs.pythonbuild_changed == 'true' || needs.generate-matrix.outputs.any_builds == 'true' || github.ref == 'refs/heads/main' }}
crate-build:
needs:
- generate-matrix
runs-on: depot-macos-latest
runs-on: ${{ matrix.runner }}
strategy:
matrix: ${{ fromJson(needs.generate-matrix.outputs.crate-build-matrix) }}
fail-fast: false
name: crate / ${{ matrix.arch }}
steps:
- uses: actions/checkout@v4

Expand All @@ -40,15 +43,15 @@ jobs:
- name: Upload pythonbuild Executable
uses: actions/upload-artifact@v4
with:
name: pythonbuild
name: ${{ matrix.crate_artifact_name }}
path: target/release/pythonbuild

generate-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
crate-build-matrix: ${{ steps.set-matrix.outputs.crate-build-matrix }}
any_builds: ${{ steps.set-matrix.outputs.any_builds }}
pythonbuild_changed: ${{ steps.check-pythonbuild.outputs.changed }}
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -64,13 +67,26 @@ jobs:
LABELS=$(echo '${{ toJson(github.event.pull_request.labels.*.name) }}' | jq -r 'join(",")')
echo "labels=$LABELS" >> $GITHUB_OUTPUT

- name: Check if the `pythonbuild` crate changed
id: check-pythonbuild
env:
BASE_REF: ${{ github.event.pull_request.base.ref || 'main' }}
run: |
merge_base=$(git merge-base HEAD "origin/${BASE_REF}")
if git diff --quiet "${merge_base}...HEAD" -- ':src/*.rs'; then
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
fi

- name: Generate build matrix
id: set-matrix
run: |
uv run ci-matrix.py --platform darwin --labels '${{ steps.get-labels.outputs.labels }}' > matrix.json
uv run ci-matrix.py --platform darwin --labels '${{ steps.get-labels.outputs.labels }}' ${{ (steps.check-pythonbuild.outputs.changed == 'true' || github.ref == 'refs/heads/main') && '--force-crate-build' || '' }} > matrix.json

# Extract python-build matrix
echo "matrix=$(jq -c '."python-build"' matrix.json)" >> $GITHUB_OUTPUT
echo "crate-build-matrix=$(jq -c '."crate-build"' matrix.json)" >> $GITHUB_OUTPUT

# Display the matrix for debugging too
cat matrix.json | jq
Expand All @@ -83,22 +99,10 @@ jobs:
echo "any_builds=false" >> $GITHUB_OUTPUT
fi

- name: Check if the `pythonbuild` crate changed
id: check-pythonbuild
env:
BASE_REF: ${{ github.event.pull_request.base.ref || 'main' }}
run: |
merge_base=$(git merge-base HEAD "origin/${BASE_REF}")
if git diff --quiet "${merge_base}...HEAD" -- ':src/*.rs'; then
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
fi

build:
needs:
- generate-matrix
- pythonbuild
- crate-build
# Permissions used for actions/attest-build-provenance
permissions:
id-token: write
Expand All @@ -121,7 +125,7 @@ jobs:
- name: Download pythonbuild
uses: actions/download-artifact@v4
with:
name: pythonbuild
name: ${{ matrix.crate_artifact_name }}
path: build

- name: Build
Expand Down
44 changes: 24 additions & 20 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ env:
FORCE_COLOR: 1

jobs:
pythonbuild:
if: ${{ needs.generate-matrix.outputs.pythonbuild_changed == 'true' || needs.generate-matrix.outputs.any_builds == 'true' || github.ref == 'refs/heads/main' }}
crate-build:
needs:
- generate-matrix
runs-on: 'windows-2022'
runs-on: ${{ matrix.runner }}
strategy:
matrix: ${{ fromJson(needs.generate-matrix.outputs.crate-build-matrix) }}
fail-fast: false
name: crate / ${{ matrix.arch }}
steps:
- uses: actions/checkout@v4

Expand All @@ -40,15 +43,15 @@ jobs:
- name: Upload executable
uses: actions/upload-artifact@v4
with:
name: pythonbuild
name: ${{ matrix.crate_artifact_name }}
path: target/release/pythonbuild.exe

generate-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
crate-build-matrix: ${{ steps.set-matrix.outputs.crate-build-matrix }}
any_builds: ${{ steps.set-matrix.outputs.any_builds }}
pythonbuild_changed: ${{ steps.check-pythonbuild.outputs.changed }}
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -64,13 +67,26 @@ jobs:
LABELS=$(echo '${{ toJson(github.event.pull_request.labels.*.name) }}' | jq -r 'join(",")')
echo "labels=$LABELS" >> $GITHUB_OUTPUT

- name: Check if the `pythonbuild` crate changed
id: check-pythonbuild
env:
BASE_REF: ${{ github.event.pull_request.base.ref || 'main' }}
run: |
merge_base=$(git merge-base HEAD "origin/${BASE_REF}")
if git diff --quiet "${merge_base}...HEAD" -- ':src/*.rs'; then
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
fi

- name: Generate build matrix
id: set-matrix
run: |
uv run ci-matrix.py --platform windows --labels '${{ steps.get-labels.outputs.labels }}' > matrix.json
uv run ci-matrix.py --platform windows --labels '${{ steps.get-labels.outputs.labels }}' ${{ (steps.check-pythonbuild.outputs.changed == 'true' || github.ref == 'refs/heads/main') && '--force-crate-build' || '' }} > matrix.json

# Extract python-build matrix
echo "matrix=$(jq -c '."python-build"' matrix.json)" >> $GITHUB_OUTPUT
echo "crate-build-matrix=$(jq -c '."crate-build"' matrix.json)" >> $GITHUB_OUTPUT

# Display the matrix for debugging too
cat matrix.json | jq
Expand All @@ -83,23 +99,11 @@ jobs:
echo "any_builds=false" >> $GITHUB_OUTPUT
fi

- name: Check if the `pythonbuild` crate changed
id: check-pythonbuild
env:
BASE_REF: ${{ github.event.pull_request.base.ref || 'main' }}
run: |
merge_base=$(git merge-base HEAD "origin/${BASE_REF}")
if git diff --quiet "${merge_base}...HEAD" -- ':src/*.rs'; then
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
fi

build:
timeout-minutes: 60
needs:
- generate-matrix
- pythonbuild
- crate-build
# Permissions used for actions/attest-build-provenance
permissions:
id-token: write
Expand Down Expand Up @@ -127,7 +131,7 @@ jobs:
- name: Download pythonbuild Executable
uses: actions/download-artifact@v4
with:
name: pythonbuild
name: ${{ matrix.crate_artifact_name }}

# We need to do this before we activate the VC++ environment or else binary packages
# don't get compiled properly.
Expand Down
Loading
Loading