#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
TypeScript dockerhacktoberfestjavapdfpdf-converterpdf-editorpdf-manipulationpdf-mergerpdf-ocrpdf-toolspdf-web-appspdfmergerself-hosted
Shard a11y nightlies (#8573)
James Brunton9f267e8b0620
diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.ymlindex 3b4a0d9d7f..03e4659476 100644--- a/.github/workflows/nightly.yml+++ b/.github/workflows/nightly.yml@@ -35,9 +35,11 @@ jobs:fail-fast: falsematrix:theme: [light, dark]+ # One slice of the story set per entry, each on its own runner; add an+ # entry when the slowest leg passes about 15 minutes.+ shard: ["1/4", "2/4", "3/4", "4/4"]runs-on: ubuntu-latest- # One full sweep (~30 minutes of browser time).- timeout-minutes: 60+ timeout-minutes: 30steps:- name: Harden the runner (Audit all outbound calls)uses: step-security/harden-runner@ccd8616d44fd3846e67624a50d5aad6d37bf2d25 # v2.22.1@@ -59,14 +61,15 @@ jobs:with:version: 3.54.0- - name: a11y gate (every story, ${{ matrix.theme }})- run: task frontend:storybook:a11y:${{ matrix.theme }}+ - name: a11y gate (every story, ${{ matrix.theme }} ${{ matrix.shard }})+ run: task frontend:storybook:a11y:${{ matrix.theme }} -- --shard=${{ matrix.shard }}- name: Upload scan reportsif: always()uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2with:- name: a11y-scan-nightly-${{ matrix.theme }}-${{ github.run_id }}+ # job-index because `shard` holds a slash, which artifact names reject.+ name: a11y-scan-nightly-${{ matrix.theme }}-${{ strategy.job-index }}-${{ github.run_id }}path: frontend/.a11y-scan/retention-days: 14if-no-files-found: ignorediff --git a/frontend/.storybook/a11y-scan.mjs b/frontend/.storybook/a11y-scan.mjsindex 3e73705238..51054a9802 100644--- a/frontend/.storybook/a11y-scan.mjs+++ b/frontend/.storybook/a11y-scan.mjs@@ -5,6 +5,7 @@//// node a11y-scan.mjs scan every story// node a11y-scan.mjs <file> [file…] scan only these story files+// node a11y-scan.mjs --shard=<i>/<n> scan the i-th of n slices of either set//// Batching keeps each browser session small: a single run over the whole story// set holds one Chromium context open for the entire scan, so one crash in it@@ -40,13 +41,30 @@ mkdirSync(OUT, { recursive: true });const manifestFile = join(OUT, "manifest.txt");const logFile = join(OUT, "scan.log");+/** Parses `--shard=<index>/<count>`, 1-based like Playwright's. */+function parseShard(arg) {+ const m = /^--shard=(\d+)\/(\d+)$/.exec(arg);+ const index = Number(m?.[1]);+ const count = Number(m?.[2]);+ if (!m || index < 1 || index > count) {+ console.error(+ `a11y-scan: --shard expects <index>/<count>, e.g. --shard=2/4; got ${arg}`,+ );+ process.exit(2);+ }+ return { index, count };+}+const args = process.argv.slice(2);+const shardArg = args.find((a) => a.startsWith("--shard="));+const shard = shardArg ? parseShard(shardArg) : null;+const fileArgs = args.filter((a) => a !== shardArg);let files;-if (args.length > 0) {+if (fileArgs.length > 0) {// Explicit list (the pull-request path passes just the stories a branch// affects). Anything that no longer exists is dropped, so a deleted story// doesn't fail the manifest check.- files = [...new Set(args.filter((f) => existsSync(f)))].sort();+ files = [...new Set(fileArgs.filter((f) => existsSync(f)))].sort();if (files.length === 0) {console.log("a11y-scan: no existing story files in the given list — nothing to scan",@@ -75,7 +93,6 @@ if (args.length > 0) {process.exit(2);}}-writeFileSync(manifestFile, files.join("\n") + "\n");/** Failures carrying no axe rule — a throw, a timeout, a dropped browser page. */function crashCount(reportFile) {@@ -133,11 +150,27 @@ function runBatch(filters, outputFile) {const hasReport = (f) => existsSync(f) && statSync(f).size > 0;-const batches = [];+let batches = [];for (let i = 0; i < files.length; i += CHUNK)batches.push(files.slice(i, i + CHUNK));+if (shard) {+ // Whole batches, not files: every batch pays a full Vite + Chromium startup,+ // so cutting through one adds a partial batch to each shard.+ const edge = (k) => Math.floor((k * batches.length) / shard.count);+ batches = batches.slice(edge(shard.index - 1), edge(shard.index));+ files = batches.flat();+ if (files.length === 0) {+ console.log(+ `a11y-scan: shard ${shard.index}/${shard.count} has no batches - nothing to scan`,+ );+ writeFileSync(manifestFile, "");+ process.exit(0);+ }+}+writeFileSync(manifestFile, files.join("\n") + "\n");console.log(- `a11y-scan: ${files.length} story files, ${batches.length} batches of ${CHUNK}`,+ `a11y-scan: ${files.length} story files, ${batches.length} batches of ${CHUNK}` ++ (shard ? ` (shard ${shard.index}/${shard.count})` : ""),);const failed = [];