Skip to content

Commit b3e8533

Browse files
committed
Add checks for previous runs
Should minimize the cases where we re-run tests which have already passed for an existing commit.
1 parent 9c697ab commit b3e8533

File tree

1 file changed

+77
-1
lines changed

1 file changed

+77
-1
lines changed

.github/workflows/tests.yml

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,39 @@ on:
66
workflow_dispatch:
77

88
jobs:
9+
check-previous-run:
10+
name: Check for previous successful run
11+
runs-on: ubuntu-latest
12+
outputs:
13+
should_skip: ${{ steps.check.outputs.should_skip }}
14+
steps:
15+
- name: Check if commit was already tested
16+
id: check
17+
env:
18+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19+
run: |
20+
echo "Current commit: ${{ github.sha }}"
21+
echo "Current ref: ${{ github.ref }}"
22+
23+
# Check if there's a previous successful workflow run for this exact commit
24+
PREVIOUS_RUN=$(gh api \
25+
-H "Accept: application/vnd.github+json" \
26+
"/repos/${{ github.repository }}/actions/workflows/tests.yml/runs?status=success&per_page=5" \
27+
--jq '.workflow_runs[] | select(.head_sha == "${{ github.sha }}") | .id' \
28+
| head -n 1)
29+
30+
if [ -n "$PREVIOUS_RUN" ] && [ "$PREVIOUS_RUN" != "${{ github.run_id }}" ]; then
31+
echo "Found previous successful run: $PREVIOUS_RUN"
32+
echo "should_skip=true" >> $GITHUB_OUTPUT
33+
else
34+
echo "No previous successful run found for this commit"
35+
echo "should_skip=false" >> $GITHUB_OUTPUT
36+
fi
37+
938
test-aarch64:
1039
name: Test aarch64
40+
needs: check-previous-run
41+
if: needs.check-previous-run.outputs.should_skip != 'true'
1142
strategy:
1243
matrix:
1344
os: [ubuntu-22.04-arm, ubuntu-24.04-arm, macos-14, macos-15, macos-26, macos-latest, windows-11-arm]
@@ -38,6 +69,8 @@ jobs:
3869

3970
test-x86_64:
4071
name: Test x86_64
72+
needs: check-previous-run
73+
if: needs.check-previous-run.outputs.should_skip != 'true'
4174
strategy:
4275
matrix:
4376
os: [ ubuntu-latest, ubuntu-22.04, ubuntu-24.04, macos-15-intel, windows-2022, windows-2025, windows-latest ]
@@ -69,6 +102,8 @@ jobs:
69102

70103
test-x86-linux:
71104
name: Test x86 Linux
105+
needs: check-previous-run
106+
if: needs.check-previous-run.outputs.should_skip != 'true'
72107
runs-on: ubuntu-latest
73108
strategy:
74109
matrix:
@@ -94,6 +129,8 @@ jobs:
94129

95130
test-x86-windows:
96131
name: Test x86 Windows
132+
needs: check-previous-run
133+
if: needs.check-previous-run.outputs.should_skip != 'true'
97134
runs-on: windows-2022
98135
strategy:
99136
matrix:
@@ -124,6 +161,8 @@ jobs:
124161

125162
test-software:
126163
name: Test software fallback
164+
needs: check-previous-run
165+
if: needs.check-previous-run.outputs.should_skip != 'true'
127166
runs-on: ubuntu-latest
128167
strategy:
129168
matrix:
@@ -149,7 +188,8 @@ jobs:
149188

150189
miri-test-x86_64:
151190
name: Miri Test x86_64
152-
needs: test-x86_64
191+
needs: [check-previous-run, test-x86_64]
192+
if: needs.check-previous-run.outputs.should_skip != 'true'
153193
runs-on: ubuntu-24.04
154194
steps:
155195
- uses: actions/checkout@v4
@@ -177,6 +217,8 @@ jobs:
177217

178218
test-no-std:
179219
name: Test no_std
220+
needs: check-previous-run
221+
if: needs.check-previous-run.outputs.should_skip != 'true'
180222
runs-on: ubuntu-latest
181223
strategy:
182224
matrix:
@@ -207,6 +249,8 @@ jobs:
207249

208250
test-wasm:
209251
name: Test WASM
252+
needs: check-previous-run
253+
if: needs.check-previous-run.outputs.should_skip != 'true'
210254
runs-on: ubuntu-latest
211255
strategy:
212256
matrix:
@@ -253,3 +297,35 @@ jobs:
253297
- if: ${{ matrix.target == 'wasm32-unknown-unknown' && matrix.rust-toolchain == 'stable' }}
254298
name: Build WASM package with wasm-pack
255299
run: wasm-pack build --target web --no-default-features --features alloc,panic-handler
300+
301+
tests-complete:
302+
name: All tests complete
303+
needs: [check-previous-run, test-aarch64, test-x86_64, test-x86-linux, test-x86-windows, test-software, miri-test-x86_64, test-no-std, test-wasm]
304+
if: always()
305+
runs-on: ubuntu-latest
306+
steps:
307+
- name: Check test results
308+
run: |
309+
echo "Checking test results..."
310+
echo "Previous run check: ${{ needs.check-previous-run.result }}"
311+
echo "Should skip: ${{ needs.check-previous-run.outputs.should_skip }}"
312+
313+
if [ "${{ needs.check-previous-run.outputs.should_skip }}" == "true" ]; then
314+
echo "✓ Tests were skipped because this commit was already tested successfully"
315+
exit 0
316+
fi
317+
318+
# Check if any test job failed
319+
if [ "${{ needs.test-aarch64.result }}" == "failure" ] || \
320+
[ "${{ needs.test-x86_64.result }}" == "failure" ] || \
321+
[ "${{ needs.test-x86-linux.result }}" == "failure" ] || \
322+
[ "${{ needs.test-x86-windows.result }}" == "failure" ] || \
323+
[ "${{ needs.test-software.result }}" == "failure" ] || \
324+
[ "${{ needs.miri-test-x86_64.result }}" == "failure" ] || \
325+
[ "${{ needs.test-no-std.result }}" == "failure" ] || \
326+
[ "${{ needs.test-wasm.result }}" == "failure" ]; then
327+
echo "✗ One or more test jobs failed"
328+
exit 1
329+
fi
330+
331+
echo "✓ All test jobs passed"

0 commit comments

Comments
 (0)