Skip to content

Commit 6b6b22f

Browse files
committed
Generate the matrix for building the pythonbuild crate
1 parent 526189d commit 6b6b22f

File tree

4 files changed

+162
-77
lines changed

4 files changed

+162
-77
lines changed

.github/workflows/linux.yml

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ env:
1313
FORCE_COLOR: 1
1414

1515
jobs:
16-
pythonbuild:
17-
if: ${{ needs.generate-matrix.outputs.pythonbuild_changed == 'true' || needs.generate-matrix.outputs.any_builds == 'true' || github.ref == 'refs/heads/main' }}
16+
crate-build:
1817
needs:
1918
- generate-matrix
20-
runs-on: depot-ubuntu-22.04
19+
runs-on: ${{ matrix.runner }}
20+
strategy:
21+
matrix: ${{ fromJson(needs.generate-matrix.outputs.crate-build-matrix) }}
22+
fail-fast: false
23+
name: crate / ${{ matrix.arch }}
2124
steps:
2225
- name: Install System Dependencies
2326
run: |
@@ -45,7 +48,7 @@ jobs:
4548
- name: Upload pythonbuild Executable
4649
uses: actions/upload-artifact@v4
4750
with:
48-
name: pythonbuild
51+
name: ${{ matrix.crate_artifact_name }}
4952
path: target/release/pythonbuild
5053

5154
image:
@@ -55,7 +58,7 @@ jobs:
5558
strategy:
5659
fail-fast: false
5760
matrix: ${{ fromJson(needs.generate-matrix.outputs.docker-build-matrix) }}
58-
name: ${{ matrix.name }}
61+
name: image / ${{ matrix.name }}
5962
runs-on: ${{ matrix.runner }}
6063
permissions:
6164
packages: write
@@ -122,8 +125,8 @@ jobs:
122125
python-build-matrix-0: ${{ steps.set-matrix.outputs.python-build-matrix-0 }}
123126
python-build-matrix-1: ${{ steps.set-matrix.outputs.python-build-matrix-1 }}
124127
docker-build-matrix: ${{ steps.set-matrix.outputs.docker-build-matrix }}
128+
crate-build-matrix: ${{ steps.set-matrix.outputs.crate-build-matrix }}
125129
any_builds: ${{ steps.set-matrix.outputs.any_builds }}
126-
pythonbuild_changed: ${{ steps.check-pythonbuild.outputs.changed }}
127130
steps:
128131
- uses: actions/checkout@v4
129132
with:
@@ -139,18 +142,32 @@ jobs:
139142
LABELS=$(echo '${{ toJson(github.event.pull_request.labels.*.name) }}' | jq -r 'join(",")')
140143
echo "labels=$LABELS" >> $GITHUB_OUTPUT
141144
145+
- name: Check if the `pythonbuild` crate changed
146+
id: check-pythonbuild
147+
env:
148+
BASE_REF: ${{ github.event.pull_request.base.ref || 'main' }}
149+
run: |
150+
merge_base=$(git merge-base HEAD "origin/${BASE_REF}")
151+
if git diff --quiet "${merge_base}...HEAD" -- ':src/*.rs'; then
152+
echo "changed=false" >> "$GITHUB_OUTPUT"
153+
else
154+
echo "changed=true" >> "$GITHUB_OUTPUT"
155+
fi
156+
142157
- name: Generate build matrix
143158
id: set-matrix
144159
run: |
145160
uv run ci-matrix.py \
146161
--platform linux \
147162
--labels '${{ steps.get-labels.outputs.labels }}' \
148163
--max-shards 2 \
164+
${{ (steps.check-pythonbuild.outputs.changed == 'true' || github.ref == 'refs/heads/main') && '--force-crate-build' || '' }} \
149165
> matrix.json
150166
151167
echo "python-build-matrix-0=$(jq -c '."python-build"["0"]' matrix.json)" >> $GITHUB_OUTPUT
152168
echo "python-build-matrix-1=$(jq -c '."python-build"["1"]' matrix.json)" >> $GITHUB_OUTPUT
153169
echo "docker-build-matrix=$(jq -c '."docker-build"' matrix.json)" >> $GITHUB_OUTPUT
170+
echo "crate-build-matrix=$(jq -c '."crate-build"' matrix.json)" >> $GITHUB_OUTPUT
154171
155172
# Display the matrix for debugging too
156173
cat matrix.json | jq
@@ -163,22 +180,10 @@ jobs:
163180
echo "any_builds=false" >> $GITHUB_OUTPUT
164181
fi
165182
166-
- name: Check if the `pythonbuild` crate changed
167-
id: check-pythonbuild
168-
env:
169-
BASE_REF: ${{ github.event.pull_request.base.ref || 'main' }}
170-
run: |
171-
merge_base=$(git merge-base HEAD "origin/${BASE_REF}")
172-
if git diff --quiet "${merge_base}...HEAD" -- ':src/*.rs'; then
173-
echo "changed=false" >> "$GITHUB_OUTPUT"
174-
else
175-
echo "changed=true" >> "$GITHUB_OUTPUT"
176-
fi
177-
178183
build-0:
179184
needs:
180185
- generate-matrix
181-
- pythonbuild
186+
- crate-build
182187
- image
183188
# Permissions used for actions/attest-build-provenance
184189
permissions:
@@ -202,7 +207,7 @@ jobs:
202207
- name: Download pythonbuild
203208
uses: actions/download-artifact@v4
204209
with:
205-
name: pythonbuild
210+
name: ${{ matrix.crate_artifact_name }}
206211
path: build
207212

208213
- name: Download images
@@ -278,7 +283,7 @@ jobs:
278283
build-1:
279284
needs:
280285
- generate-matrix
281-
- pythonbuild
286+
- crate-build
282287
- image
283288
# Permissions used for actions/attest-build-provenance
284289
permissions:
@@ -302,7 +307,7 @@ jobs:
302307
- name: Download pythonbuild
303308
uses: actions/download-artifact@v4
304309
with:
305-
name: pythonbuild
310+
name: ${{ matrix.crate_artifact_name }}
306311
path: build
307312

308313
- name: Download images

.github/workflows/macos.yml

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ env:
1313
FORCE_COLOR: 1
1414

1515
jobs:
16-
pythonbuild:
17-
if: ${{ needs.generate-matrix.outputs.pythonbuild_changed == 'true' || needs.generate-matrix.outputs.any_builds == 'true' || github.ref == 'refs/heads/main' }}
16+
crate-build:
1817
needs:
1918
- generate-matrix
20-
runs-on: depot-macos-latest
19+
runs-on: ${{ matrix.runner }}
20+
strategy:
21+
matrix: ${{ fromJson(needs.generate-matrix.outputs.crate-build-matrix) }}
22+
fail-fast: false
23+
name: crate / ${{ matrix.arch }}
2124
steps:
2225
- uses: actions/checkout@v4
2326

@@ -40,15 +43,15 @@ jobs:
4043
- name: Upload pythonbuild Executable
4144
uses: actions/upload-artifact@v4
4245
with:
43-
name: pythonbuild
46+
name: ${{ matrix.crate_artifact_name }}
4447
path: target/release/pythonbuild
4548

4649
generate-matrix:
4750
runs-on: ubuntu-latest
4851
outputs:
4952
matrix: ${{ steps.set-matrix.outputs.matrix }}
53+
crate-build-matrix: ${{ steps.set-matrix.outputs.crate-build-matrix }}
5054
any_builds: ${{ steps.set-matrix.outputs.any_builds }}
51-
pythonbuild_changed: ${{ steps.check-pythonbuild.outputs.changed }}
5255
steps:
5356
- uses: actions/checkout@v4
5457
with:
@@ -64,13 +67,26 @@ jobs:
6467
LABELS=$(echo '${{ toJson(github.event.pull_request.labels.*.name) }}' | jq -r 'join(",")')
6568
echo "labels=$LABELS" >> $GITHUB_OUTPUT
6669
70+
- name: Check if the `pythonbuild` crate changed
71+
id: check-pythonbuild
72+
env:
73+
BASE_REF: ${{ github.event.pull_request.base.ref || 'main' }}
74+
run: |
75+
merge_base=$(git merge-base HEAD "origin/${BASE_REF}")
76+
if git diff --quiet "${merge_base}...HEAD" -- ':src/*.rs'; then
77+
echo "changed=false" >> "$GITHUB_OUTPUT"
78+
else
79+
echo "changed=true" >> "$GITHUB_OUTPUT"
80+
fi
81+
6782
- name: Generate build matrix
6883
id: set-matrix
6984
run: |
70-
uv run ci-matrix.py --platform darwin --labels '${{ steps.get-labels.outputs.labels }}' > matrix.json
85+
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
7186
7287
# Extract python-build matrix
7388
echo "matrix=$(jq -c '."python-build"' matrix.json)" >> $GITHUB_OUTPUT
89+
echo "crate-build-matrix=$(jq -c '."crate-build"' matrix.json)" >> $GITHUB_OUTPUT
7490
7591
# Display the matrix for debugging too
7692
cat matrix.json | jq
@@ -83,22 +99,10 @@ jobs:
8399
echo "any_builds=false" >> $GITHUB_OUTPUT
84100
fi
85101
86-
- name: Check if the `pythonbuild` crate changed
87-
id: check-pythonbuild
88-
env:
89-
BASE_REF: ${{ github.event.pull_request.base.ref || 'main' }}
90-
run: |
91-
merge_base=$(git merge-base HEAD "origin/${BASE_REF}")
92-
if git diff --quiet "${merge_base}...HEAD" -- ':src/*.rs'; then
93-
echo "changed=false" >> "$GITHUB_OUTPUT"
94-
else
95-
echo "changed=true" >> "$GITHUB_OUTPUT"
96-
fi
97-
98102
build:
99103
needs:
100104
- generate-matrix
101-
- pythonbuild
105+
- crate-build
102106
# Permissions used for actions/attest-build-provenance
103107
permissions:
104108
id-token: write
@@ -121,7 +125,7 @@ jobs:
121125
- name: Download pythonbuild
122126
uses: actions/download-artifact@v4
123127
with:
124-
name: pythonbuild
128+
name: ${{ matrix.crate_artifact_name }}
125129
path: build
126130

127131
- name: Build

.github/workflows/windows.yml

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ env:
1313
FORCE_COLOR: 1
1414

1515
jobs:
16-
pythonbuild:
17-
if: ${{ needs.generate-matrix.outputs.pythonbuild_changed == 'true' || needs.generate-matrix.outputs.any_builds == 'true' || github.ref == 'refs/heads/main' }}
16+
crate-build:
1817
needs:
1918
- generate-matrix
20-
runs-on: 'windows-2022'
19+
runs-on: ${{ matrix.runner }}
20+
strategy:
21+
matrix: ${{ fromJson(needs.generate-matrix.outputs.crate-build-matrix) }}
22+
fail-fast: false
23+
name: crate / ${{ matrix.arch }}
2124
steps:
2225
- uses: actions/checkout@v4
2326

@@ -40,15 +43,15 @@ jobs:
4043
- name: Upload executable
4144
uses: actions/upload-artifact@v4
4245
with:
43-
name: pythonbuild
46+
name: ${{ matrix.crate_artifact_name }}
4447
path: target/release/pythonbuild.exe
4548

4649
generate-matrix:
4750
runs-on: ubuntu-latest
4851
outputs:
4952
matrix: ${{ steps.set-matrix.outputs.matrix }}
53+
crate-build-matrix: ${{ steps.set-matrix.outputs.crate-build-matrix }}
5054
any_builds: ${{ steps.set-matrix.outputs.any_builds }}
51-
pythonbuild_changed: ${{ steps.check-pythonbuild.outputs.changed }}
5255
steps:
5356
- uses: actions/checkout@v4
5457
with:
@@ -64,13 +67,26 @@ jobs:
6467
LABELS=$(echo '${{ toJson(github.event.pull_request.labels.*.name) }}' | jq -r 'join(",")')
6568
echo "labels=$LABELS" >> $GITHUB_OUTPUT
6669
70+
- name: Check if the `pythonbuild` crate changed
71+
id: check-pythonbuild
72+
env:
73+
BASE_REF: ${{ github.event.pull_request.base.ref || 'main' }}
74+
run: |
75+
merge_base=$(git merge-base HEAD "origin/${BASE_REF}")
76+
if git diff --quiet "${merge_base}...HEAD" -- ':src/*.rs'; then
77+
echo "changed=false" >> "$GITHUB_OUTPUT"
78+
else
79+
echo "changed=true" >> "$GITHUB_OUTPUT"
80+
fi
81+
6782
- name: Generate build matrix
6883
id: set-matrix
6984
run: |
70-
uv run ci-matrix.py --platform windows --labels '${{ steps.get-labels.outputs.labels }}' > matrix.json
85+
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
7186
7287
# Extract python-build matrix
7388
echo "matrix=$(jq -c '."python-build"' matrix.json)" >> $GITHUB_OUTPUT
89+
echo "crate-build-matrix=$(jq -c '."crate-build"' matrix.json)" >> $GITHUB_OUTPUT
7490
7591
# Display the matrix for debugging too
7692
cat matrix.json | jq
@@ -83,23 +99,11 @@ jobs:
8399
echo "any_builds=false" >> $GITHUB_OUTPUT
84100
fi
85101
86-
- name: Check if the `pythonbuild` crate changed
87-
id: check-pythonbuild
88-
env:
89-
BASE_REF: ${{ github.event.pull_request.base.ref || 'main' }}
90-
run: |
91-
merge_base=$(git merge-base HEAD "origin/${BASE_REF}")
92-
if git diff --quiet "${merge_base}...HEAD" -- ':src/*.rs'; then
93-
echo "changed=false" >> "$GITHUB_OUTPUT"
94-
else
95-
echo "changed=true" >> "$GITHUB_OUTPUT"
96-
fi
97-
98102
build:
99103
timeout-minutes: 60
100104
needs:
101105
- generate-matrix
102-
- pythonbuild
106+
- crate-build
103107
# Permissions used for actions/attest-build-provenance
104108
permissions:
105109
id-token: write
@@ -127,7 +131,7 @@ jobs:
127131
- name: Download pythonbuild Executable
128132
uses: actions/download-artifact@v4
129133
with:
130-
name: pythonbuild
134+
name: ${{ matrix.crate_artifact_name }}
131135

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

0 commit comments

Comments
 (0)