Skip to content

Commit 481cb7f

Browse files
authored
docs: recommend computing splits once for consistent re-runs (#3)
Update Quick Start to show the recommended pattern of computing splits in a dedicated job and passing to test jobs via outputs. This ensures that re-running a failed job runs the same tests, since GitHub Actions preserves workflow outputs on re-runs.
2 parents c94e522 + 0842c19 commit 481cb7f

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

README.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ Fairsplice is a CLI tool and GitHub Action that optimizes test distribution acro
44

55
## Quick Start (GitHub Action)
66

7+
**Recommended:** Compute splits once and pass to test jobs. This ensures re-running a failed job runs the same tests.
8+
79
```yaml
810
jobs:
9-
test:
11+
# Compute splits once - ensures consistent re-runs
12+
compute-splits:
1013
runs-on: ubuntu-latest
11-
strategy:
12-
matrix:
13-
index: [0, 1, 2]
14+
outputs:
15+
test-buckets: ${{ steps.split.outputs.buckets }}
1416
steps:
1517
- uses: actions/checkout@v4
1618

@@ -21,8 +23,22 @@ jobs:
2123
command: split
2224
pattern: 'tests/**/*.py'
2325
total: 3
24-
index: ${{ matrix.index }}
2526
cache-key: python-tests
27+
# No index = outputs all buckets as JSON array
28+
29+
test:
30+
needs: compute-splits
31+
runs-on: ubuntu-latest
32+
strategy:
33+
matrix:
34+
index: [0, 1, 2]
35+
steps:
36+
- uses: actions/checkout@v4
37+
38+
- name: Get test files
39+
id: split
40+
run: |
41+
echo "tests=$(echo '${{ needs.compute-splits.outputs.test-buckets }}' | jq -r '.[${{ matrix.index }}] | join(" ")')" >> "$GITHUB_OUTPUT"
2642
2743
- name: Run tests
2844
run: pytest ${{ steps.split.outputs.tests }} --junit-xml=junit.xml
@@ -57,6 +73,15 @@ jobs:
5773
5874
That's it! Caching is handled automatically.
5975
76+
### Why compute splits once?
77+
78+
When you compute splits inside each matrix job (using `index`), re-running a failed job can run different tests:
79+
1. Other jobs may have updated the timing cache
80+
2. The re-run computes a new split with updated timings
81+
3. The failed test might now be assigned to a different worker
82+
83+
By computing splits once in a dedicated job and passing via workflow outputs, GitHub Actions preserves the same split on re-runs.
84+
6085
## How It Works
6186

6287
```

0 commit comments

Comments
 (0)