Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

ci: an out-of-scope run still writes its dependent-audit record (#10687)

Cindy Zhang394edfe16810
diff --git a/.github/scripts/a11y-dependent-audits.test.mjs b/.github/scripts/a11y-dependent-audits.test.mjs
index f84eaf525c..43e1b10b30 100644
--- a/.github/scripts/a11y-dependent-audits.test.mjs
+++ b/.github/scripts/a11y-dependent-audits.test.mjs
@@ -358,7 +358,47 @@ describe('the dependent-audits jobs', () => {
expect(planJob.outputs.complete).toBe(
"${{ steps.plan.outputs.complete || 'true' }}",
);
+ // A run out of scope still writes a record that owes nothing.
+ const skip = step(planJob, 'Skip the dependent audits outside their scope');
+ expect(skip.run).toContain(
+ '"owed": [], "ran": [], "deferred": [], "complete": true',
+ );
+ expect(skip.run).toContain('> "$RUNNER_TEMP/a11y-dependent-audits.json"');
+ // It names the same fields as the planner's own record for a decided scope.
+ const template = /printf '(\{.*\})\\n'/.exec(skip.run)[1];
+ const outOfScope = JSON.parse(
+ template.replace('"%s"', '"head"').replace('%s', '1'),
+ );
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'dependent-record-'));
+ try {
+ fs.writeFileSync(path.join(dir, 'changed.txt'), 'README.md\n');
+ execFileSync(
+ process.execPath,
+ [
+ '.github/scripts/a11y-dependent-audits.mjs',
+ '--changed',
+ path.join(dir, 'changed.txt'),
+ '--out',
+ path.join(dir, 'record.json'),
+ ],
+ {
+ cwd: root,
+ env: {...process.env, GITHUB_OUTPUT: '', GITHUB_STEP_SUMMARY: ''},
+ },
+ );
+ const planned = JSON.parse(
+ fs.readFileSync(path.join(dir, 'record.json'), 'utf8'),
+ );
+ expect(Object.keys(outOfScope).sort()).toEqual(
+ Object.keys(planned).sort(),
+ );
+ } finally {
+ fs.rmSync(dir, {recursive: true, force: true});
+ }
const upload = step(planJob, 'Upload the dependent-audit record');
+ // Every run uploads a record, and a run without one fails in CI.
+ expect(upload.if).toBe('always()');
+ expect(upload.with['if-no-files-found']).toBe('error');
expect(upload.with.name).toBe(
'a11y-dependent-audits-record-${{ github.run_attempt }}',
);
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 6681ae9585..b30881e3a6 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -4663,9 +4663,17 @@ jobs:
outside-pull-request: skip
component-audit: 'true'
+ # Out of scope the run still writes its record, so merge-guard reads
+ # "nothing owed" rather than a missing record.
- name: Skip the dependent audits outside their scope
if: steps.scope.outputs.applies != 'true'
- run: echo "No package source changed; no dependent audit to run."
+ env:
+ ASTRYX_HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
+ RUN_ATTEMPT: ${{ github.run_attempt }}
+ run: |
+ echo "No package source changed; no dependent audit to run."
+ printf '{"head": "%s", "attempt": %s, "owed": [], "ran": [], "deferred": [], "complete": true}\n' \
+ "$ASTRYX_HEAD_SHA" "$RUN_ATTEMPT" > "$RUNNER_TEMP/a11y-dependent-audits.json"
# The planner, the primitive list, the import graph and the recorded
# times all come from the merge commit.
@@ -4707,13 +4715,16 @@ jobs:
fi
node .github/scripts/a11y-dependent-audits.mjs "${changes[@]}" --out "$RUNNER_TEMP/a11y-dependent-audits.json" --attempt "$RUN_ATTEMPT"
+ # Every run of this job uploads its record. A run that planned audits
+ # but wrote no record fails here, not later at the merge.
- name: Upload the dependent-audit record
- if: steps.plan.outcome == 'success'
+ if: always()
uses: actions/upload-artifact@v7
with:
# One record per attempt: merge-guard reads the latest attempt's.
name: a11y-dependent-audits-record-${{ github.run_attempt }}
path: ${{ runner.temp }}/a11y-dependent-audits.json
+ if-no-files-found: error
retention-days: 30
# Each leg runs its share of the plan at the head that built the Storybook.