Skip to content

Commit 86c5a29

Browse files
committed
refactor(ci): only test for relevant passing builds
1 parent 37f8d3c commit 86c5a29

File tree

1 file changed

+63
-12
lines changed

1 file changed

+63
-12
lines changed

.github/workflows/ci.yml

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ jobs:
5252
- name: Generate Matrix
5353
id: generate-matrix
5454
run: |
55-
systems=("x86_64-linux" "aarch64-linux" "x86_64-windows" "aarch64-windows" "x86_64-darwin" "aarch64-darwin")
56-
5755
if [ "${{ steps.check-root-changes.outputs.rebuild_all }}" == true ]; then
5856
crates=$(find crates -mindepth 1 -maxdepth 1 -type d -exec basename {} \;)
5957
else
@@ -77,18 +75,13 @@ jobs:
7775
echo "Default Members: $default_members"
7876
echo "Crates to Build: $crates"
7977
80-
matrix="{\"system\": ["
81-
for system in "${systems[@]}"; do
82-
matrix+="\"$system\","
83-
done
84-
matrix="${matrix::-1}],\"crate\": ["
78+
matrix='{"system": ["x86_64-linux","aarch64-linux","x86_64-windows","aarch64-windows","x86_64-darwin","aarch64-darwin"],"crate": ['
8579
for crate in $crates; do
8680
matrix+="\"$crate\","
8781
done
8882
matrix="${matrix::-1}]}"
8983
9084
echo "$matrix" | jq .
91-
9285
echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
9386
9487
build-artifacts:
@@ -114,17 +107,75 @@ jobs:
114107
- run: nix build .#${{ matrix.crate }}-${{ matrix.system }}-dev -L --accept-flake-config
115108

116109
- uses: actions/[email protected]
117-
if: ${{ contains(needs.get-changes.outputs.binaries, matrix.crate) && !env.ACT }}
110+
if: ${{ contains(needs.get-changes.outputs.binaries, matrix.crate) }}
118111
with:
119112
name: ${{ matrix.crate }}-${{ matrix.system }}
120113
path: result/bin/
121114
if-no-files-found: error
122115

123-
run-tests:
116+
- run: touch "build-success-${{ matrix.crate }}-${{ matrix.system }}"
117+
- uses: actions/upload-artifact@v4
118+
with:
119+
name: build-success-${{ matrix.crate }}-${{ matrix.system }}
120+
path: build-success-${{ matrix.crate }}-${{ matrix.system }}
121+
122+
determine-tests:
124123
needs: [ get-changes, build-artifacts ]
124+
if: ${{ needs.get-changes.outputs.matrix != '{}' && always() }}
125+
runs-on: ubuntu-latest
126+
outputs:
127+
test-matrix: ${{ steps.get-test-matrix.outputs.matrix }}
128+
steps:
129+
- uses: actions/download-artifact@v4
130+
with:
131+
pattern: build-success-*
132+
133+
- name: Get Test Matrix
134+
id: get-test-matrix
135+
shell: bash
136+
run: |
137+
crate_systems=$(echo '${{ needs.get-changes.outputs.matrix }}' | jq -r '.crate[] as $crate | .system[] as $system | "\($crate)-\($system)"')
138+
139+
build_success_files=$(find . -maxdepth 2 -type f -name "build-success-*" -exec basename {} \;)
140+
echo "Build Success Files: $build_success_files"
141+
142+
declare -a found_artifacts=()
143+
for crate_system in $crate_systems; do
144+
echo "Checking for build-success-$crate_system"
145+
if [[ ${build_success_files[*]} =~ build-success-$crate_system ]]; then
146+
echo "Found build-success-$crate_system"
147+
found_artifacts+=("$crate_system")
148+
fi
149+
done
150+
151+
if [ ${#found_artifacts[@]} = 0 ]; then
152+
echo "No artifacts found."
153+
echo "matrix={}" >> "$GITHUB_OUTPUT"
154+
exit 0
155+
fi
156+
157+
matrix='{"system": ["x86_64-linux","aarch64-linux","x86_64-windows","aarch64-windows","x86_64-darwin","aarch64-darwin"], "crate": ['
158+
for crate_system in "${found_artifacts[@]}"; do
159+
crate="${crate_system%-*}"
160+
matrix+="\"$crate\","
161+
done
162+
matrix="${matrix::-1}]}"
163+
164+
echo "$matrix" | jq .
165+
echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
166+
167+
# We always want to cleanup the matrix artifacts.
168+
- uses: geekyeggo/delete-artifact@v5
169+
if: ${{ always() }}
170+
with:
171+
name: build-success-*
172+
173+
run-tests:
174+
needs: [ determine-tests ]
175+
if: ${{ needs.determine-tests.outputs.test-matrix != '{}' }}
125176
strategy:
126177
fail-fast: false
127-
matrix: ${{ fromJson(needs.get-changes.outputs.matrix) }}
178+
matrix: ${{ fromJson(needs.determine-tests.outputs.test-matrix) }}
128179
runs-on: ${{ endsWith(matrix.system, 'darwin') && 'macos-latest' || 'ubuntu-latest' }}
129180
name: Run Tests for ${{ matrix.crate }} on ${{ matrix.system }}
130181
steps:
@@ -142,7 +193,7 @@ jobs:
142193
echo "run_tests=false" >> "$GITHUB_OUTPUT"
143194
fi
144195
145-
# We only want to run native tests on the runner that matches the host system.
196+
# We only want to run native tests on the runner that matches the host system, no cross-architecture testing.
146197
host_system=$(nix eval --raw nixpkgs#system)
147198
if [[ "$matrix_system" == "$host_system" ]]; then
148199
echo "run_tests=true" >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)