An open source design system that's fully customizable and agent ready
TypeScript
Setting up storybook publishing during PR push (#78)
Cindy Zhange780ed42ac99
diff --git a/.github/scripts/capture-screenshots.js b/.github/scripts/capture-screenshots.jsindex 7cd64a9e06..462961f930 100644--- a/.github/scripts/capture-screenshots.js+++ b/.github/scripts/capture-screenshots.js@@ -87,7 +87,7 @@ async function getStories(storybookPath) {async function captureScreenshots() {console.log('Starting screenshot capture...');- console.log(`Components to capture: ${components.length > 0 ? components.join(', ') : 'all'}`);+ console.log(`Components to capture: ${components.length > 0 ? components.join(', ') : 'none (no components specified)'}`);// Ensure output directory existsfs.mkdirSync(outputDir, { recursive: true });@@ -118,13 +118,27 @@ async function captureScreenshots() {// Skip docs pages - they often have rendering issuesif (id.endsWith('--docs')) return false;- if (components.length === 0) return true;+ // If no components specified, don't capture any (avoid accidental full runs)+ if (components.length === 0) return false;+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"+ // 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;+ });});console.log(`Capturing ${relevantStories.length} relevant stories`);diff --git a/.github/scripts/generate-pr-comment.js b/.github/scripts/generate-pr-comment.jsindex 4ba0dd5b24..e70b3459c4 100644--- a/.github/scripts/generate-pr-comment.js+++ b/.github/scripts/generate-pr-comment.js@@ -2,7 +2,7 @@/*** @description Generates and posts PR comment with analysis results and embedded screenshots- * @input --analysis <file> --a11y <file> --screenshots <file> --screenshot-urls <file> --run-url <url>+ * @input --analysis <file> --a11y <file> --screenshots <file> --screenshot-urls <file> --storybook-url <url> --run-url <url>* @output Formatted markdown comment body to stdout*/@@ -20,6 +20,7 @@ const screenshotsFile = getArg('screenshots') || 'screenshots/screenshots.json';const screenshotUrlsFile = getArg('screenshot-urls') || 'screenshot-urls.json';const runUrl = getArg('run-url') || '';const prNumber = getArg('pr-number') || '';+const storybookUrl = getArg('storybook-url') || '';// Read analysis resultslet analysis = { newComponents: [], modifiedComponents: [], componentStats: {}, totalBundle: {} };@@ -185,15 +186,26 @@ if (hasAffectedComponents && screenshots.length > 0) {}}+// Build storybook link section+let storybookSection = '';+if (storybookUrl) {+ storybookSection = `### 📚 Storybook Preview++**[View Storybook for this PR](${storybookUrl})**++`;+}+// Build footer with linkslet footerLinks = [];+if (storybookUrl) footerLinks.push(`[Storybook](${storybookUrl})`);if (runUrl) footerLinks.push(`[View full report](${runUrl})`);const footerLinksStr = footerLinks.length > 0 ? ` | ${footerLinks.join(' | ')}` : '';// Build the full commentconst body = `## PR Analysis Report-${componentSection || '_No new or modified components detected._\n\n'}+${storybookSection}${componentSection || '_No new or modified components detected._\n\n'}${bundleSection}${a11ySection}${screenshotSection}diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.ymlindex c09c012223..5286fdf24f 100644--- a/.github/workflows/lint.yml+++ b/.github/workflows/lint.yml@@ -11,8 +11,6 @@ jobs:runs-on: ubuntu-latestpermissions:contents: read- pull-requests: write- checks: writesteps:- uses: actions/checkout@v4@@ -24,11 +22,9 @@ jobs:- run: yarn install --frozen-lockfile+ # Clear ESLint cache to ensure fresh run+ - name: Clear ESLint cache+ run: rm -rf .eslintcache node_modules/.cache+- name: Run ESLint- uses: reviewdog/action-eslint@v1- with:- github_token: ${{ secrets.GITHUB_TOKEN }}- reporter: github-pr-review- eslint_flags: '--max-warnings 0 packages/core/src/'- fail_on_error: true- filter_mode: nofilter+ run: yarn lintdiff --git a/.github/workflows/pr-enrichment.yml b/.github/workflows/storybook.ymlsimilarity index 57%rename from .github/workflows/pr-enrichment.ymlrename to .github/workflows/storybook.ymlindex 0d4b4372c3..db4e99d68a 100644--- a/.github/workflows/pr-enrichment.yml+++ b/.github/workflows/storybook.yml@@ -1,35 +1,141 @@-name: PR Enrichment+# Deploy Storybook to GitHub Pages with versioned builds+name: Deploy Storybook to Pageson:+ # Runs on pushes targeting the default branch+ push:+ branches: ["main"]++ # Runs on pull requestspull_request:- branches: [main]+ 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+ id-token: write+ 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: pr-enrichment-${{ github.head_ref || github.ref }}+ group: "pages-${{ github.head_ref || github.ref }}"cancel-in-progress: truejobs:- analyze:- name: Analyze PR+ # Run tests first+ test:runs-on: ubuntu-latest- permissions:- contents: write- pull-requests: write- actions: read+ 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++ # Build and deploy Storybook+ deploy:+ needs: test+ runs-on: ubuntu-latest+ outputs:+ storybook_url: ${{ steps.urls.outputs.storybook_url }}+ short_hash: ${{ steps.urls.outputs.short_hash }}steps:- - name: Checkout PR+ - name: Checkoutuses: actions/checkout@v4++ - name: Setup Node.js+ uses: actions/setup-node@v4with:- fetch-depth: 0+ 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: Prepare versioned deployment+ id: urls+ run: |+ COMMIT_HASH="${{ github.event.pull_request.head.sha || github.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}/"- - name: Checkout base branch for comparison- run: git fetch origin ${{ github.base_ref }}:base-branch+ echo "short_hash=${SHORT_HASH}" >> $GITHUB_OUTPUT+ echo "storybook_url=${STORYBOOK_URL}" >> $GITHUB_OUTPUT++ # Create deployment directory structure+ mkdir -p deploy/${SHORT_HASH}+ cp -r apps/storybook/dist/* deploy/${SHORT_HASH}/++ # 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++ - name: Upload Storybook artifact+ uses: actions/upload-artifact@v4+ with:+ name: storybook-${{ steps.urls.outputs.short_hash }}+ path: apps/storybook/dist/+ retention-days: 30++ - 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: .++ # PR Enrichment - only runs on pull requests+ pr-enrichment:+ needs: deploy+ if: github.event_name == 'pull_request'+ runs-on: ubuntu-latest+ steps:+ - name: Checkout+ uses: actions/checkout@v4+ with:+ fetch-depth: 0- name: Setup Node.jsuses: actions/setup-node@v4with:- node-version: '22'+ node-version: 22cache: 'yarn'- name: Install dependencies@@ -42,12 +148,15 @@ jobs:id: analyzerun: |node .github/scripts/analyze-pr.js \- --base base-branch \+ --base origin/${{ github.base_ref }} \--head HEAD \--output analysis.json- - name: Build Storybook- run: yarn storybook:build+ - name: Download Storybook artifact+ uses: actions/download-artifact@v4+ with:+ name: storybook-${{ needs.deploy.outputs.short_hash }}+ path: apps/storybook/dist- name: Install Playwrightrun: npx playwright install chromium@@ -127,13 +236,6 @@ jobs:path: screenshots/retention-days: 30- - name: Upload Storybook artifact- uses: actions/upload-artifact@v4- with:- name: storybook-build- path: apps/storybook/dist/- retention-days: 30-- name: Generate PR commentid: commentrun: |@@ -144,6 +246,7 @@ jobs:--a11y a11y-report.json \--screenshots screenshots/screenshots.json \--screenshot-urls screenshot-urls.json \+ --storybook-url "${{ needs.deploy.outputs.storybook_url }}" \--run-url "$RUN_URL" \--pr-number "${{ github.event.pull_request.number }}")@@ -156,12 +259,13 @@ jobs:script: |const fs = require('fs');const body = fs.readFileSync('pr-comment.md', 'utf8');+ const prNumber = ${{ github.event.pull_request.number }};// Find and update existing commentconst { data: comments } = await github.rest.issues.listComments({owner: context.repo.owner,repo: context.repo.repo,- issue_number: context.issue.number,+ issue_number: prNumber,});const botComment = comments.find(comment =>@@ -180,7 +284,7 @@ jobs:await github.rest.issues.createComment({owner: context.repo.owner,repo: context.repo.repo,- issue_number: context.issue.number,+ issue_number: prNumber,body: body});}diff --git a/.github/workflows/test.yml b/.github/workflows/test.ymldeleted file mode 100644index 75b8ec0248..0000000000--- a/.github/workflows/test.yml+++ /dev/null@@ -1,24 +0,0 @@-name: Tests--on:- push:- branches: [main]- pull_request:- branches: [main]--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 builddiff --git a/internal/eslint-plugin-xds/index.js b/internal/eslint-plugin-xds/index.jsindex 113d18fff4..983ee0b991 100644--- a/internal/eslint-plugin-xds/index.js+++ b/internal/eslint-plugin-xds/index.js@@ -195,59 +195,6 @@ const noHardcodedStylesRule = {},};-// =============================================================================-// Rule: require-letter-spacing-// Ensures letterSpacing is defined when fontSize is used (badge-specific pattern)-// =============================================================================--const requireLetterSpacingRule = {- meta: {- type: 'suggestion',- docs: {- description: 'Recommend adding letterSpacing when defining fontSize in StyleX',- category: 'Best Practices',- recommended: false,- },- messages: {- addLetterSpacing: 'Consider adding letterSpacing when using fontSize. Common value: letterSpacing: \'-0.24px\'',- },- schema: [],- },- create(context) {- return {- Property(node) {- // Only check inside stylex.create()- if (!isInsideStylexCreate(node)) {- return;- }-- // Look for fontSize property- const propName = node.key?.name || node.key?.value;- if (propName !== 'fontSize') {- return;- }-- // Check if sibling properties include letterSpacing- const parent = node.parent;- if (parent?.type !== 'ObjectExpression') {- return;- }-- const hasLetterSpacing = parent.properties.some(- (prop) => (prop.key?.name || prop.key?.value) === 'letterSpacing'- );-- if (!hasLetterSpacing) {- context.report({- node,- messageId: 'addLetterSpacing',- });- }- },- };- },-};-// =============================================================================// Plugin Export// =============================================================================@@ -259,7 +206,6 @@ const plugin = {},rules: {'no-hardcoded-styles': noHardcodedStylesRule,- 'require-letter-spacing': requireLetterSpacingRule,},configs: {},};@@ -271,7 +217,6 @@ plugin.configs.strict = {},rules: {'@xds/no-hardcoded-styles': 'error',- '@xds/require-letter-spacing': 'error',},};@@ -282,7 +227,6 @@ plugin.configs.recommended = {},rules: {'@xds/no-hardcoded-styles': 'warn',- '@xds/require-letter-spacing': 'off', // Optional for humans},};