Skip to content
Draft
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
23 changes: 18 additions & 5 deletions .github/workflows/windows-scoped-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ name: Windows Scoped Tests
# red Windows job blocks the pull request it runs on: in a pull request that
# touches path, file-name or process code, a changed curated test file has to
# pass on Windows. A change to path or process code with no changed curated
# test selects nothing; the nightly suite covers it.
# test selects nothing; the nightly suite covers it. A large selection (an
# upstream sync, CHE-9815) is dealt into up to 10 Windows jobs; none is skipped.
# gstack-pregate reads a job keyed on a dispatch input as manual, never a PR
# obligation: this check runs on the pull request itself. A workflow_dispatch
# run with the files input reruns chosen Windows-safe files on a branch.
Expand Down Expand Up @@ -93,6 +94,7 @@ jobs:
timeout-minutes: 5
outputs:
files: ${{ steps.select.outputs.files }}
matrix: ${{ steps.select.outputs.matrix }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
if: github.event_name == 'pull_request'
Expand Down Expand Up @@ -139,14 +141,25 @@ jobs:
echo 'No changed test file is in the curated Windows-safe subset, so no Windows job runs.' >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
# CHE-9815: one windows-latest job runs 4 shards with a 360s deadline each; 113 files (an upstream sync) timed out every shard.
# Every selected file still runs: they are dealt round-robin into ceil(n/20) Windows jobs, at most 10 (the nightly's job count).
n=$(wc -l < "$RUNNER_TEMP/selected" | tr -d ' ')
jobs=$(( (n + 19) / 20 ))
[ "$jobs" -gt 10 ] && jobs=10
matrix=$(jq -R -s -c --argjson k "$jobs" 'split("\n") | map(select(length > 0)) as $f | {include: [range(0; $k) as $g | {group: ($g + 1), files: ([$f | to_entries[] | select(.key % $k == $g) | .value] | join("\n"))}]}' "$RUNNER_TEMP/selected")
echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
{ echo 'files<<GSTACK_SCOPED_FILES'; cat "$RUNNER_TEMP/selected"; echo 'GSTACK_SCOPED_FILES'; } >> "$GITHUB_OUTPUT"
{ echo "The Windows job runs $(wc -l < "$RUNNER_TEMP/selected" | tr -d ' ') changed Windows-safe test file(s):"; sed 's/^/- /' "$RUNNER_TEMP/selected"; } >> "$GITHUB_STEP_SUMMARY"
{ echo "The Windows job runs $n changed Windows-safe test file(s) in $jobs job(s):"; sed 's/^/- /' "$RUNNER_TEMP/selected"; } >> "$GITHUB_STEP_SUMMARY"

windows-scoped-shard:
needs: windows-scope
if: ${{ (github.event_name == 'workflow_dispatch' && inputs.files != '') || needs.windows-scope.outputs.files != '' }}
runs-on: windows-latest
timeout-minutes: 20
# CHE-9815: one job per group of selected files; a workflow_dispatch run has no matrix output and runs its input as one group.
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.windows-scope.outputs.matrix || '{"include":[{"group":1,"files":""}]}') }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
Expand Down Expand Up @@ -185,7 +198,7 @@ jobs:

- name: Run the scoped Windows-safe test files
env:
FILES: ${{ inputs.files || needs.windows-scope.outputs.files }}
FILES: ${{ inputs.files || matrix.files }}
GSTACK_FREE_RETRY_FLAKY: '1'
GSTACK_FLAKE_LEDGER: ${{ runner.temp }}/flake-ledger.jsonl
TEMP: ${{ runner.temp }}
Expand All @@ -200,7 +213,7 @@ jobs:
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: windows-scoped-test-logs
name: windows-scoped-test-logs-${{ matrix.group }}
path: |
.context/free-test-logs/gstack-free-test-*.log
${{ runner.temp }}/gstack-free-test-*.log
Expand All @@ -211,7 +224,7 @@ jobs:
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: flake-ledger-windows-scoped
name: flake-ledger-windows-scoped-${{ matrix.group }}
path: ${{ runner.temp }}/flake-ledger.jsonl
if-no-files-found: ignore
retention-days: 90
Expand Down
27 changes: 26 additions & 1 deletion test/windows-path-scope-workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ describe('the path-scoped Windows shard on pull requests', () => {
expect(shard.needs).toBe('windows-scope');
expect(shard.steps[0].with).toEqual({ 'persist-credentials': false });
const run = shard.steps.find((s: any) => s.name === 'Run the scoped Windows-safe test files');
expect(run.env.FILES).toBe('${{ inputs.files || needs.windows-scope.outputs.files }}');
expect(run.env.FILES).toBe('${{ inputs.files || matrix.files }}');
expect(run.env.GSTACK_FREE_RETRY_FLAKY).toBe('1');
expect(run.run).toContain('bun run scripts/test-free-shards.ts --files-from "$RUNNER_TEMP/windows-scoped-files.txt"');
expect(scoped.jobs['windows-scoped-tests'].needs).toEqual(['windows-scope', 'windows-scoped-shard']);
Expand Down Expand Up @@ -256,6 +256,31 @@ describe('the path-scoped Windows shard on pull requests', () => {
expect(select.outputs.files).toBe('test/hook-scripts.test.ts');
}, 60_000);

test.skipIf(!CAN_SELECT)('CHE-9815: a large change (an upstream sync) runs every selected test, dealt into at most 10 Windows jobs', () => {
const select = (count: number) => {
const many = Array.from({ length: count }, (_, i) => `test/sync-${i}.test.ts`);
const temp = newTemp();
const bin = path.join(temp, 'bin');
fs.mkdirSync(bin);
fs.writeFileSync(path.join(bin, 'bun'), '#!/bin/sh\nwhile [ $# -gt 0 ]; do [ "$1" = --ci-plan ] && printf \'%s\' "$PLAN_JSON" > "$2"; shift; done\n', { mode: 0o755 });
fs.writeFileSync(path.join(temp, 'changed-files'), many.join('\n') + '\n');
const plan = JSON.stringify({ version: 1, revision: 'r', shards: [{ shard: 1, predictedMs: 1, files: many }], id: 'x' });
const r = runStep(selectScript, ROOT, { PATH: `${toShell(bin)}:${process.env.PATH}`, PLAN_JSON: plan }, temp);
expect(r.status, r.stderr).toBe(0);
const groups = (JSON.parse(r.outputs.matrix!) as { include: { group: number; files: string }[] }).include;
// Nothing is skipped: the groups together hold exactly the selected files, and each runs as its own job.
expect(groups.flatMap(g => g.files.split('\n')).sort()).toEqual([...many].sort());
expect(r.outputs.files?.split('\n')).toHaveLength(count);
return groups;
};
expect(select(20)).toHaveLength(1);
expect(select(21)).toHaveLength(2);
const sync = select(113);
expect(sync).toHaveLength(6);
expect(Math.max(...sync.map(g => g.files.split('\n').length))).toBeLessThanOrEqual(19);
expect(select(500)).toHaveLength(10);
});

test.skipIf(!CAN_SELECT)('#3758: the hook paths put it in scope and the Windows job runs test/hook-scripts.test.ts', () => {
const dir = prRepo(PR_3758);
try {
Expand Down
Loading