Skip to content

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

TypeScript

fix(ci): speed up PR enrichment deploy (#236)

Cindy Zhang412722ca6821
diff --git a/.github/scripts/accessibility-audit.js b/.github/scripts/accessibility-audit.js
index 317018f8d1..eab0d3bba4 100644
--- a/.github/scripts/accessibility-audit.js
+++ b/.github/scripts/accessibility-audit.js
@@ -203,13 +203,19 @@ async function runAccessibilityAudit() {
// Filter stories for relevant components
const relevantStories = storyIds.filter(id => {
+ // Skip docs pages
+ if (id.endsWith('--docs')) return false;
+
if (components.length === 0) return true;
const story = stories[id];
const title = story.title || '';
- return components.some(comp =>
- title.toLowerCase().includes(comp.toLowerCase()) ||
- id.toLowerCase().includes(comp.toLowerCase())
- );
+
+ // Titles are like "Core/XDSButton" or "Layout/XDSCard"
+ const titleParts = title.split('/');
+ const componentPart = titleParts.length > 1 ? titleParts[1] : titleParts[0];
+ const normalizedComponent = componentPart.replace(/^XDS/i, '').toLowerCase();
+
+ return components.some(comp => normalizedComponent === comp.toLowerCase());
});
// Group stories by component
diff --git a/.github/scripts/capture-screenshots.js b/.github/scripts/capture-screenshots.js
index 462961f930..c78e9d6e8d 100644
--- a/.github/scripts/capture-screenshots.js
+++ b/.github/scripts/capture-screenshots.js
@@ -127,23 +127,38 @@ async function captureScreenshots() {
// Titles are like "Core/XDSButton" or "Layout/XDSCard"
// Components are folder names like "Button" or "Layout"
const titleParts = title.split('/');
- const category = titleParts[0].toLowerCase(); // e.g., "core", "layout", "typography"
const componentPart = titleParts.length > 1 ? titleParts[1] : titleParts[0];
// Remove "XDS" prefix if present for matching
const normalizedComponent = componentPart.replace(/^XDS/i, '').toLowerCase();
return components.some(comp => {
const compLower = comp.toLowerCase();
- // Match if:
- // 1. Component name matches (e.g., "Button" matches "Core/XDSButton")
- // 2. Category matches (e.g., "Layout" matches "Layout/XDSCard")
- return normalizedComponent === compLower || category === compLower;
+ // Match only by component name (e.g., "Button" matches "Core/XDSButton")
+ return normalizedComponent === compLower;
});
});
+ // When video is enabled, only record video for the Default story of each component
+ // to avoid spending ~7s per story on video capture + conversion
+ const defaultStoryIds = new Set();
+ if (captureVideo) {
+ const byComponent = {};
+ for (const storyId of relevantStories) {
+ const story = stories[storyId];
+ const title = story.title || '';
+ if (!byComponent[title]) byComponent[title] = [];
+ byComponent[title].push({ id: storyId, name: story.name || '' });
+ }
+ for (const [, componentStories] of Object.entries(byComponent)) {
+ // Prefer "Default" story, fall back to first story
+ const defaultStory = componentStories.find(s => s.name === 'Default') || componentStories[0];
+ if (defaultStory) defaultStoryIds.add(defaultStory.id);
+ }
+ }
+
console.log(`Capturing ${relevantStories.length} relevant stories`);
if (captureVideo) {
- console.log('Video capture enabled - will record interactions and convert to GIF');
+ console.log(`Video capture enabled for ${defaultStoryIds.size} default stories (screenshots only for the rest)`);
}
const browser = await chromium.launch();
@@ -153,13 +168,16 @@ async function captureScreenshots() {
for (const storyId of relevantStories) {
const story = stories[storyId];
- // Create context with video recording if enabled
+ // Only record video for Default stories to save time
+ const shouldRecordVideo = captureVideo && defaultStoryIds.has(storyId);
+
+ // Create context with video recording if enabled for this story
const contextOptions = {
viewport: { width: 800, height: 600 },
deviceScaleFactor: 2,
};
- if (captureVideo) {
+ if (shouldRecordVideo) {
contextOptions.recordVideo = {
dir: path.join(outputDir, 'videos'),
size: { width: 800, height: 600 },
@@ -230,7 +248,7 @@ async function captureScreenshots() {
await page.waitForTimeout(500);
// If capturing video, ensure we have some content recorded
- if (captureVideo) {
+ if (shouldRecordVideo) {
// Wait to ensure video has content
await page.waitForTimeout(500);
}
@@ -255,7 +273,7 @@ async function captureScreenshots() {
};
// If capturing video, simulate some interactions with visible cursor
- if (captureVideo) {
+ if (shouldRecordVideo) {
// Inject a visible cursor element
await page.evaluate(() => {
const cursor = document.createElement('div');
@@ -369,7 +387,7 @@ async function captureScreenshots() {
await page.close();
let videoPath = null;
- if (captureVideo) {
+ if (shouldRecordVideo) {
const video = page.video();
if (video) {
// Wait for video to be saved - this resolves when the file is ready
@@ -385,7 +403,7 @@ async function captureScreenshots() {
await context.close();
// Now process video after context is closed
- if (captureVideo && videoPath) {
+ if (shouldRecordVideo && videoPath) {
// Give filesystem time to sync
await new Promise(r => setTimeout(r, 500));
diff --git a/.github/workflows/storybook.yml b/.github/workflows/ci.yml
similarity index 56%
rename from .github/workflows/storybook.yml
rename to .github/workflows/ci.yml
index cdb0a1e663..a47db61d5d 100644
--- a/.github/workflows/storybook.yml
+++ b/.github/workflows/ci.yml
@@ -1,19 +1,11 @@
-# Deploy Storybook to GitHub Pages with versioned builds
-name: Deploy Storybook to Pages
+# PR CI: test, build, analyze, screenshot, a11y audit, and comment
+# Everything runs in parallel where possible
+name: CI
on:
- # Runs on pushes targeting the default branch
- push:
- branches: ["main"]
-
- # Runs on pull requests
pull_request:
branches: ["main"]
- # Allows you to run this workflow manually from the Actions tab
- workflow_dispatch:
-
-# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: write
pages: write
@@ -21,14 +13,30 @@ permissions:
pull-requests: write
actions: read
-# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
-# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
- group: "pages-${{ github.head_ref || github.ref }}"
+ group: "ci-${{ github.head_ref }}"
cancel-in-progress: true
jobs:
- # Run tests first
+ # Lightweight check — does the PR touch any core components?
+ # Gates pr-screenshots and pr-a11y to avoid unnecessary work
+ check-components:
+ runs-on: ubuntu-latest
+ outputs:
+ has_components: ${{ steps.check.outputs.has_components }}
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+
+ - name: Check for component changes
+ id: check
+ run: |
+ CHANGED=$(git diff --name-only origin/${{ github.base_ref }}...HEAD -- packages/core/src/ | grep -v -E '(hooks|theme|utils)/' | head -1)
+ echo "has_components=$( [ -n "$CHANGED" ] && echo true || echo false )" >> $GITHUB_OUTPUT
+
+ # Run tests (parallel with build)
test:
runs-on: ubuntu-latest
steps:
@@ -45,17 +53,19 @@ jobs:
- run: yarn build
- # Build and deploy Storybook
- deploy:
- needs: test
+ # Build storybook + analyze components (parallel with test)
+ # Uploads storybook preview and analysis artifacts for downstream jobs
+ build:
runs-on: ubuntu-latest
outputs:
storybook_url: ${{ steps.urls.outputs.storybook_url }}
- sandbox_url: ${{ steps.urls.outputs.sandbox_url }}
short_hash: ${{ steps.urls.outputs.short_hash }}
+ sandbox_url: ${{ steps.urls.outputs.sandbox_url }}
steps:
- name: Checkout
uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
@@ -69,57 +79,24 @@ jobs:
- name: Build core package
run: yarn build
- - name: Compute short hash
- id: hash
- run: |
- COMMIT_HASH="${{ github.event.pull_request.head.sha || github.sha }}"
- echo "short_hash=${COMMIT_HASH:0:7}" >> $GITHUB_OUTPUT
-
- name: Build Storybook
run: yarn workspace @xds/storybook build
- name: Build Sandbox
run: yarn workspace @xds/sandbox build
- env:
- SANDBOX_BASE_PATH: /${{ steps.hash.outputs.short_hash }}/sandbox
+ continue-on-error: true
- - name: Prepare versioned deployment
+ - name: Compute URLs
id: urls
run: |
- SHORT_HASH="${{ steps.hash.outputs.short_hash }}"
+ COMMIT_HASH="${{ github.event.pull_request.head.sha }}"
+ SHORT_HASH="${COMMIT_HASH:0:7}"
REPO_NAME="${{ github.event.repository.name }}"
REPO_OWNER="${{ github.repository_owner }}"
- STORYBOOK_URL="https://${REPO_OWNER}.github.io/${REPO_NAME}/${SHORT_HASH}/"
- SANDBOX_URL="https://${REPO_OWNER}.github.io/${REPO_NAME}/${SHORT_HASH}/sandbox/"
echo "short_hash=${SHORT_HASH}" >> $GITHUB_OUTPUT
- echo "storybook_url=${STORYBOOK_URL}" >> $GITHUB_OUTPUT
- echo "sandbox_url=${SANDBOX_URL}" >> $GITHUB_OUTPUT
-
- # Create deployment directory structure
- mkdir -p deploy/${SHORT_HASH}
- cp -r apps/storybook/dist/* deploy/${SHORT_HASH}/
- mkdir -p deploy/${SHORT_HASH}/sandbox
- cp -r apps/sandbox/out/* deploy/${SHORT_HASH}/sandbox/
-
- # Create root index.html that redirects to latest build (only for main branch)
- if [ "${{ github.event_name }}" == "push" ]; then
- cat > deploy/index.html << EOF
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="refresh" content="0;url=${SHORT_HASH}/index.html">
- <title>XDS Storybook</title>
- </head>
- <body>
- <p>Redirecting to <a href="${SHORT_HASH}/index.html">latest Storybook (${SHORT_HASH})</a>...</p>
- </body>
- </html>
- EOF
- fi
-
- # Create .nojekyll to prevent GitHub Pages from ignoring files starting with underscore
- touch deploy/.nojekyll
+ echo "storybook_url=https://${REPO_OWNER}.github.io/${REPO_NAME}/${SHORT_HASH}/" >> $GITHUB_OUTPUT
+ echo "sandbox_url=https://${REPO_OWNER}.github.io/${REPO_NAME}/${SHORT_HASH}/sandbox/" >> $GITHUB_OUTPUT
- name: Upload Storybook artifact
uses: actions/upload-artifact@v4
@@ -128,7 +105,21 @@ jobs:
path: apps/storybook/dist/
retention-days: 30
- - name: Deploy to GitHub Pages
+ - name: Prepare and deploy Storybook preview
+ run: |
+ SHORT_HASH="${{ steps.urls.outputs.short_hash }}"
+
+ mkdir -p deploy/${SHORT_HASH}
+ cp -r apps/storybook/dist/* deploy/${SHORT_HASH}/
+
+ if [ -d "apps/sandbox/dist" ]; then
+ mkdir -p deploy/${SHORT_HASH}/sandbox
+ cp -r apps/sandbox/dist/* deploy/${SHORT_HASH}/sandbox/
+ fi
+
+ touch deploy/.nojekyll
+
+ - name: Deploy Storybook preview to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
@@ -136,41 +127,44 @@ jobs:
keep_files: true
destination_dir: .
- # PR Enrichment - only runs on pull requests
- pr-enrichment:
- needs: deploy
- if: github.event_name == 'pull_request'
+ - name: Analyze components
+ run: |
+ node .github/scripts/analyze-pr.js \
+ --base origin/${{ github.base_ref }} \
+ --head HEAD \
+ --output analysis.json
+
+ - name: Upload analysis artifact
+ uses: actions/upload-artifact@v4
+ with:
+ name: pr-analysis
+ path: analysis.json
+ retention-days: 1
+
+ # Capture component screenshots and videos (parallel with a11y)
+ # Skipped when no components changed. No yarn install needed.
+ pr-screenshots:
+ needs: [build, check-components]
+ if: needs.check-components.outputs.has_components == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- with:
- fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- cache: 'yarn'
-
- - name: Install dependencies
- run: yarn install --frozen-lockfile
-
- - name: Build packages
- run: yarn build
- - name: Analyze components
- id: analyze
- run: |
- node .github/scripts/analyze-pr.js \
- --base origin/${{ github.base_ref }} \
- --head HEAD \
- --output analysis.json
+ - name: Download analysis artifact
+ uses: actions/download-artifact@v4
+ with:
+ name: pr-analysis
- name: Download Storybook artifact
uses: actions/download-artifact@v4
with:
- name: storybook-${{ needs.deploy.outputs.short_hash }}
+ name: storybook-${{ needs.build.outputs.short_hash }}
path: apps/storybook/dist
- name: Install Playwright
@@ -180,7 +174,6 @@ jobs:
run: sudo apt-get update && sudo apt-get install -y ffmpeg
- name: Capture component screenshots and videos
- id: screenshots
run: |
COMPONENTS=$(cat analysis.json | jq -r '(.newComponents + .modifiedComponents) | join(",")')
node .github/scripts/capture-screenshots.js \
@@ -190,17 +183,13 @@ jobs:
--video
- name: Upload screenshots and videos to GitHub
- id: upload_screenshots
env:
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
- # Install CML CLI only (no visualization deps)
npm install -g @dvcorg/cml
- # Upload each screenshot and video, collect URLs
echo '{}' > screenshot-urls.json
- # Upload PNG screenshots
for file in screenshots/*.png; do
if [ -f "$file" ]; then
filename=$(basename "$file")
@@ -211,7 +200,6 @@ jobs:
fi
done
- # Upload GIF videos
for file in screenshots/*.gif; do
if [ -f "$file" ]; then
filename=$(basename "$file")
@@ -222,7 +210,6 @@ jobs:
fi
done
- # Upload MP4 videos
for file in screenshots/*.mp4; do
if [ -f "$file" ]; then
filename=$(basename "$file")
@@ -235,8 +222,45 @@ jobs:
cat screenshot-urls.json
+ - name: Upload screenshots artifact
+ uses: actions/upload-artifact@v4
+ with:
+ name: component-screenshots
+ path: |
+ screenshots/
+ screenshot-urls.json
+ retention-days: 30
+
+ # Accessibility audit (parallel with screenshots)
+ # Skipped when no components changed. No yarn install needed.
+ pr-a11y:
+ needs: [build, check-components]
+ if: needs.check-components.outputs.has_components == 'true'
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+
+ - name: Setup Node.js
+ uses: actions/setup-node@v4
+ with:
+ node-version: 22
+
+ - name: Download analysis artifact
+ uses: actions/download-artifact@v4
+ with:
+ name: pr-analysis
+
+ - name: Download Storybook artifact
+ uses: actions/download-artifact@v4
+ with:
+ name: storybook-${{ needs.build.outputs.short_hash }}
+ path: apps/storybook/dist
+
+ - name: Install Playwright
+ run: npx playwright install chromium
+
- name: Run accessibility audit
- id: a11y
run: |
COMPONENTS=$(cat analysis.json | jq -r '(.newComponents + .modifiedComponents) | join(",")')
node .github/scripts/accessibility-audit.js \
@@ -244,29 +268,73 @@ jobs:
--output a11y-report.json \
--components "$COMPONENTS"
- - name: Upload screenshots artifact
+ - name: Upload a11y artifact
uses: actions/upload-artifact@v4
+ with:
+ name: a11y-report
+ path: a11y-report.json
+ retention-days: 1
+
+ # Post PR comment with results
+ # Waits for test to pass. Runs even when screenshots/a11y are skipped.
+ pr-comment:
+ needs: [test, build, check-components, pr-screenshots, pr-a11y]
+ if: always() && needs.test.result == 'success' && needs.build.result == 'success'
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+
+ - name: Setup Node.js
+ uses: actions/setup-node@v4
+ with:
+ node-version: 22
+
+ - name: Download analysis artifact
+ uses: actions/download-artifact@v4
+ with:
+ name: pr-analysis
+
+ - name: Download screenshots artifact
+ if: needs.pr-screenshots.result == 'success'
+ uses: actions/download-artifact@v4
with:
name: component-screenshots
- path: screenshots/
- retention-days: 30
+ path: screenshots-artifact
+
+ - name: Download a11y artifact
+ if: needs.pr-a11y.result == 'success'
+ uses: actions/download-artifact@v4
+ with:
+ name: a11y-report
- name: Generate PR comment
- id: comment
run: |
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
+ if [ ! -f a11y-report.json ]; then
+ echo '{"components":{},"summary":{"componentsAudited":0,"totalViolations":0}}' > a11y-report.json
+ fi
+
+ SCREENSHOTS_ARG=""
+ SCREENSHOT_URLS_ARG=""
+ if [ -f screenshots-artifact/screenshots/screenshots.json ]; then
+ SCREENSHOTS_ARG="--screenshots screenshots-artifact/screenshots/screenshots.json"
+ fi
+ if [ -f screenshots-artifact/screenshot-urls.json ]; then
+ SCREENSHOT_URLS_ARG="--screenshot-urls screenshots-artifact/screenshot-urls.json"
+ fi
+
COMMENT_BODY=$(node .github/scripts/generate-pr-comment.js \
--analysis analysis.json \
--a11y a11y-report.json \
- --screenshots screenshots/screenshots.json \
- --screenshot-urls screenshot-urls.json \
- --storybook-url "${{ needs.deploy.outputs.storybook_url }}" \
- --sandbox-url "${{ needs.deploy.outputs.sandbox_url }}" \
+ $SCREENSHOTS_ARG \
+ $SCREENSHOT_URLS_ARG \
+ --storybook-url "${{ needs.build.outputs.storybook_url }}" \
+ --sandbox-url "${{ needs.build.outputs.sandbox_url }}" \
--run-url "$RUN_URL" \
--pr-number "${{ github.event.pull_request.number }}")
- # Save to file for the next step
echo "$COMMENT_BODY" > pr-comment.md
- name: Comment on PR
@@ -277,7 +345,6 @@ jobs:
const body = fs.readFileSync('pr-comment.md', 'utf8');
const prNumber = ${{ github.event.pull_request.number }};
- // Find and update existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
new file mode 100644
index 0000000000..d4b8e9210c
--- /dev/null
+++ b/.github/workflows/deploy.yml
@@ -0,0 +1,97 @@
+# Deploy Storybook to GitHub Pages
+# Only runs on push to main — simple and sequential: test → deploy
+name: Deploy Storybook to Pages
+
+on:
+ push:
+ branches: ["main"]
+ workflow_dispatch:
+
+permissions:
+ contents: write
+ pages: write
+ id-token: write
+
+concurrency:
+ group: "pages-deploy"
+ cancel-in-progress: false
+
+jobs:
+ test:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+
+ - uses: actions/setup-node@v4
+ with:
+ node-version: 20
+ cache: 'yarn'
+
+ - run: yarn install --frozen-lockfile
+
+ - run: yarn test
+
+ - run: yarn build
+
+ deploy:
+ needs: test
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+
+ - name: Setup Node.js
+ uses: actions/setup-node@v4
+ with:
+ node-version: 20
+ cache: 'yarn'
+
+ - name: Install dependencies
+ run: yarn install --frozen-lockfile
+
+ - name: Build core package
+ run: yarn build
+
+ - name: Build Storybook
+ run: yarn workspace @xds/storybook build
+
+ - name: Build Sandbox
+ run: yarn workspace @xds/sandbox build
+ continue-on-error: true
+
+ - name: Prepare deployment
+ run: |
+ SHORT_HASH="${GITHUB_SHA:0:7}"
+ REPO_NAME="${{ github.event.repository.name }}"
+ REPO_OWNER="${{ github.repository_owner }}"
+
+ mkdir -p deploy/${SHORT_HASH}
+ cp -r apps/storybook/dist/* deploy/${SHORT_HASH}/
+
+ if [ -d "apps/sandbox/dist" ]; then
+ mkdir -p deploy/${SHORT_HASH}/sandbox
+ cp -r apps/sandbox/dist/* deploy/${SHORT_HASH}/sandbox/
+ fi
+
+ cat > deploy/index.html << EOF
+ <!DOCTYPE html>
+ <html>
+ <head>
+ <meta http-equiv="refresh" content="0;url=${SHORT_HASH}/index.html">
+ <title>XDS Storybook</title>
+ </head>
+ <body>
+ <p>Redirecting to <a href="${SHORT_HASH}/index.html">latest Storybook (${SHORT_HASH})</a>...</p>
+ </body>
+ </html>
+ EOF
+
+ touch deploy/.nojekyll
+
+ - name: Deploy to GitHub Pages
+ uses: peaceiris/actions-gh-pages@v4
+ with:
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ publish_dir: ./deploy
+ keep_files: true
+ destination_dir: .