diff --git a/.github/workflows/storybook-audit.yml b/.github/workflows/storybook-audit.yml new file mode 100644 index 000000000..794382fd0 --- /dev/null +++ b/.github/workflows/storybook-audit.yml @@ -0,0 +1,53 @@ +# Storybook audit: build static Storybook, serve it, run the audit script. +# Fails the job if any story has console errors, page errors, or unhandled network failures. +# See docs/STORYBOOK_CONTRACT.md and apps/web/scripts/audit-storybook.js. +name: Storybook Audit + +on: + push: + paths: + - "apps/web/**" + - ".github/workflows/storybook-audit.yml" + pull_request: + paths: + - "apps/web/**" + - ".github/workflows/storybook-audit.yml" + workflow_dispatch: + +jobs: + audit: + name: Build & audit Storybook + runs-on: ubuntu-latest + defaults: + run: + working-directory: apps/web + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Node + uses: actions/setup-node@v4 + with: + node-version: "20" + cache: "npm" + cache-dependency-path: apps/web/package-lock.json + + - name: Install dependencies + run: npm ci + + - name: Build Storybook + run: npm run build-storybook + env: + VITE_API_URL: /api/v1 + VITE_USE_MSW: "true" + VITE_STORYBOOK: "true" + + - name: Install Playwright Chromium + run: npx playwright install chromium --with-deps + + - name: Serve Storybook and run audit + run: | + npx serve -s storybook-static -p 6007 & + sleep 5 + node scripts/audit-storybook.js diff --git a/apps/web/scripts/audit-storybook.js b/apps/web/scripts/audit-storybook.js index cb68b05f4..eac55e246 100644 --- a/apps/web/scripts/audit-storybook.js +++ b/apps/web/scripts/audit-storybook.js @@ -144,6 +144,13 @@ async function audit() { console.log(`Detailed report saved to: ${outputPath}`); await browser.close(); + + if (report.metadata.storiesWithErrors > 0 || report.metadata.totalErrors > 0) { + process.exit(1); + } } -audit().catch(e => console.error("Top level error:", e)); +audit().catch(e => { + console.error("Top level error:", e); + process.exit(1); +});