Skip to content
Closed
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
89 changes: 73 additions & 16 deletions .github/workflows/javascript-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,11 @@ jobs:
# checks packed consumers once per compiler (6 and 7), separately from `tooling`; the
# public-types check runs once per compiler in `published-artifact` (same build recipe),
# which also uploads the report, and `Build` waits for that job.
# `source`, `typescript-consumers`, and `storybook` build `@cratis/components` (and, for
# `source`, `typescript-consumers`, and `storybook-build` build `@cratis/components` (and, for
# the latter two, the adapters) before checks that need packed/dist output - mirroring
# what `run-task-on-workspaces.js ci` already did per workspace, and what every other job
# in this file already does in its own
# "Build the published artifact" step. Each of the three Storybook shards builds its own
# previews, then runs a deterministic partition of the story, manager, and viewport checks.
# in this file already does in its own "Build the published artifact" step. Storybook shards
# consume the producer's output, then run a deterministic partition of story, manager and viewport checks.
source:
needs: [changes]
if: needs.changes.outputs.relevant == 'true'
Expand Down Expand Up @@ -393,22 +392,17 @@ jobs:
yarn workspace @cratis/components.designsystemet run build
yarn verify-typescript-consumers --typescript ${{ matrix.typescript }} --skip-public-types

# The Storybook workspace is `private`, so `run-task-on-workspaces.js ci` always skipped
# it; its checks ran as their own steps at the end of the old `build` job instead, after
# that job's single step had already built `@cratis/components` and every adapter. This
# matrix rebuilds those same packages in each shard (build only, matching
# `typescript-consumers`) so each composed Storybook has the packed output it imports. All stories and auxiliary
# checks run exactly once across the three shards; preflight and index checks run in each.
storybook:
# Build and verify the composed Storybook once; transfer only its static output and prepared
# workspace exports. Consumers still verify indexes/isolation in run-story-matrix.mjs and run
# every story and auxiliary unit exactly once across the unchanged three-shard partition.
storybook-build:
needs: [changes]
if: needs.changes.outputs.relevant == 'true'
name: Storybook (shard ${{ matrix.shard }}/3)
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3]
name: Build Storybook
runs-on: ubuntu-latest
timeout-minutes: 25
permissions:
contents: read

steps:
- name: Checkout code
Expand Down Expand Up @@ -467,6 +461,68 @@ jobs:
working-directory: Source
run: yarn verify-storybook-index

- name: Archive prepared Storybook output
run: |
tar -czf "$RUNNER_TEMP/storybook-build.tar.gz" \
Source/storybook-static Source/dist Conformance/dist \
Adapters/Mui/dist Adapters/PrimeReact/dist \
Adapters/PrimeReact10/dist Adapters/Designsystemet/dist

- name: Upload prepared Storybook output
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: storybook-build-${{ github.sha }}
path: ${{ runner.temp }}/storybook-build.tar.gz
if-no-files-found: error
compression-level: 0
retention-days: 1

storybook:
needs: [changes, storybook-build]
if: needs.changes.outputs.relevant == 'true'
name: Storybook (shard ${{ matrix.shard }}/3)
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3]
runs-on: ubuntu-latest
timeout-minutes: 25
permissions:
contents: read

steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Setup node
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: 24.x
registry-url: 'https://registry.npmjs.org'

- name: Restore Yarn package cache
id: yarn-cache
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .yarn/cache
key: ${{ runner.os }}-yarn-cache-v3-${{ hashFiles('yarn.lock', '.yarnrc.yml', '.yarn/releases/yarn-4.17.1.cjs') }}
restore-keys: |
${{ runner.os }}-yarn-cache-v3-

- name: Yarn install
run: yarn install --immutable

- name: Download prepared Storybook output
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
with:
name: storybook-build-${{ github.sha }}
path: ${{ runner.temp }}/storybook-build

- name: Restore prepared Storybook output
run: tar -xzf "$RUNNER_TEMP/storybook-build/storybook-build.tar.gz"

- name: Cache Playwright browsers
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
Expand Down Expand Up @@ -561,6 +617,7 @@ jobs:
- tooling
- typescript-consumers
- published-artifact
- storybook-build
- storybook
- verify-arc-consumers
- verify-package-managers
Expand Down
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,18 @@ building, and each verification. Locally, export `NODE_OPTIONS="--max-old-space-
and time each script in that chain from the repository root with
`time yarn workspace @cratis/components run <script>`; do not also run `ci:static` in that sequence.

Each "Storybook (shard N/3)" job exposes the four preflight steps from "Verify renderer
Storybook inventory" through "Verify renderer Storybook peer isolation" before "Build composed
renderer Storybook". After building the packages that Storybook imports, reproduce the preflight
from `Storybook/` with `time yarn verify-inventory`, `time yarn typecheck`, `time yarn test`, and
The "Build Storybook" job builds the packages that Storybook imports, then exposes the four
preflight steps from "Verify renderer Storybook inventory" through "Verify renderer Storybook peer
isolation" before "Build composed renderer Storybook" and index/attestation verification. It uploads
one SHA-named artifact for this workflow run, retained for one day, containing only
`Source/storybook-static` and the prepared Source, Conformance, Mui, PrimeReact, PrimeReact10, and
Designsystemet `dist` directories. Each "Storybook (shard N/3)" job installs its own dependencies,
restores that artifact, and runs its unchanged assigned story, manager, and viewport units; missing
output fails rather than rebuilding. The matrix runner still checks peer isolation and indexes in
each shard, and `Build` requires both the producer and all three consumers.

Locally, after building the packages that Storybook imports, reproduce the preflight from
`Storybook/` with `time yarn verify-inventory`, `time yarn typecheck`, `time yarn test`, and
`time yarn verify-isolation`, in that order. "Install Storybook browser" and "Test assigned
Storybook units" remain separate steps for browser provisioning and story-test timings.

Expand Down
2 changes: 1 addition & 1 deletion scripts/javascript-build-gate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { fileURLToPath } from 'node:url';

export const expensiveJobs = Object.freeze([
'source', 'source-specs', 'adapters', 'tooling', 'typescript-consumers',
'published-artifact', 'storybook', 'verify-arc-consumers',
'published-artifact', 'storybook-build', 'storybook', 'verify-arc-consumers',
'verify-package-managers', 'verify-renderer-adapters', 'designsystemet-browser',
]);
export const maxGitOutput = 32 * 1024 * 1024;
Expand Down
97 changes: 91 additions & 6 deletions scripts/javascript-build-gate.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ test('Git exit, spawn, signal, timeout, overflow and partial-output failures nev

for (const mode of ['true', 'false']) {
test(`aggregate accepts only the complete intentional ${mode} truth-table row`, () => {
assert.match(aggregate(needsFixture(mode)), /^Verified 11 jobs:/);
assert.match(aggregate(needsFixture(mode)), /^Verified 12 jobs:/);
});
for (const job of expensiveJobs) {
test(`aggregate ${mode} rejects every inconsistent or missing result for ${job}`, () => {
Expand Down Expand Up @@ -291,11 +291,12 @@ test('workflow has unfiltered ordinary PRs and preserves the original push filte
`);
});

test('every one of the 11 expensive job groups is guarded and directly required by Build', () => {
assert.equal(expensiveJobs.length, 11);
test('every one of the 12 expensive job groups is guarded and directly required by Build', () => {
assert.equal(expensiveJobs.length, 12);
assert.deepEqual(Object.keys(jobs).sort(), ['changes', 'build', ...expensiveJobs].sort());
for (const job of expensiveJobs) {
assert.match(jobs[job], /^ needs: \[changes\]$/m);
const dependencies = job === 'storybook' ? 'changes, storybook-build' : 'changes';
assert.ok(jobs[job].includes(` needs: [${dependencies}]\n`), job);
assert.match(jobs[job], /^ if: needs.changes.outputs.relevant == 'true'$/m);
}
const needs = jobs.build.match(/ needs:\n((?: - [a-z-]+\n)+)/)?.[1];
Expand Down Expand Up @@ -390,7 +391,7 @@ test('the local Source ci:static chain remains identical to the visible CI phase
});

test('Storybook exposes each preflight phase once before the composed build', () => {
const steps = workflowSteps(jobs.storybook);
const steps = workflowSteps(jobs['storybook-build']);
const packages = steps.findIndex(step => step.name === 'Build packages the composed Storybook imports');
const build = steps.findIndex(step => step.name === 'Build composed renderer Storybook');
assert.ok(packages >= 0 && build > packages);
Expand All @@ -400,7 +401,91 @@ test('Storybook exposes each preflight phase once before the composed build', ()
for (const step of preflight) {
assert.match(step.body, /^ working-directory: Storybook$/m, step.name);
}
assert.doesNotMatch(jobs.storybook, /^ run: .*ci:preflight/m);
assert.doesNotMatch(jobs['storybook-build'], /^ run: .*ci:preflight/m);
});

test('Storybook builds packages, previews and verified indexes once before publishing output', () => {
const steps = workflowSteps(jobs['storybook-build']);
const install = steps.findIndex(step => step.name === 'Yarn install');
assert.ok(install >= 0);
assert.deepEqual(steps.slice(install + 1).map(step => step.name), [
'Build packages the composed Storybook imports', ...storybookPreflightNames,
'Build composed renderer Storybook', 'Verify every renderer Storybook index and build attestation',
'Archive prepared Storybook output', 'Upload prepared Storybook output',
]);
const packages = steps[install + 1].body;
assert.match(packages, /^ export NODE_OPTIONS="--max-old-space-size=4096"$/m);
assert.deepEqual([...packages.matchAll(/^ yarn workspace (.+) run build$/gm)]
.map(match => match[1]), [
'@cratis/components.conformance', '@cratis/components.mui', '@cratis/components.primereact',
'@cratis/components.primereact10', '@cratis/components.designsystemet',
]);
const build = steps.findIndex(step => step.name === 'Build composed renderer Storybook');
assertStepCommands(steps.slice(build, build + 2), [
'Build composed renderer Storybook', 'Verify every renderer Storybook index and build attestation',
], ['yarn workspace @cratis/components build-storybook', 'yarn verify-storybook-index']);
assert.match(steps[build + 1].body, /^ working-directory: Source$/m);
assert.equal(workflow.split('run: yarn workspace @cratis/components build-storybook').length - 1, 1);
for (const step of steps) {
assert.doesNotMatch(step.body, /^ (?:if|continue-on-error):/m, step.name);
}
});

test('Storybook shares only explicit prepared outputs in a required same-run SHA-named artifact', () => {
const producer = workflowSteps(jobs['storybook-build']);
const archive = producer.find(step => step.name === 'Archive prepared Storybook output');
assert.equal(archive.body.trim(), `run: |
tar -czf "$RUNNER_TEMP/storybook-build.tar.gz" \\
Source/storybook-static Source/dist Conformance/dist \\
Adapters/Mui/dist Adapters/PrimeReact/dist \\
Adapters/PrimeReact10/dist Adapters/Designsystemet/dist`);
const upload = producer.find(step => step.name === 'Upload prepared Storybook output');
assert.equal(upload.body.trim(), `uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: storybook-build-\${{ github.sha }}
path: \${{ runner.temp }}/storybook-build.tar.gz
if-no-files-found: error
compression-level: 0
retention-days: 1`);
const consumer = workflowSteps(jobs.storybook);
const download = consumer.find(step => step.name === 'Download prepared Storybook output');
assert.equal(download.body.trim(), `uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
with:
name: storybook-build-\${{ github.sha }}
path: \${{ runner.temp }}/storybook-build`);
const restore = consumer.find(step => step.name === 'Restore prepared Storybook output');
assert.equal(restore.body.trim(), 'run: tar -xzf "$RUNNER_TEMP/storybook-build/storybook-build.tar.gz"');
for (const job of ['storybook-build', 'storybook']) {
assert.match(jobs[job], /^ permissions:\n contents: read$/m);
assert.match(jobs[job], /^ runs-on: ubuntu-latest$/m);
assert.doesNotMatch(jobs[job], /continue-on-error|always\(\)|!cancelled\(\)/);
}
});

test('Storybook consumers install, restore and run the unchanged three-shard browser partition without builds', () => {
const steps = workflowSteps(jobs.storybook);
assert.deepEqual(steps.map(step => step.name), [
'Checkout code', 'Setup node', 'Restore Yarn package cache', 'Yarn install',
'Download prepared Storybook output', 'Restore prepared Storybook output',
'Cache Playwright browsers', 'Install Storybook browser', 'Test assigned Storybook units',
]);
assert.match(jobs.storybook, /^ name: Storybook \(shard \$\{\{ matrix.shard \}\}\/3\)$/m);
assert.match(jobs.storybook, /strategy:\n fail-fast: false\n matrix:\n shard: \[1, 2, 3\]/);
assert.match(jobs.storybook, /^ timeout-minutes: 25$/m);
assert.doesNotMatch(jobs.storybook, /^\s+(?:run: )?yarn (?:workspace \S+ (?:run )?)?(?:build(?:-storybook)?|prepare|typecheck|ci:preflight|verify-inventory|verify-isolation|verify-storybook-index)\b/m);
const browser = steps.find(step => step.name === 'Install Storybook browser');
assert.match(browser.body, /^ timeout-minutes: 15$/m);
assert.match(browser.body, /set -euo pipefail\n for attempt in 1 2 3 4; do/);
assert.match(browser.body, /if yarn playwright install --with-deps chromium; then exit 0; fi/);
assert.match(browser.body, /\[ "\$attempt" -lt 4 \] && sleep \$\(\(attempt \* 20\)\)/);
assert.match(browser.body, /exit 1\n/);
assertStepCommands(steps.slice(-1), ['Test assigned Storybook units'], [
'node scripts/run-story-matrix.mjs --shard ${{ matrix.shard }}/3',
]);
assert.match(steps.at(-1).body, /^ working-directory: Storybook$/m);
for (const step of steps) {
assert.doesNotMatch(step.body, /^ (?:if|continue-on-error):/m, step.name);
}
});

test('the local Storybook preflight chain remains identical to the visible CI phases', () => {
Expand Down
Loading