An open source design system that's fully customizable and agent ready
TypeScript
ci: route remaining gh-pages writers through publisher (#5674)
Cindy Zhangc2ae093f4e82
diff --git a/.github/scripts/compact-gh-pages-history.sh b/.github/scripts/compact-gh-pages-history.shindex 4d209db981..243f0563f7 100755--- a/.github/scripts/compact-gh-pages-history.sh+++ b/.github/scripts/compact-gh-pages-history.sh@@ -3,66 +3,4 @@set -euo pipefail-PAGES_BRANCH="${PAGES_BRANCH:-gh-pages}"-REPO="${GITHUB_REPOSITORY:?GITHUB_REPOSITORY is required}"-TOKEN="${GITHUB_TOKEN:?GITHUB_TOKEN is required}"-REMOTE_URL="https://x-access-token:${TOKEN}@github.com/${REPO}.git"-MAX_ATTEMPTS="${MAX_ATTEMPTS:-5}"-WORK_DIR="$(mktemp -d)"--cleanup() {- rm -rf "${WORK_DIR}"-}-trap cleanup EXIT--CURRENT_DIR="${WORK_DIR}/current"-COMPACT_DIR="${WORK_DIR}/compact"--# gh-pages has concurrent writers this workflow is not serialized against —-# preview deploys and cleanup runs sit in their own concurrency groups — and-# compaction takes ~10 minutes, so the lease taken at clone time regularly goes-# stale before the push ("[rejected] (stale info)"). The snapshot is of the tip-# it cloned, so a retry has to re-clone: pushing the old snapshot would silently-# revert whatever landed meanwhile. Same shape as the retry in-# cleanup-previews.yml.-for attempt in $(seq 1 "${MAX_ATTEMPTS}"); do- if [ "${attempt}" -gt 1 ]; then- echo "Retrying compaction in $((attempt * 2))s (attempt ${attempt}/${MAX_ATTEMPTS})"- sleep $((attempt * 2))- fi-- rm -rf "${CURRENT_DIR}" "${COMPACT_DIR}"-- git clone --depth=1 --single-branch --branch "${PAGES_BRANCH}" "${REMOTE_URL}" "${CURRENT_DIR}"- OLD_HEAD="$(git -C "${CURRENT_DIR}" rev-parse HEAD)"-- mkdir -p "${COMPACT_DIR}"- rsync -a --delete --exclude='.git' "${CURRENT_DIR}/" "${COMPACT_DIR}/"-- (- cd "${COMPACT_DIR}"- git init -b "${PAGES_BRANCH}"- git config user.name "github-actions[bot]"- git config user.email "github-actions[bot]@users.noreply.github.com"- git add -A- git commit --allow-empty -m "chore: compact ${PAGES_BRANCH} history"- git remote add origin "${REMOTE_URL}"- )-- if PUSH_OUT=$(git -C "${COMPACT_DIR}" push origin \- "HEAD:refs/heads/${PAGES_BRANCH}" \- "--force-with-lease=refs/heads/${PAGES_BRANCH}:${OLD_HEAD}" 2>&1); then- echo "Compacted ${PAGES_BRANCH} to a single commit (previous tip ${OLD_HEAD})"- exit 0- fi- echo "${PUSH_OUT}"-- # A permission denial is not a race; retrying can never clear it.- if echo "${PUSH_OUT}" | grep -qiE 'denied|403|permission|not authorized'; then- echo "::error::Push to ${PAGES_BRANCH} denied (403/permissions) — not a race, aborting."- exit 1- fi-done--echo "::error::Failed to compact ${PAGES_BRANCH} after ${MAX_ATTEMPTS} attempts"-exit 1+node .github/scripts/gh-pages-publisher.mjs compactdiff --git a/.github/scripts/lib/gh-pages-publisher.mjs b/.github/scripts/lib/gh-pages-publisher.mjsindex b7f271120b..cadc20998e 100755--- a/.github/scripts/lib/gh-pages-publisher.mjs+++ b/.github/scripts/lib/gh-pages-publisher.mjs@@ -10,6 +10,11 @@ import {fileURLToPath} from 'node:url';const PAGES_BRANCH = 'gh-pages';const QUEUE_REL = path.join('.astryx-gh-pages', 'publication-queue');const LEGACY_BASELINE_QUEUE_REL = path.join('visual-gate', 'publication-queue');+const SCREENSHOT_RETENTION_INDEX_REL = path.join(+ '.astryx-gh-pages',+ 'retention',+ 'screenshot-created-at.json',+);const BASELINE_SCOPE = 'visual-gate/baseline';const HOLDER_NAME = 'holder.json';const RUN_ID = /^[1-9][0-9]*$/;@@ -497,6 +502,7 @@ function checkoutPages({tempRoot,sparsePaths = [],noCheckout = false,+ fullHistory = false,prefix = 'gh-pages-',remoteURL: configuredRemoteURL,}) {@@ -504,12 +510,14 @@ function checkoutPages({const args = ['clone','--quiet',- '--depth=1','--filter=blob:none','--single-branch','--branch',PAGES_BRANCH,];+ if (!fullHistory) {+ args.push('--depth=1');+ }if (noCheckout) {args.push('--no-checkout');} else if (sparsePaths.length > 0) {@@ -1533,6 +1541,661 @@ export async function publishManualVisualBaseline({refuse(`could not push the updated baseline after ${maxAttempts} attempts`);}+function removeContents(destination) {+ fs.rmSync(destination, {recursive: true, force: true});+ fs.mkdirSync(destination, {recursive: true});+}++export async function publishPrPreview({+ repository,+ token,+ tempRoot,+ remoteURL,+ pr,+ storybook,+ sandbox,+ maxAttempts = 5,+ beforePush,+}) {+ const prNumber = Number(pr);+ if (!Number.isSafeInteger(prNumber) || prNumber <= 0) {+ refuse('PR number is invalid');+ }+ const storybookDir = path.resolve(storybook);+ const sandboxDir = path.resolve(sandbox);+ for (const [name, dir] of [+ ['--storybook', storybookDir],+ ['--sandbox', sandboxDir],+ ]) {+ if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) {+ refuse(`${name} must be a directory`);+ }+ }+ const destinationRel = `pr/${prNumber}`;+ for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {+ const checkout = checkoutPages({+ repository,+ token,+ tempRoot,+ remoteURL,+ sparsePaths: [destinationRel],+ prefix: 'gh-pages-preview-',+ });+ try {+ const destination = path.join(checkout, destinationRel);+ removeContents(destination);+ copyContents(storybookDir, destination);+ fs.mkdirSync(path.join(destination, 'sandbox'), {recursive: true});+ for (const entry of fs.readdirSync(sandboxDir, {withFileTypes: true})) {+ if (entry.name === 'template-assets') continue;+ fs.cpSync(+ path.join(sandboxDir, entry.name),+ path.join(destination, 'sandbox', entry.name),+ {recursive: true, force: true},+ );+ }+ const commit = commitIfNeeded(+ checkout,+ `Deploy PR #${prNumber} preview`,+ ['-A', destinationRel],+ );+ if (commit === null) {+ process.stdout.write('Nothing to publish.\n');+ return {published: false};+ }+ await beforePush?.({attempt, checkout, commit});+ const pushed = tryRun('git', [+ '-C',+ checkout,+ 'push',+ 'origin',+ PAGES_BRANCH,+ ]);+ if (pushOrRetry(pushed)) {+ process.stdout.write(`Deployed PR #${prNumber} preview.\n`);+ return {published: true, commit};+ }+ } finally {+ fs.rmSync(checkout, {recursive: true, force: true});+ }+ process.stdout.write(+ `Push rejected; retrying PR preview publish (${attempt}/${maxAttempts}).\n`,+ );+ await sleep(attempt * 2000);+ }+ refuse(+ `could not publish PR #${prNumber} preview after ${maxAttempts} attempts`,+ );+}++function listOpenPRsFromGitHub(repository) {+ const result = run('gh', [+ 'pr',+ 'list',+ '--repo',+ repository,+ '--state',+ 'open',+ '--limit',+ '1000',+ '--json',+ 'number',+ '--jq',+ '.[].number',+ ]);+ return new Set(+ result+ .split(/\s+/)+ .filter(Boolean)+ .map(value => String(Number(value)))+ .filter(value => value !== 'NaN'),+ );+}++function isSevenHex(value) {+ return /^[0-9a-f]{7}$/.test(value);+}++function currentTimeMs() {+ return Number(process.env.ASTRYX_GH_PAGES_NOW_MS) || Date.now();+}++function screenshotRetentionFile(checkout) {+ return path.join(checkout, SCREENSHOT_RETENTION_INDEX_REL);+}++function readScreenshotRetentionIndex(checkout) {+ const file = screenshotRetentionFile(checkout);+ const value = readJSON(file);+ return value && typeof value === 'object' && !Array.isArray(value)+ ? value+ : {};+}++function writeScreenshotRetentionIndex(checkout, index) {+ const file = screenshotRetentionFile(checkout);+ fs.mkdirSync(path.dirname(file), {recursive: true});+ fs.writeFileSync(file, `${JSON.stringify(index, null, 2)}\n`);+}++function screenshotPaths(checkout) {+ const reportsRoot = path.join(checkout, 'reports');+ const paths = [];+ if (!fs.existsSync(reportsRoot)) return paths;+ for (const report of fs.readdirSync(reportsRoot, {withFileTypes: true})) {+ if (!report.isDirectory()) continue;+ const root = path.join(reportsRoot, report.name, 'screenshots');+ if (!fs.existsSync(root)) continue;+ for (const file of fileList(root)) {+ if (file.endsWith('.png')) {+ paths.push(+ path.posix.join('reports', report.name, 'screenshots', file),+ );+ }+ }+ }+ return paths.sort();+}++function gitPathTimestamp(checkout, rel) {+ const result = tryRun('git', [+ '-C',+ checkout,+ 'log',+ '-1',+ '--format=%ct',+ '--',+ rel,+ ]);+ if (result.status !== 0) return null;+ const timestamp = Number(result.stdout.trim());+ return Number.isFinite(timestamp) && timestamp > 0 ? timestamp * 1000 : null;+}++function seedScreenshotRetentionIndex(checkout, now = currentTimeMs()) {+ const index = readScreenshotRetentionIndex(checkout);+ let changed = false;+ const live = new Set(screenshotPaths(checkout));+ for (const rel of live) {+ if (typeof index[rel] !== 'string') {+ index[rel] = new Date(+ gitPathTimestamp(checkout, rel) ?? now,+ ).toISOString();+ changed = true;+ }+ }+ for (const rel of Object.keys(index)) {+ if (!live.has(rel) || !rel.endsWith('.png')) {+ delete index[rel];+ changed = true;+ }+ }+ if (changed) writeScreenshotRetentionIndex(checkout, index);+ return {index, changed};+}++function rememberPublishedScreenshots(+ checkout,+ destinationRel,+ sourceDir,+ now = currentTimeMs(),+) {+ const {index} = seedScreenshotRetentionIndex(checkout, now);+ let changed = false;+ for (const file of fileList(sourceDir)) {+ if (!file.endsWith('.png')) continue;+ const rel = path.posix.join(destinationRel.replaceAll(path.sep, '/'), file);+ if (typeof index[rel] !== 'string') {+ index[rel] = new Date(now).toISOString();+ changed = true;+ }+ }+ if (changed) writeScreenshotRetentionIndex(checkout, index);+}++function expiredReportScreenshots(checkout, now = currentTimeMs()) {+ const cutoffMs = now - 30 * 24 * 60 * 60 * 1000;+ const {index} = seedScreenshotRetentionIndex(checkout, now);+ return Object.entries(index)+ .filter(+ ([rel, iso]) =>+ rel.endsWith('.png') &&+ fs.existsSync(path.join(checkout, rel)) &&+ Date.parse(iso) < cutoffMs,+ )+ .map(([rel]) => rel)+ .sort();+}++function pruneEmptyScreenshotDirs(checkout) {+ const reportsRoot = path.join(checkout, 'reports');+ if (!fs.existsSync(reportsRoot)) return;+ for (const report of fs.readdirSync(reportsRoot, {withFileTypes: true})) {+ if (!report.isDirectory()) continue;+ const root = path.join(reportsRoot, report.name, 'screenshots');+ if (!fs.existsSync(root)) continue;+ if (!fileList(root).some(file => file.endsWith('.png'))) {+ fs.rmSync(root, {recursive: true, force: true});+ }+ }+}++function forgetScreenshots(checkout, rels) {+ const index = readScreenshotRetentionIndex(checkout);+ let changed = false;+ for (const rel of rels) {+ if (index[rel] !== undefined) {+ delete index[rel];+ changed = true;+ }+ }+ if (changed) writeScreenshotRetentionIndex(checkout, index);+}++export async function cleanupPreviews({+ repository,+ token,+ tempRoot,+ remoteURL,+ dryRun = false,+ openPRs,+ now,+ maxAttempts = 5,+ beforePush,+}) {+ const open =+ openPRs instanceof Set ? openPRs : listOpenPRsFromGitHub(repository);+ if (open.size === 0) {+ process.stdout.write('No confirmed open PR list; skipping cleanup.\n');+ return {deleted: 0, skipped: true};+ }+ for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {+ const checkout = checkoutPages({+ repository,+ token,+ tempRoot,+ remoteURL,+ fullHistory: true,+ prefix: 'gh-pages-cleanup-',+ });+ try {+ const deleted = [];+ for (const entry of fs.readdirSync(checkout, {withFileTypes: true})) {+ if (entry.isDirectory() && isSevenHex(entry.name))+ deleted.push(entry.name);+ }+ const prRoot = path.join(checkout, 'pr');+ if (fs.existsSync(prRoot)) {+ for (const entry of fs.readdirSync(prRoot, {withFileTypes: true})) {+ if (!entry.isDirectory()) continue;+ if (!open.has(entry.name))+ deleted.push(path.posix.join('pr', entry.name));+ const templateAssets = path.join(+ prRoot,+ entry.name,+ 'sandbox',+ 'template-assets',+ );+ if (fs.existsSync(templateAssets)) {+ deleted.push(+ path.posix.join('pr', entry.name, 'sandbox', 'template-assets'),+ );+ }+ }+ }+ for (const item of [+ 'favicon.svg',+ 'iframe.html',+ 'index.json',+ 'project.json',+ 'nunito-sans-bold-italic.woff2',+ 'nunito-sans-bold.woff2',+ 'nunito-sans-italic.woff2',+ 'nunito-sans-regular.woff2',+ 'sb-addons',+ 'sb-common-assets',+ 'sb-manager',+ ]) {+ if (fs.existsSync(path.join(checkout, item))) deleted.push(item);+ }+ const expiredScreenshots = expiredReportScreenshots(checkout, now);+ deleted.push(...expiredScreenshots);+ const uniqueDeleted = [...new Set(deleted)].sort();+ for (const rel of uniqueDeleted) process.stdout.write(`DELETE ${rel}\n`);+ if (dryRun) return {deleted: uniqueDeleted.length, dryRun: true};+ for (const rel of uniqueDeleted) {+ fs.rmSync(path.join(checkout, rel), {recursive: true, force: true});+ }+ forgetScreenshots(checkout, expiredScreenshots);+ pruneEmptyScreenshotDirs(checkout);+ if (uniqueDeleted.length === 0) {+ process.stdout.write('Nothing to clean up.\n');+ return {deleted: 0};+ }+ const commit = commitIfNeeded(+ checkout,+ `chore: cleanup ${uniqueDeleted.length} stale deployments`,+ ['-A'],+ );+ if (commit === null) return {deleted: 0};+ await beforePush?.({attempt, checkout, commit});+ const pushed = tryRun('git', [+ '-C',+ checkout,+ 'push',+ 'origin',+ PAGES_BRANCH,+ ]);+ if (pushOrRetry(pushed)) return {deleted: uniqueDeleted.length, commit};+ } finally {+ fs.rmSync(checkout, {recursive: true, force: true});+ }+ process.stdout.write(+ `Push rejected; retrying cleanup publish (${attempt}/${maxAttempts}).\n`,+ );+ await sleep(attempt * 2000);+ }+ refuse(`could not push cleanup after ${maxAttempts} attempts`);+}++export async function publishVibeReport({+ repository,+ token,+ tempRoot,+ remoteURL,+ reportId,+ source,+ maxAttempts = 5,+ beforePush,+}) {+ const report = safeRelativePath(String(reportId), '--report-id');+ const sourceDir = path.resolve(source);+ if (!fs.existsSync(sourceDir) || !fs.statSync(sourceDir).isDirectory()) {+ refuse('--source must be a directory');+ }+ const destinationRel = `reports/${report}`;+ for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {+ const checkout = checkoutPages({+ repository,+ token,+ tempRoot,+ remoteURL,+ sparsePaths: ['reports'],+ prefix: 'gh-pages-vibe-report-',+ });+ const stageRoot = fs.mkdtempSync(path.join(tempRoot, 'vibe-report-stage-'));+ try {+ const destination = path.join(checkout, destinationRel);+ const stage = path.join(stageRoot, report);+ seedScreenshotRetentionIndex(checkout);+ if (fs.existsSync(destination)) {+ copyContents(destination, stage);+ }+ copyContents(sourceDir, stage);+ fs.rmSync(destination, {recursive: true, force: true});+ copyContents(stage, destination);+ const screenshots = path.join(stage, 'screenshots');+ if (fs.existsSync(screenshots)) {+ rememberPublishedScreenshots(+ checkout,+ `${destinationRel}/screenshots`,+ screenshots,+ );+ }+ updateReportsIndex(path.join(checkout, 'reports'));+ const commit = commitIfNeeded(checkout, `report: ${report}`, [+ '-A',+ 'reports',+ ]);+ if (commit === null) return {published: false};+ await beforePush?.({attempt, checkout, commit});+ const pushed = tryRun('git', [+ '-C',+ checkout,+ 'push',+ 'origin',+ PAGES_BRANCH,+ ]);+ if (pushOrRetry(pushed)) return {published: true, commit};+ } finally {+ fs.rmSync(stageRoot, {recursive: true, force: true});+ fs.rmSync(checkout, {recursive: true, force: true});+ }+ process.stdout.write(+ `Push rejected; retrying vibe report publish (${attempt}/${maxAttempts}).\n`,+ );+ await sleep(attempt * 2000);+ }+ refuse(`could not publish report ${report} after ${maxAttempts} attempts`);+}++function updateReportsIndex(reportsDir) {+ fs.mkdirSync(reportsDir, {recursive: true});+ const entries = fs+ .readdirSync(reportsDir, {withFileTypes: true})+ .filter(entry => entry.isDirectory())+ .map(entry => entry.name)+ .sort()+ .reverse();+ const html = `<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Astryx Vibe Test Reports</title>+</head>+<body>+ <h1>📊 Astryx Vibe Test Reports</h1>+ <ul>+ ${entries.map(name => `<li><a href="${name}/">${name}</a></li>`).join('\n ')}+ </ul>+</body>+</html>`;+ fs.writeFileSync(path.join(reportsDir, 'index.html'), html);+}++export async function publishVibeScreenshots({+ repository,+ token,+ tempRoot,+ remoteURL,+ reportId,+ screenshots,+ manifests,+ maxAttempts = 5,+ beforePush,+}) {+ const report = safeRelativePath(String(reportId), '--report-id');+ const screenshotsDir = path.resolve(screenshots);+ const manifestsDir = path.resolve(manifests);+ if (+ !fs.existsSync(screenshotsDir) ||+ !fs.statSync(screenshotsDir).isDirectory()+ ) {+ refuse('--screenshots must be a directory');+ }+ const destinationRel = `reports/${report}/screenshots`;+ const stageRoot = fs.mkdtempSync(+ path.join(tempRoot, 'vibe-screenshots-stage-'),+ );+ try {+ const stage = path.join(stageRoot, 'screenshots');+ fs.mkdirSync(stage, {recursive: true});+ for (const file of fileList(screenshotsDir)) {+ if (file.endsWith('.png')) {+ fs.copyFileSync(+ path.join(screenshotsDir, file),+ path.join(stage, path.basename(file)),+ );+ }+ }+ const merged = {};+ if (fs.existsSync(manifestsDir)) {+ for (const file of fileList(manifestsDir)) {+ if (path.basename(file) === 'manifest.json') {+ Object.assign(merged, readJSON(path.join(manifestsDir, file)) ?? {});+ }+ }+ }+ fs.writeFileSync(+ path.join(stage, 'manifest.json'),+ `${JSON.stringify(merged, null, 2)}\n`,+ );+ return await publishMutableSubtree({+ repository,+ token,+ tempRoot,+ remoteURL,+ source: stage,+ destination: destinationRel,+ message: `screenshots: ${report} (${fileList(stage).filter(file => file.endsWith('.png')).length} images)`,+ maxAttempts,+ beforePush,+ });+ } finally {+ fs.rmSync(stageRoot, {recursive: true, force: true});+ }+}++export async function publishMutableSubtree({+ repository,+ token,+ tempRoot,+ remoteURL,+ source,+ destination,+ message,+ maxAttempts = 5,+ beforePush,+}) {+ const sourceDir = path.resolve(source);+ const destinationRel = safeRelativePath(destination, '--destination');+ if (!fs.existsSync(sourceDir) || !fs.statSync(sourceDir).isDirectory()) {+ refuse('--source must be a directory');+ }+ for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {+ const checkout = checkoutPages({+ repository,+ token,+ tempRoot,+ remoteURL,+ sparsePaths: [destinationRel],+ prefix: 'gh-pages-subtree-',+ });+ try {+ const destinationDir = path.join(checkout, destinationRel);+ seedScreenshotRetentionIndex(checkout);+ fs.rmSync(destinationDir, {recursive: true, force: true});+ copyContents(sourceDir, destinationDir);+ if (destinationRel.endsWith('/screenshots')) {+ rememberPublishedScreenshots(checkout, destinationRel, sourceDir);+ }+ const commit = commitIfNeeded(+ checkout,+ message ?? `publish ${destinationRel}`,+ ['-A', destinationRel],+ );+ if (commit === null) return {published: false};+ await beforePush?.({attempt, checkout, commit});+ const pushed = tryRun('git', [+ '-C',+ checkout,+ 'push',+ 'origin',+ PAGES_BRANCH,+ ]);+ if (pushOrRetry(pushed)) return {published: true, commit};+ } finally {+ fs.rmSync(checkout, {recursive: true, force: true});+ }+ process.stdout.write(+ `Push rejected; retrying subtree publish (${attempt}/${maxAttempts}).\n`,+ );+ await sleep(attempt * 2000);+ }+ refuse(`could not publish ${destinationRel} after ${maxAttempts} attempts`);+}++export async function compactGhPages({+ repository,+ runId,+ scope,+ token,+ tempRoot,+ remoteURL,+ clearQueueForRun = false,+ maxAttempts = 5,+ beforePush,+}) {+ for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {+ const checkout = checkoutPages({+ repository,+ token,+ tempRoot,+ remoteURL,+ fullHistory: true,+ prefix: 'gh-pages-compact-',+ });+ try {+ const oldHead = git(checkout, 'rev-parse', 'HEAD');+ seedScreenshotRetentionIndex(checkout);+ const expiredScreenshots = expiredReportScreenshots(checkout);+ for (const rel of expiredScreenshots) {+ fs.rmSync(path.join(checkout, rel), {recursive: true, force: true});+ }+ forgetScreenshots(checkout, expiredScreenshots);+ pruneEmptyScreenshotDirs(checkout);+ if (clearQueueForRun) {+ fs.rmSync(path.join(checkout, QUEUE_REL, `${runId}.json`), {+ force: true,+ });+ const holder = path.join(checkout, QUEUE_REL, HOLDER_NAME);+ const held = readJSON(holder);+ if (held?.runId === runId && held?.scope === scope) {+ fs.rmSync(holder, {force: true});+ }+ fs.rmSync(path.join(checkout, LEGACY_BASELINE_QUEUE_REL), {+ recursive: true,+ force: true,+ });+ }+ git(checkout, 'add', '-A');+ configureGitIdentity(checkout);+ const tree = git(checkout, 'write-tree');+ const commit = run('git', [+ '-C',+ checkout,+ 'commit-tree',+ tree,+ '-m',+ `chore: compact ${PAGES_BRANCH} history`,+ ]);+ await beforePush?.({attempt, checkout, commit, oldHead});+ const pushed = tryRun('git', [+ '-C',+ checkout,+ 'push',+ 'origin',+ `--force-with-lease=refs/heads/${PAGES_BRANCH}:${oldHead}`,+ `${commit}:refs/heads/${PAGES_BRANCH}`,+ ]);+ if (pushOrRetry(pushed)) {+ process.stdout.write(+ `Compacted ${PAGES_BRANCH} to ${commit.slice(0, 7)}.\n`,+ );+ return {published: true, commit};+ }+ } finally {+ fs.rmSync(checkout, {recursive: true, force: true});+ }+ process.stdout.write(+ `Push rejected; retrying gh-pages compaction (${attempt}/${maxAttempts}).\n`,+ );+ await sleep(attempt * 2000);+ }+ refuse(`could not compact ${PAGES_BRANCH} after ${maxAttempts} attempts`);+}+export async function publishReleaseGateReport({repository,token,@@ -1842,9 +2505,67 @@ export async function main(argv = process.argv.slice(2)) {actor: flag(argv, '--actor'),prune: flag(argv, '--prune', 'false') === 'true',});+ } else if (command === 'pr-preview') {+ const pr = flag(argv, '--pr');+ await withPublicationTurn({+ ...context,+ scope: `pr-preview/${pr}`,+ publish: () =>+ publishPrPreview({+ ...context,+ pr,+ storybook: flag(argv, '--storybook'),+ sandbox: flag(argv, '--sandbox'),+ }),+ });+ } else if (command === 'cleanup-previews') {+ await withPublicationTurn({+ ...context,+ scope: 'cleanup/previews',+ publish: () =>+ cleanupPreviews({+ ...context,+ dryRun: flag(argv, '--dry-run', 'false') === 'true',+ }),+ });+ } else if (command === 'vibe-report') {+ const reportId = flag(argv, '--report-id');+ await withPublicationTurn({+ ...context,+ scope: 'reports/vibe-report',+ publish: () =>+ publishVibeReport({+ ...context,+ reportId,+ source: flag(argv, '--source'),+ }),+ });+ } else if (command === 'vibe-screenshots') {+ const reportId = flag(argv, '--report-id');+ await withPublicationTurn({+ ...context,+ scope: 'reports/vibe-screenshots',+ publish: () =>+ publishVibeScreenshots({+ ...context,+ reportId,+ screenshots: flag(argv, '--screenshots'),+ manifests: flag(argv, '--manifests'),+ }),+ });+ } else if (command === 'compact') {+ const scope = 'whole-tree';+ await enqueuePublication({...context, scope});+ await waitForPublicationTurn({...context, scope});+ try {+ await compactGhPages({...context, scope, clearQueueForRun: true});+ } catch (error) {+ await releasePublication({...context, scope});+ throw error;+ }} else {refuse(- 'usage: gh-pages-publisher.mjs <enqueue|wait|release|stable-site|release-gate|immutable-path|visual-acceptance-record|visual-baseline-accepted|visual-baseline-manual>',+ 'usage: gh-pages-publisher.mjs <enqueue|wait|release|stable-site|release-gate|immutable-path|visual-acceptance-record|visual-baseline-accepted|visual-baseline-manual|pr-preview|cleanup-previews|vibe-report|vibe-screenshots|compact>',);}}diff --git a/.github/scripts/lib/gh-pages-publisher.test.mjs b/.github/scripts/lib/gh-pages-publisher.test.mjsindex 4fc2b06fc3..ae88f595bd 100644--- a/.github/scripts/lib/gh-pages-publisher.test.mjs+++ b/.github/scripts/lib/gh-pages-publisher.test.mjs@@ -11,10 +11,15 @@ import {afterEach, describe, expect, it} from 'vitest';import {PNG} from 'pngjs';import {+ cleanupPreviews,+ compactGhPages,enqueuePublication,publishAcceptedVisualBaseline,publishImmutablePath,+ publishPrPreview,publishReleaseGateReport,+ publishVibeReport,+ publishVibeScreenshots,publishVisualAcceptanceRecord,publishStableSite,releasePublication,@@ -139,6 +144,12 @@ function fixture() {writeFile(path.join(seed, 'sandbox', 'old.html'), 'old sandbox');writeFile(path.join(seed, 'assets', 'old.css'), 'old asset');writeFile(path.join(seed, 'pr', '123', 'index.html'), 'preview');+ writeFile(path.join(seed, 'pr', '124', 'index.html'), 'closed preview');+ writeFile(+ path.join(seed, 'pr', '123', 'sandbox', 'template-assets', 'old.txt'),+ 'old duplicate asset',+ );+ writeFile(path.join(seed, 'abcdef1', 'index.html'), 'legacy preview');writeFile(path.join(seed, 'reports', 'vibe', 'index.html'), 'vibe');const before = png(255);const after = png(0, 0, 255);@@ -306,6 +317,35 @@ function writeCompetingSharedHolder(remote, root, runId, scope) {git(writer, 'push', '-q', 'origin', 'gh-pages');}+function commitReportScreenshots({remote, root, reportId, files, isoDate}) {+ const writer = cloneRemote(+ remote,+ root,+ `report-shots-${reportId}-${Date.parse(isoDate)}`,+ );+ git(writer, 'config', 'user.name', 'Test');+ git(writer, 'config', 'user.email', '[email protected]');+ for (const [name, bytes] of Object.entries(files)) {+ writeFile(+ path.join(writer, 'reports', reportId, 'screenshots', name),+ bytes,+ );+ }+ git(writer, 'add', '.');+ execFileSync(+ 'git',+ ['-C', writer, 'commit', '-qm', `screenshots ${reportId}`],+ {+ env: {+ ...process.env,+ GIT_AUTHOR_DATE: isoDate,+ GIT_COMMITTER_DATE: isoDate,+ },+ },+ );+ git(writer, 'push', '-q', 'origin', 'gh-pages');+}+function cloneRemote(remote, root, name = 'final') {const checkout = path.join(root, name);git(root, 'clone', '-q', '--branch', 'gh-pages', remote, checkout);@@ -337,6 +377,16 @@ async function queuedPublish(fx, runId, scope, publish) {}}+async function withFixturePath(fx, callback) {+ const previousPath = process.env.PATH;+ process.env.PATH = `${fx.bin}:${previousPath}`;+ try {+ return await callback();+ } finally {+ process.env.PATH = previousPath;+ }+}+async function withoutGitIdentity(callback) {const root = fs.mkdtempSync(path.join(os.tmpdir(), 'git-no-identity-'));const emptyGlobalConfig = path.join(root, 'config');@@ -996,4 +1046,441 @@ describe('gh-pages publisher', () => {mergeSha: MERGE,});});++ it('publishes PR previews without losing reports or visual state', async () => {+ const fx = fixture();+ const storybook = path.join(fx.root, 'preview-storybook');+ const sandbox = path.join(fx.root, 'preview-sandbox');+ writeFile(path.join(storybook, 'index.html'), 'new preview');+ writeFile(path.join(sandbox, 'index.html'), 'new sandbox');+ writeFile(+ path.join(sandbox, 'template-assets', 'ignored.txt'),+ 'shared asset copy',+ );++ await queuedPublish(fx, 940, 'pr-preview/123', () =>+ publishPrPreview({+ ...context(fx, 940, 'pr-preview/123'),+ pr: 123,+ storybook,+ sandbox,+ }),+ );++ const final = cloneRemote(fx.remote, fx.root);+ expect(+ fs.readFileSync(path.join(final, 'pr', '123', 'index.html'), 'utf8'),+ ).toBe('new preview');+ expect(+ fs.readFileSync(+ path.join(final, 'pr', '123', 'sandbox', 'index.html'),+ 'utf8',+ ),+ ).toBe('new sandbox');+ expect(+ fs.existsSync(+ path.join(final, 'pr', '123', 'sandbox', 'template-assets'),+ ),+ ).toBe(false);+ expect(+ fs.readFileSync(+ path.join(final, 'reports', 'vibe', 'index.html'),+ 'utf8',+ ),+ ).toBe('vibe');+ expect(+ fs.existsSync(+ path.join(final, 'visual-gate', 'baseline', 'manifest.json'),+ ),+ ).toBe(true);+ expect(+ fs.existsSync(+ path.join(+ final,+ 'pr',+ '42',+ 'visual',+ HEAD,+ '123',+ '1',+ 'evidence.json',+ ),+ ),+ ).toBe(true);+ });++ it('cleans stale previews without deleting visual evidence or live previews', async () => {+ const fx = fixture();+ await queuedPublish(fx, 941, 'cleanup/previews', () =>+ cleanupPreviews({+ ...context(fx, 941, 'cleanup/previews'),+ openPRs: new Set(['123', '42']),+ }),+ );++ const final = cloneRemote(fx.remote, fx.root);+ expect(fs.existsSync(path.join(final, 'abcdef1'))).toBe(false);+ expect(fs.existsSync(path.join(final, 'pr', '124'))).toBe(false);+ expect(fs.existsSync(path.join(final, 'pr', '123', 'index.html'))).toBe(+ true,+ );+ expect(+ fs.existsSync(+ path.join(final, 'pr', '123', 'sandbox', 'template-assets'),+ ),+ ).toBe(false);+ expect(+ fs.existsSync(+ path.join(+ final,+ 'pr',+ '42',+ 'visual',+ HEAD,+ '123',+ '1',+ 'evidence.json',+ ),+ ),+ ).toBe(true);+ expect(+ fs.existsSync(+ path.join(final, 'visual-gate', 'baseline', 'manifest.json'),+ ),+ ).toBe(true);+ });++ it('publishes vibe screenshots without disturbing previews or baselines', async () => {+ const fx = fixture();+ const screenshots = path.join(fx.root, 'screenshots');+ const manifests = path.join(fx.root, 'manifests');+ writeFile(path.join(screenshots, 'iteration', 'one.png'), png(10));+ writeJSON(path.join(manifests, 'iteration', 'manifest.json'), {+ one: {ok: true},+ });++ await queuedPublish(fx, 942, 'reports/vibe-screenshots', () =>+ publishVibeScreenshots({+ ...context(fx, 942, 'reports/vibe-screenshots'),+ reportId: 'vibe',+ screenshots,+ manifests,+ }),+ );++ const final = cloneRemote(fx.remote, fx.root);+ expect(+ fs.existsSync(+ path.join(final, 'reports', 'vibe', 'screenshots', 'one.png'),+ ),+ ).toBe(true);+ expect(+ JSON.parse(+ fs.readFileSync(+ path.join(final, 'reports', 'vibe', 'screenshots', 'manifest.json'),+ 'utf8',+ ),+ ).one.ok,+ ).toBe(true);+ expect(fs.existsSync(path.join(final, 'pr', '123', 'index.html'))).toBe(+ true,+ );+ expect(+ fs.existsSync(+ path.join(final, 'visual-gate', 'baseline', 'manifest.json'),+ ),+ ).toBe(true);+ });++ it('removes 58-day-old report screenshots while keeping the report page', async () => {+ const fx = fixture();+ commitReportScreenshots({+ remote: fx.remote,+ root: fx.root,+ reportId: 'vibe',+ isoDate: '2026-07-01T00:00:00Z',+ files: {+ 'old.png': png(58),+ 'manifest.json': Buffer.from('{\"old\":true}\n'),+ },+ });++ await queuedPublish(fx, 944, 'cleanup/previews', () =>+ cleanupPreviews({+ ...context(fx, 944, 'cleanup/previews'),+ openPRs: new Set(['123', '42']),+ now: Date.parse('2026-08-28T00:00:00Z'),+ }),+ );++ const final = cloneRemote(fx.remote, fx.root);+ expect(+ fs.existsSync(path.join(final, 'reports', 'vibe', 'index.html')),+ ).toBe(true);+ expect(+ fs.existsSync(path.join(final, 'reports', 'vibe', 'screenshots')),+ ).toBe(false);+ });++ it('compaction drops terminal legacy migration state and preserves active shared queue', async () => {+ const fx = fixture();+ const writer = cloneRemote(fx.remote, fx.root, 'compact-queue-state');+ git(writer, 'config', 'user.name', 'Test');+ git(writer, 'config', 'user.email', '[email protected]');+ writeJSON(+ path.join(writer, 'visual-gate', 'publication-queue', '899.json'),+ {+ version: 1,+ repository: REPO,+ runId: 899,+ },+ );+ writeJSON(+ path.join(writer, 'visual-gate', 'publication-queue', 'holder.json'),+ {+ version: 1,+ repository: REPO,+ runId: 899,+ },+ );+ writeJSON(+ path.join(writer, '.astryx-gh-pages', 'publication-queue', '950.json'),+ {+ version: 1,+ repository: REPO,+ runId: 950,+ scope: 'pr-preview/950',+ },+ );+ git(writer, 'add', '.');+ git(writer, 'commit', '-qm', 'queue state');+ git(writer, 'push', '-q', 'origin', 'gh-pages');++ const turn = context(fx, 943, 'whole-tree');+ await withFixturePath(fx, async () => {+ await enqueuePublication(turn);+ await waitForPublicationTurn(turn);+ await compactGhPages({...turn, clearQueueForRun: true});+ });++ const final = cloneRemote(fx.remote, fx.root);+ expect(+ fs.existsSync(path.join(final, 'visual-gate', 'publication-queue')),+ ).toBe(false);+ expect(+ fs.existsSync(+ path.join(final, '.astryx-gh-pages', 'publication-queue', '950.json'),+ ),+ ).toBe(true);+ expect(+ fs.existsSync(+ path.join(final, '.astryx-gh-pages', 'publication-queue', '943.json'),+ ),+ ).toBe(false);+ });++ it('publishes a vibe report through the shared publisher while preserving screenshots', async () => {+ const fx = fixture();+ const writer = cloneRemote(fx.remote, fx.root, 'existing-report-shots');+ git(writer, 'config', 'user.name', 'Test');+ git(writer, 'config', 'user.email', '[email protected]');+ writeFile(+ path.join(+ writer,+ 'reports',+ 'vibe-report',+ 'screenshots',+ 'existing.png',+ ),+ png(1),+ );+ writeFile(+ path.join(writer, 'reports', 'vibe-report', 'screenshots', 'same.png'),+ 'old bytes',+ );+ git(writer, 'add', '.');+ git(writer, 'commit', '-qm', 'existing screenshots');+ git(writer, 'push', '-q', 'origin', 'gh-pages');+ const source = path.join(fx.root, 'vibe-report-source');+ writeFile(path.join(source, 'index.html'), 'new report');+ writeFile(path.join(source, 'previews', 'case.html'), 'preview');+ writeFile(path.join(source, 'screenshots', 'same.png'), 'new bytes');++ await queuedPublish(fx, 945, 'reports/vibe-report', () =>+ publishVibeReport({+ ...context(fx, 945, 'reports/vibe-report'),+ reportId: 'vibe-report',+ source,+ }),+ );++ const final = cloneRemote(fx.remote, fx.root);+ expect(+ fs.readFileSync(+ path.join(final, 'reports', 'vibe-report', 'index.html'),+ 'utf8',+ ),+ ).toBe('new report');+ expect(+ fs.existsSync(+ path.join(+ final,+ 'reports',+ 'vibe-report',+ 'screenshots',+ 'existing.png',+ ),+ ),+ ).toBe(true);+ expect(+ fs.readFileSync(+ path.join(final, 'reports', 'vibe-report', 'screenshots', 'same.png'),+ 'utf8',+ ),+ ).toBe('new bytes');+ expect(fs.existsSync(path.join(final, 'reports', 'index.html'))).toBe(true);+ });++ it('keeps screenshot ages stable across repeated production compactions', async () => {+ const fx = fixture();+ commitReportScreenshots({+ remote: fx.remote,+ root: fx.root,+ reportId: 'old-report',+ isoDate: '2026-08-20T00:00:00Z',+ files: {'old.png': png(58)},+ });+ commitReportScreenshots({+ remote: fx.remote,+ root: fx.root,+ reportId: 'recent-report',+ isoDate: '2026-09-15T00:00:00Z',+ files: {'recent.png': png(8)},+ });++ for (const [index, isoDate] of [+ '2026-08-28T00:00:00Z',+ '2026-09-04T00:00:00Z',+ '2026-09-11T00:00:00Z',+ '2026-09-18T00:00:00Z',+ ].entries()) {+ const compactTurn = context(fx, 946 + index, 'whole-tree');+ await withFixturePath(fx, () =>+ withoutGitIdentity(async () => {+ await enqueuePublication(compactTurn);+ await waitForPublicationTurn(compactTurn);+ const previousNow = process.env.ASTRYX_GH_PAGES_NOW_MS;+ process.env.ASTRYX_GH_PAGES_NOW_MS = String(Date.parse(isoDate));+ try {+ await compactGhPages({...compactTurn, clearQueueForRun: true});+ } finally {+ if (previousNow === undefined) {+ delete process.env.ASTRYX_GH_PAGES_NOW_MS;+ } else {+ process.env.ASTRYX_GH_PAGES_NOW_MS = previousNow;+ }+ }+ }),+ );+ const afterCompact = cloneRemote(+ fx.remote,+ fx.root,+ `after-compact-${index}`,+ );+ expect(+ fs.existsSync(+ path.join(afterCompact, 'visual-gate', 'publication-queue'),+ ),+ ).toBe(false);+ expect(+ fs.existsSync(+ path.join(+ afterCompact,+ 'reports',+ 'old-report',+ 'screenshots',+ 'old.png',+ ),+ ),+ ).toBe(true);+ expect(+ fs.existsSync(+ path.join(+ afterCompact,+ 'reports',+ 'recent-report',+ 'screenshots',+ 'recent.png',+ ),+ ),+ ).toBe(true);+ }++ await queuedPublish(fx, 951, 'cleanup/previews', () =>+ cleanupPreviews({+ ...context(fx, 951, 'cleanup/previews'),+ openPRs: new Set(['123', '42']),+ now: Date.parse('2026-09-21T00:00:00Z'),+ }),+ );++ const final = cloneRemote(fx.remote, fx.root);+ expect(+ fs.existsSync(path.join(final, 'reports', 'old-report', 'screenshots')),+ ).toBe(false);+ expect(+ fs.existsSync(+ path.join(+ final,+ 'reports',+ 'recent-report',+ 'screenshots',+ 'recent.png',+ ),+ ),+ ).toBe(true);+ expect(+ fs.existsSync(path.join(final, 'visual-gate', 'publication-queue')),+ ).toBe(false);+ });++ it('compacts the whole gh-pages tree without dropping scoped content', async () => {+ const fx = fixture();+ const turn = context(fx, 943, 'whole-tree');+ await withFixturePath(fx, () =>+ withoutGitIdentity(async () => {+ await enqueuePublication(turn);+ await waitForPublicationTurn(turn);+ await compactGhPages({...turn, clearQueueForRun: true});+ }),+ );++ const final = cloneRemote(fx.remote, fx.root);+ expect(git(final, 'rev-list', '--count', 'HEAD')).toBe('1');+ expect(fs.existsSync(path.join(final, 'pr', '123', 'index.html'))).toBe(+ true,+ );+ expect(+ fs.existsSync(+ path.join(+ final,+ 'pr',+ '42',+ 'visual',+ HEAD,+ '123',+ '1',+ 'evidence.json',+ ),+ ),+ ).toBe(true);+ expect(+ fs.existsSync(+ path.join(final, 'visual-gate', 'baseline', 'manifest.json'),+ ),+ ).toBe(true);+ expect(+ fs.existsSync(path.join(final, 'reports', 'vibe', 'index.html')),+ ).toBe(true);+ });});diff --git a/.github/scripts/visual-gate/workflow-concurrency.test.mjs b/.github/scripts/visual-gate/workflow-concurrency.test.mjsindex 23bd380489..2ea615c8b7 100644--- a/.github/scripts/visual-gate/workflow-concurrency.test.mjs+++ b/.github/scripts/visual-gate/workflow-concurrency.test.mjs@@ -339,6 +339,105 @@ describe('visual acceptance workflow concurrency', () => {expect(promoteJob).toContain('contents: write');});+ it('resolves automatic previews from trusted API state before checking artifacts', () => {+ const value = workflow('deploy-preview.yml');+ const resolve = value.indexOf('Resolve trusted preview target');+ const metadata = value.indexOf('Download PR metadata from the CI run');+ const crossCheck = value.indexOf('Cross-check artifact identity');++ expect(value).toContain("run.conclusion !== 'success'");+ expect(value).toContain('pr.draft');+ expect(value).toContain('listPullRequestsAssociatedWithCommit');+ expect(value).toContain('pr.head?.sha === run.head_sha');+ expect(value).toContain('pr.head?.repo?.id');+ expect(value).not.toContain('PR_NUMBER="$(jq');+ expect(resolve).toBeGreaterThan(-1);+ expect(resolve).toBeLessThan(metadata);+ expect(metadata).toBeLessThan(crossCheck);+ expect(value).toContain('artifact PR number does not match trusted PR');+ expect(value).toContain('artifact head does not match trusted PR head');+ expect(value).toContain('steps.preview.outputs.ready');+ expect(value).toContain('steps.artifact.outputs.ready');+ });++ it('rechecks trusted preview readiness immediately before publishing', () => {+ const value = workflow('deploy-preview.yml');+ const verify = value.indexOf('Verify preview artifacts are present');+ const final = value.indexOf('Confirm preview target before publish');+ const publish = value.indexOf('Deploy PR preview to GitHub Pages');+ const finalBlock = value.slice(final, publish);+ const publishBlock = value.slice(publish);++ expect(final).toBeGreaterThan(verify);+ expect(final).toBeLessThan(publish);+ expect(finalBlock).toContain("pr.state !== 'open'");+ expect(finalBlock).toContain('pr.draft');+ expect(finalBlock).toContain('pr.head.sha !== process.env.HEAD_SHA');+ expect(finalBlock).toContain('pr.head.ref !== process.env.HEAD_REF');+ expect(finalBlock).toContain('pr.head.repo?.id');+ expect(publishBlock).toContain(+ "if: steps.final-preview.outputs.ready == 'true'",+ );+ });++ it('keeps every remaining gh-pages writer behind the shared publisher', () => {+ const files = [+ '.github/workflows/deploy-preview.yml',+ '.github/workflows/redeploy-preview.yml',+ '.github/workflows/cleanup-previews.yml',+ '.github/workflows/compact-gh-pages.yml',+ '.github/workflows/vibe-screenshots.yml',+ 'internal/vibe-tests/src/deploy-report.ts',+ ];+ const combined = files+ .map(file => fs.readFileSync(path.join(ROOT, file), 'utf8'))+ .join('\n');+ expect(combined).toContain('gh-pages-publisher.mjs');+ expect(combined).not.toContain('git push origin gh-pages');+ expect(combined).not.toContain('ref: gh-pages');+ expect(combined).not.toContain('git clone --depth 1 --branch gh-pages');+ });++ it('grants remaining publisher jobs read access to overlapping workflow runs', () => {+ const jobs = [+ [workflow('cleanup-previews.yml'), ' cleanup:'],+ [workflow('compact-gh-pages.yml'), ' compact:'],+ [workflow('vibe-screenshots.yml'), ' deploy-screenshots:'],+ ];+ for (const [value, jobName] of jobs) {+ const job = value.slice(+ value.indexOf(jobName),+ value.indexOf(' steps:', value.indexOf(jobName)),+ );+ expect(job).toContain('actions: read');+ expect(job).toContain('contents: write');+ }+ });++ it('routes previews, cleanup, compaction, and vibe screenshots through the shared publisher', () => {+ const deployPreview = workflow('deploy-preview.yml');+ const redeployPreview = workflow('redeploy-preview.yml');+ const cleanup = workflow('cleanup-previews.yml');+ const compact = workflow('compact-gh-pages.yml');+ const vibe = workflow('vibe-screenshots.yml');++ expect(deployPreview).toContain('gh-pages-publisher.mjs pr-preview');+ expect(redeployPreview).toContain('gh-pages-publisher.mjs pr-preview');+ expect(cleanup).toContain('gh-pages-publisher.mjs cleanup-previews');+ expect(compact).toContain('gh-pages-publisher.mjs compact');+ expect(vibe).toContain('gh-pages-publisher.mjs vibe-screenshots');+ for (const value of [+ deployPreview,+ redeployPreview,+ cleanup,+ compact,+ vibe,+ ]) {+ expect(value).not.toContain('git push origin gh-pages');+ expect(value).not.toContain('ref: gh-pages');+ }+ });+it('projects every known validation or publication failure from an always-running job', () => {const value = workflow('visual-acceptance-promote.yml');const status = value.slice(value.indexOf(' project-status:'));diff --git a/.github/workflows/cleanup-previews.yml b/.github/workflows/cleanup-previews.ymlindex 6047f2fab6..8d5df9fa51 100644--- a/.github/workflows/cleanup-previews.yml+++ b/.github/workflows/cleanup-previews.yml@@ -25,7 +25,7 @@ on:schedule:- cron: '0 6 * * *' # Daily 6am UTCworkflow_run:- workflows: ["CI"]+ workflows: ['CI']types: [completed]workflow_dispatch:inputs:@@ -43,7 +43,7 @@ permissions: {}# per group), leaving the site stale. Races against deploy.yml are handled by# the push retry below instead.concurrency:- group: "cleanup-previews"+ group: 'cleanup-previews'cancel-in-progress: falsejobs:@@ -56,233 +56,17 @@ jobs:github.event.workflow_run.event == 'pull_request'runs-on: ubuntu-slimpermissions:+ actions: readcontents: writepull-requests: readsteps:- - name: Checkout gh-pages+ - name: Checkout publisheruses: actions/checkout@v7- with:- ref: gh-pages- fetch-depth: 1- name: Cleanup stale deployments- shell: bashenv:- GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}DRY_RUN: ${{ inputs.dry_run || 'false' }}- run: |- # ---------------------------------------------------------------- # gh-pages layout:- # /storybook/ — stable (managed by deploy.yml, never cleaned)- # /sandbox/ — stable (managed by deploy.yml, never cleaned)- # /pr/<number>/ — PR previews (cleaned when PR closes)- # /reports/ — vibe test reports (never cleaned)- # /visual-gate/ — visual baseline + gate reports (never cleaned- # here; release-gate.yml prunes its own old runs,- # and the baseline under visual-gate/baseline/ is- # the reference the gate compares against — losing- # it silently disarms visual regression testing)- # /assets/ — landing page CSS (never cleaned)- # /index.html — landing page (never cleaned)- # /latest — deploy hash pointer (never cleaned)- #- # Legacy: 7-char hex dirs from old deploy format are always deleted.- # ----------------------------------------------------------------- echo "Dry run: ${DRY_RUN}"- echo ""-- DELETED=0- # Every deleted path is recorded so the push-retry below can replay- # the removals on top of a refreshed gh-pages tip.- DELETED_PATHS=()-- # ----- Clean legacy hash directories ------ # Old deploy format put previews at /<7-char-hex>/. These are all- # stale now that PRs deploy to /pr/<number>/.- mapfile -t HASH_DIRS < <(ls -d [0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f] 2>/dev/null)- if [ ${#HASH_DIRS[@]} -gt 0 ]; then- echo "Found ${#HASH_DIRS[@]} legacy hash directories — removing all"- for dir in "${HASH_DIRS[@]}"; do- echo " DELETE ${dir} (legacy)"- if [ "$DRY_RUN" != "true" ]; then- git rm -rf --quiet "$dir"- fi- DELETED_PATHS+=("$dir")- DELETED=$((DELETED + 1))- done- echo ""- fi-- # ----- Clean closed PR previews ------ if [ -d "pr" ]; then- mapfile -t PR_DIRS < <(ls pr/ 2>/dev/null)- echo "Found ${#PR_DIRS[@]} PR preview(s)"-- # Get open PR numbers. --limit is REQUIRED: `gh pr list` defaults to- # 30 results, so without it any still-open PR outside the newest 30- # is absent from this list, mistaken for closed, and its preview- # wrongly deleted. The repo routinely has >100 open PRs, so cap high.- #- # A failed/empty fetch is fatal to guard against: if OPEN_PRS is- # empty, every preview looks "closed" and the whole pr/ tree gets- # deleted. Only proceed when we have a confirmed non-empty list.- if OPEN_PRS=$(gh pr list --repo "$GITHUB_REPOSITORY" --state open --limit 1000 --json number --jq '.[].number'); then- OPEN_PR_COUNT=$(echo "$OPEN_PRS" | grep -c '[0-9]' || true)- else- OPEN_PR_COUNT=0- fi-- if [ "$OPEN_PR_COUNT" -eq 0 ]; then- echo " Could not fetch open PRs (or none open) — skipping PR cleanup this run to avoid mass-deleting live previews"- PR_DIRS=()- fi-- for pr_num in "${PR_DIRS[@]}"; do- if echo "$OPEN_PRS" | grep -qx "$pr_num"; then- echo " KEEP pr/${pr_num} — open"- else- echo " DELETE pr/${pr_num} — closed/merged"- if [ "$DRY_RUN" != "true" ]; then- git rm -rf --quiet "pr/${pr_num}"- fi- DELETED_PATHS+=("pr/${pr_num}")- DELETED=$((DELETED + 1))- fi- done- echo ""- fi-- # ----- Drop template-assets from previews ------ # Every preview uses the one shared /sandbox/template-assets copy.- # Sweep duplicate copies left by earlier deploys.- if [ -d "pr" ]; then- TA_PURGED=0- for ta in pr/*/sandbox/template-assets; do- [ -d "$ta" ] || continue- echo " DELETE ${ta} (duplicate preview copy)"- if [ "$DRY_RUN" != "true" ]; then- git rm -rf --quiet "$ta"- fi- DELETED_PATHS+=("$ta")- TA_PURGED=$((TA_PURGED + 1))- DELETED=$((DELETED + 1))- done- if [ "$TA_PURGED" -gt 0 ]; then- echo "Purged template-assets from ${TA_PURGED} preview(s)"- echo ""- fi- fi-- # ----- Clean stale root-level files ------ # Leftovers from old Storybook-at-root deploy format- ROOT_STALE=0- for item in favicon.svg iframe.html index.json project.json \- nunito-sans-bold-italic.woff2 nunito-sans-bold.woff2 \- nunito-sans-italic.woff2 nunito-sans-regular.woff2 \- sb-addons sb-common-assets sb-manager; do- if [ -e "$item" ]; then- echo " DELETE root/$item (stale)"- if [ "$DRY_RUN" != "true" ]; then- git rm -rf --quiet "$item"- fi- DELETED_PATHS+=("$item")- ROOT_STALE=$((ROOT_STALE + 1))- DELETED=$((DELETED + 1))- fi- done- if [ "$ROOT_STALE" -gt 0 ]; then- echo "Cleaned ${ROOT_STALE} stale root-level items"- echo ""- fi-- # ----- Clean old report screenshots ------ # Screenshots are large (~30 per report). Purge them from reports- # older than 30 days to control gh-pages size. The report HTML- # (index.html) and previews are tiny — keep those forever.- if [ -d "reports" ]; then- SCREENSHOT_PURGED=0- CUTOFF_DATE=$(date -d "30 days ago" +%s 2>/dev/null || date -v-30d +%s 2>/dev/null || echo "0")- if [ "$CUTOFF_DATE" != "0" ]; then- for report_dir in reports/*/; do- screenshots_dir="${report_dir}screenshots"- if [ -d "$screenshots_dir" ]; then- # Use the git commit date for the screenshots directory- COMMIT_DATE=$(git log -1 --format="%ct" -- "$screenshots_dir" 2>/dev/null || echo "0")- if [ "$COMMIT_DATE" != "0" ] && [ "$COMMIT_DATE" -lt "$CUTOFF_DATE" ]; then- REPORT_NAME=$(basename "$report_dir")- PNG_COUNT=$(find "$screenshots_dir" -name '*.png' 2>/dev/null | wc -l)- echo " DELETE ${screenshots_dir} — ${PNG_COUNT} screenshots older than 30 days"- if [ "$DRY_RUN" != "true" ]; then- git rm -rf --quiet "$screenshots_dir"- fi- DELETED_PATHS+=("$screenshots_dir")- SCREENSHOT_PURGED=$((SCREENSHOT_PURGED + 1))- DELETED=$((DELETED + 1))- fi- fi- done- if [ "$SCREENSHOT_PURGED" -gt 0 ]; then- echo "Purged screenshots from ${SCREENSHOT_PURGED} old reports"- echo ""- fi- fi- fi-- # ----- Summary ------ echo "Summary: ${DELETED} items deleted"-- if [ "$DRY_RUN" = "true" ]; then- echo "Dry run — no changes committed"- exit 0- fi-- if [ "$DELETED" -eq 0 ]; then- echo "Nothing to clean up"- exit 0- fi-- git config user.name "github-actions[bot]"- git config user.email "github-actions[bot]@users.noreply.github.com"-- # Push with retry. gh-pages has concurrent writers — most notably- # deploy.yml, which force-orphan pushes on every main push, i.e.- # exactly when a merged PR also fires this workflow — so a plain- # push loses that race with "[rejected] (fetch first)". Because- # force_orphan rewrites history, a rebase can't recover; instead- # reset to the fresh remote tip and replay the recorded deletions- # on top of it. deploy.yml preserves pr/ and reports/ across- # deploys, so the stale paths are still there to delete.- MAX_ATTEMPTS=5- for attempt in $(seq 1 $MAX_ATTEMPTS); do- if [ "$attempt" -gt 1 ]; then- echo "Push rejected (concurrent gh-pages update) — retrying in $((attempt * 2))s"- sleep $((attempt * 2))- git fetch --depth=1 origin gh-pages- git reset --hard FETCH_HEAD- git rm -r -f -q --ignore-unmatch -- "${DELETED_PATHS[@]}"- if git diff --cached --quiet; then- echo "Stale paths already removed upstream — nothing left to push"- exit 0- fi- fi-- git commit -m "chore: cleanup ${DELETED} stale deployments"- PUSH_OUT=$(git push origin gh-pages 2>&1) && {- echo "Pushed cleanup commit"- exit 0- }- echo "$PUSH_OUT"-- # A 403/permission denial is not a race — retrying can never fix it- # (this is exactly what broke fork PRs before the workflow_run- # migration). Fail fast with the real cause instead of burning all- # attempts behind a misleading "concurrent update" message.- if echo "$PUSH_OUT" | grep -qiE 'denied|403|permission|not authorized'; then- echo "::error::Push to gh-pages denied (403/permissions) — not a race, aborting. Ensure this job runs with the base-repo write token (workflow_run), not a fork's read-only token."- exit 1- fi- done-- echo "::error::Failed to push cleanup after ${MAX_ATTEMPTS} attempts"- exit 1+ run: >+ node .github/scripts/gh-pages-publisher.mjs cleanup-previews+ --dry-run "$DRY_RUN"diff --git a/.github/workflows/compact-gh-pages.yml b/.github/workflows/compact-gh-pages.ymlindex 7345305f6b..3d374e0114 100644--- a/.github/workflows/compact-gh-pages.yml+++ b/.github/workflows/compact-gh-pages.yml@@ -10,13 +10,14 @@ on:permissions: {}concurrency:- group: "pages-deploy"+ group: 'pages-deploy'cancel-in-progress: falsejobs:compact:runs-on: ubuntu-slimpermissions:+ actions: readcontents: writesteps:- name: Checkout maintenance scripts@@ -27,4 +28,4 @@ jobs:- name: Compact gh-pages historyenv:GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}- run: .github/scripts/compact-gh-pages-history.sh+ run: node .github/scripts/gh-pages-publisher.mjs compactdiff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.ymlindex fc2b170aea..2004bb247b 100644--- a/.github/workflows/deploy-preview.yml+++ b/.github/workflows/deploy-preview.yml@@ -18,7 +18,7 @@ name: Deploy PR Previewon:workflow_run:- workflows: ["CI"]+ workflows: ['CI']types: [completed]permissions: {}@@ -29,7 +29,7 @@ permissions: {}# available in workflow_run context (the PR number isn't known until we parse the# artifact). Not cancel-in-progress: let an in-flight deploy finish its push.concurrency:- group: "pr-preview-${{ github.event.workflow_run.head_branch }}"+ group: 'pr-preview-${{ github.event.workflow_run.head_branch }}'cancel-in-progress: falsejobs:@@ -38,10 +38,65 @@ jobs:if: github.event.workflow_run.event == 'pull_request'runs-on: ubuntu-slimpermissions:- contents: writeactions: read+ contents: write+ pull-requests: readsteps:+ - name: Checkout publisher+ uses: actions/checkout@v7+ with:+ ref: main++ - name: Resolve trusted preview target+ id: preview+ uses: actions/github-script@v9+ with:+ retries: 3+ script: |+ const run = context.payload.workflow_run;+ const {owner, repo} = context.repo;+ if (run.conclusion !== 'success') {+ core.info(`CI run ${run.id} concluded ${run.conclusion}; preview deploy is not ready.`);+ core.setOutput('ready', 'false');+ return;+ }+ const pullByNumber = async number =>+ (await github.rest.pulls.get({owner, repo, pull_number: number})).data;+ let candidates = [];+ for (const pr of run.pull_requests ?? []) {+ if (pr.number) candidates.push(await pullByNumber(pr.number));+ }+ if (candidates.length === 0) {+ candidates = await github.paginate(+ github.rest.repos.listPullRequestsAssociatedWithCommit,+ {owner, repo, commit_sha: run.head_sha, per_page: 100},+ );+ }+ const matches = candidates.filter(pr =>+ pr.state === 'open' &&+ pr.head?.sha === run.head_sha &&+ pr.head?.ref === run.head_branch &&+ String(pr.head?.repo?.id ?? '') === String(run.head_repository?.id ?? ''),+ );+ if (matches.length !== 1) {+ core.setFailed(`Could not resolve one open PR for CI run ${run.id} at ${run.head_sha}.`);+ return;+ }+ const pr = matches[0];+ if (pr.draft) {+ core.info(`PR #${pr.number} is draft; preview deploy is not ready.`);+ core.setOutput('ready', 'false');+ return;+ }+ core.setOutput('ready', 'true');+ core.setOutput('pr_number', String(pr.number));+ core.setOutput('head_sha', pr.head.sha);+ core.setOutput('head_repo_id', String(pr.head.repo.id));+ core.setOutput('head_ref', pr.head.ref);+ core.setOutput('short_hash', pr.head.sha.slice(0, 7));+- name: Download PR metadata from the CI run+ if: steps.preview.outputs.ready == 'true'id: metauses: actions/download-artifact@v8with:@@ -51,41 +106,37 @@ jobs:github-token: ${{ secrets.GITHUB_TOKEN }}continue-on-error: true- - name: Parse PR metadata- id: parse+ - name: Cross-check artifact identity+ id: artifact+ if: steps.preview.outputs.ready == 'true'+ env:+ EXPECTED_PR: ${{ steps.preview.outputs.pr_number }}+ EXPECTED_HEAD: ${{ steps.preview.outputs.head_sha }}+ EXPECTED_RUN: ${{ github.event.workflow_run.id }}run: |- # The pr-analysis artifact (with pr-meta.json) is only produced for- # non-docsite-only PRs. Absent -> nothing to deploy, exit quietly.if [ ! -f pr-analysis/pr-meta.json ]; then- echo "No pr-meta.json — docsite-only or skipped PR, nothing to deploy."- echo "deploy=false" >> "$GITHUB_OUTPUT"+ echo "ready=false" >> "$GITHUB_OUTPUT"+ echo "::warning::No pr-meta.json — docsite-only or skipped PR, nothing to deploy."exit 0fi-- PR_NUMBER="$(jq -r '.prNumber // ""' pr-analysis/pr-meta.json)"- SHORT_HASH="$(jq -r '.shortHash // ""' pr-analysis/pr-meta.json)"-- # Validate PR number is digits and hash is hex — these name a- # gh-pages path and artifacts, so reject anything unexpected.- if ! echo "$PR_NUMBER" | grep -qE '^[0-9]+$'; then- echo "::error::Invalid or missing PR number in metadata"- exit 1- fi- if ! echo "$SHORT_HASH" | grep -qE '^[0-9a-f]{7,40}$'; then- echo "::error::Invalid or missing short hash in metadata"- exit 1- fi-- echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"- echo "short_hash=$SHORT_HASH" >> "$GITHUB_OUTPUT"- echo "deploy=true" >> "$GITHUB_OUTPUT"+ node - <<'NODE'+ const fs = require('node:fs');+ const meta = JSON.parse(fs.readFileSync('pr-analysis/pr-meta.json', 'utf8'));+ const fail = message => { console.error(`::error::${message}`); process.exit(1); };+ if (String(meta.prNumber) !== process.env.EXPECTED_PR) fail('artifact PR number does not match trusted PR');+ const shortHash = String(meta.shortHash ?? '');+ if (!/^[0-9a-f]{7,40}$/.test(shortHash)) fail('artifact head is not a valid hash');+ if (!process.env.EXPECTED_HEAD.startsWith(shortHash)) fail('artifact head does not match trusted PR head');+ if (String(meta.runId) !== process.env.EXPECTED_RUN) fail('artifact run id does not match workflow_run');+ fs.appendFileSync(process.env.GITHUB_OUTPUT, 'ready=true\n');+ NODE- name: Download Storybook artifactid: dl-storybook- if: steps.parse.outputs.deploy == 'true'+ if: steps.preview.outputs.ready == 'true' && steps.artifact.outputs.ready == 'true'uses: actions/download-artifact@v8with:- name: storybook-${{ steps.parse.outputs.short_hash }}+ name: storybook-${{ steps.preview.outputs.short_hash }}path: storybook-distrun-id: ${{ github.event.workflow_run.id }}github-token: ${{ secrets.GITHUB_TOKEN }}@@ -96,10 +147,10 @@ jobs:- name: Download Sandbox artifactid: dl-sandbox- if: steps.parse.outputs.deploy == 'true'+ if: steps.preview.outputs.ready == 'true' && steps.artifact.outputs.ready == 'true'uses: actions/download-artifact@v8with:- name: sandbox-${{ steps.parse.outputs.short_hash }}+ name: sandbox-${{ steps.preview.outputs.short_hash }}path: sandbox-distrun-id: ${{ github.event.workflow_run.id }}github-token: ${{ secrets.GITHUB_TOKEN }}@@ -107,7 +158,7 @@ jobs:- name: Verify preview artifacts are presentid: verify- if: steps.parse.outputs.deploy == 'true'+ if: steps.preview.outputs.ready == 'true' && steps.artifact.outputs.ready == 'true'run: |# A missing/expired artifact is not an error — deploy is best-effort.# Skip cleanly (green) with a warning rather than failing CI for every@@ -120,52 +171,47 @@ jobs:echo "::warning::Preview artifacts missing or empty (likely expired past retention) — skipping preview deploy for this run."fi+ - name: Confirm preview target before publish+ id: final-preview+ if: >-+ steps.preview.outputs.ready == 'true' &&+ steps.artifact.outputs.ready == 'true' &&+ steps.verify.outputs.ready == 'true'+ uses: actions/github-script@v9+ env:+ PR_NUMBER: ${{ steps.preview.outputs.pr_number }}+ HEAD_SHA: ${{ steps.preview.outputs.head_sha }}+ HEAD_REF: ${{ steps.preview.outputs.head_ref }}+ HEAD_REPO_ID: ${{ steps.preview.outputs.head_repo_id }}+ with:+ retries: 3+ script: |+ const {owner, repo} = context.repo;+ const pr = (await github.rest.pulls.get({+ owner,+ repo,+ pull_number: Number(process.env.PR_NUMBER),+ })).data;+ if (+ pr.state !== 'open' ||+ pr.draft ||+ pr.head.sha !== process.env.HEAD_SHA ||+ pr.head.ref !== process.env.HEAD_REF ||+ String(pr.head.repo?.id ?? '') !== process.env.HEAD_REPO_ID+ ) {+ core.info(`PR #${process.env.PR_NUMBER} is no longer the trusted preview target.`);+ core.setOutput('ready', 'false');+ return;+ }+ core.setOutput('ready', 'true');+- name: Deploy PR preview to GitHub Pages- if: steps.parse.outputs.deploy == 'true' && steps.verify.outputs.ready == 'true'+ if: steps.final-preview.outputs.ready == 'true'env:GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}- PR_NUMBER: ${{ steps.parse.outputs.pr_number }}- run: |- # Manual git push with retry-on-conflict (not peaceiris/actions-gh-pages)- # so a concurrent main deploy or another PR preview push just retries- # rather than failing. Copies pre-built static output only — never- # builds or runs PR code.- REPO_URL="https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git"- MAX_ATTEMPTS=5- WORK_DIR="$PWD"-- git config --global user.name "github-actions[bot]"- git config --global user.email "github-actions[bot]@users.noreply.github.com"-- for attempt in $(seq 1 $MAX_ATTEMPTS); do- echo "::group::Attempt $attempt of $MAX_ATTEMPTS"- cd "$WORK_DIR"-- rm -rf /tmp/gh-pages- git clone --depth=1 --single-branch --branch gh-pages "$REPO_URL" /tmp/gh-pages-- rm -rf /tmp/gh-pages/pr/${PR_NUMBER}- mkdir -p /tmp/gh-pages/pr/${PR_NUMBER}- cp -r storybook-dist/* /tmp/gh-pages/pr/${PR_NUMBER}/- mkdir -p /tmp/gh-pages/pr/${PR_NUMBER}/sandbox- # Every preview points at the one shared main-sandbox asset copy.- find sandbox-dist -mindepth 1 -maxdepth 1 ! -name template-assets \- -exec cp -r {} /tmp/gh-pages/pr/${PR_NUMBER}/sandbox/ \;-- cd /tmp/gh-pages- git add -A- git commit -m "Deploy PR #${PR_NUMBER} preview" || { echo "Nothing to commit"; echo "::endgroup::"; exit 0; }-- if git push origin gh-pages; then- echo "Deployed successfully on attempt $attempt"- echo "::endgroup::"- exit 0- fi-- echo "Push failed (likely concurrent update), retrying in $((attempt * 2))s..."- echo "::endgroup::"- sleep $((attempt * 2))- done-- echo "::error::Failed to deploy PR preview after $MAX_ATTEMPTS attempts"- exit 1+ PR_NUMBER: ${{ steps.preview.outputs.pr_number }}+ run: >+ node .github/scripts/gh-pages-publisher.mjs pr-preview+ --pr "$PR_NUMBER"+ --storybook storybook-dist+ --sandbox sandbox-distdiff --git a/.github/workflows/redeploy-preview.yml b/.github/workflows/redeploy-preview.ymlindex acd9f94cdd..813ea94478 100644--- a/.github/workflows/redeploy-preview.yml+++ b/.github/workflows/redeploy-preview.yml@@ -21,14 +21,14 @@ on:workflow_dispatch:inputs:pr_number:- description: "PR number to re-deploy preview for"+ description: 'PR number to re-deploy preview for'required: truetype: stringpermissions: {}concurrency:- group: "pr-preview-${{ github.event.inputs.pr_number }}"+ group: 'pr-preview-${{ github.event.inputs.pr_number }}'cancel-in-progress: truejobs:@@ -104,44 +104,9 @@ jobs:- name: Deploy to GitHub Pagesenv:GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}- run: |- # Copies pre-built static output only — never builds or runs PR code.- REPO_URL="https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git"- MAX_ATTEMPTS=5- WORK_DIR="$PWD"-- git config --global user.name "github-actions[bot]"- git config --global user.email "github-actions[bot]@users.noreply.github.com"-- for attempt in $(seq 1 $MAX_ATTEMPTS); do- echo "::group::Attempt $attempt of $MAX_ATTEMPTS"- cd "$WORK_DIR"-- rm -rf /tmp/gh-pages- git clone --depth=1 --single-branch --branch gh-pages "$REPO_URL" /tmp/gh-pages-- rm -rf /tmp/gh-pages/pr/${PR_NUMBER}- mkdir -p /tmp/gh-pages/pr/${PR_NUMBER}- cp -r storybook-dist/* /tmp/gh-pages/pr/${PR_NUMBER}/- mkdir -p /tmp/gh-pages/pr/${PR_NUMBER}/sandbox- # Every preview points at the one shared main-sandbox asset copy.- find sandbox-dist -mindepth 1 -maxdepth 1 ! -name template-assets \- -exec cp -r {} /tmp/gh-pages/pr/${PR_NUMBER}/sandbox/ \;-- cd /tmp/gh-pages- git add -A- git commit -m "Deploy PR #${PR_NUMBER} preview" || { echo "Nothing to commit"; echo "::endgroup::"; exit 0; }-- if git push origin gh-pages; then- echo "Deployed successfully on attempt $attempt"- echo "::endgroup::"- exit 0- fi-- echo "Push failed (likely concurrent update), retrying in $((attempt * 2))s..."- echo "::endgroup::"- sleep $((attempt * 2))- done-- echo "::error::Failed to deploy PR preview after $MAX_ATTEMPTS attempts"- exit 1+ PR_NUMBER: ${{ github.event.inputs.pr_number }}+ run: >+ node .github/scripts/gh-pages-publisher.mjs pr-preview+ --pr "$PR_NUMBER"+ --storybook storybook-dist+ --sandbox sandbox-distdiff --git a/.github/workflows/vibe-screenshots.yml b/.github/workflows/vibe-screenshots.ymlindex cfebf3e7a2..c85f870cc1 100644--- a/.github/workflows/vibe-screenshots.yml+++ b/.github/workflows/vibe-screenshots.yml@@ -113,13 +113,11 @@ jobs:if: ${{ github.event.inputs.deploy_to_gh_pages != 'false' }}runs-on: ubuntu-slimpermissions:+ actions: readcontents: writesteps:- - name: Checkout gh-pages+ - name: Checkout publisheruses: actions/checkout@v7- with:- ref: gh-pages- fetch-depth: 1- name: Determine report iterationid: report-id@@ -147,53 +145,9 @@ jobs:- name: Deploy screenshots to report directoryenv:REPORT_ID: ${{ steps.report-id.outputs.id }}- run: |- REPORT_DIR="reports/${REPORT_ID}"-- # Create screenshots directory in the report- mkdir -p "${REPORT_DIR}/screenshots"-- # Copy all screenshot PNGs from all iterations- find /tmp/screenshots -name '*.png' -exec cp {} "${REPORT_DIR}/screenshots/" \;-- # Merge all manifest.json files into one- # Each iteration has its own manifest — merge them- node -e "- const fs = require('fs');- const path = require('path');- const merged = {};- const manifests = [];- const walkDir = (dir) => {- for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {- const fullPath = path.join(dir, entry.name);- if (entry.isDirectory()) walkDir(fullPath);- else if (entry.name === 'manifest.json') manifests.push(fullPath);- }- };- walkDir('/tmp/manifests');- for (const f of manifests) {- const data = JSON.parse(fs.readFileSync(f, 'utf-8'));- Object.assign(merged, data);- }- const outDir = 'reports/${REPORT_ID}/screenshots';- fs.mkdirSync(outDir, { recursive: true });- fs.writeFileSync(path.join(outDir, 'manifest.json'), JSON.stringify(merged, null, 2));- const pngCount = fs.readdirSync(outDir).filter(f => f.endsWith('.png')).length;- console.log('Deployed ' + pngCount + ' screenshots + manifest to ' + outDir);- "-- - name: Commit and push- env:- REPORT_ID: ${{ steps.report-id.outputs.id }}- run: |- git config user.name "github-actions[bot]"- git config user.email "github-actions[bot]@users.noreply.github.com"- git add "reports/${REPORT_ID}/screenshots/"- if git diff --cached --quiet; then- echo "No new screenshots to deploy"- else- SCREENSHOT_COUNT=$(find "reports/${REPORT_ID}/screenshots" -name '*.png' | wc -l)- git commit -m "screenshots: ${REPORT_ID} (${SCREENSHOT_COUNT} images)"- git push origin gh-pages- echo "✅ Deployed ${SCREENSHOT_COUNT} screenshots to reports/${REPORT_ID}/screenshots/"- fi+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}+ run: >+ node .github/scripts/gh-pages-publisher.mjs vibe-screenshots+ --report-id "$REPORT_ID"+ --screenshots /tmp/screenshots+ --manifests /tmp/manifestsdiff --git a/internal/vibe-tests/src/deploy-report.ts b/internal/vibe-tests/src/deploy-report.tsindex 0f666a5815..94d07e17af 100644--- a/internal/vibe-tests/src/deploy-report.ts+++ b/internal/vibe-tests/src/deploy-report.ts@@ -73,6 +73,10 @@ function runSilent(cmd: string, opts?: {cwd?: string}): string {return run(cmd, {...opts, silent: true}).trim();}+function shellQuote(value: string): string {+ return "'" + value.replace(/'/g, "'\\''") + "'";+}+async function main() {const {iteration, baseline, html, astryxTailwind, dryRun, skipPreviews} =parseArgs();@@ -154,8 +158,8 @@ async function main() {return;}- // Step 3: Deploy to gh-pages- console.log('🚀 Step 3: Deploying to gh-pages...');+ // Step 3: Deploy through the shared gh-pages publisher.+ console.log('🚀 Step 3: Publishing through the shared gh-pages queue...');const tmpDir = path.join(REPO_ROOT, '.deploy-tmp');if (fs.existsSync(tmpDir)) {@@ -164,44 +168,18 @@ async function main() {fs.mkdirSync(tmpDir, {recursive: true});try {- const remoteUrl = runSilent('git remote get-url origin', {cwd: REPO_ROOT});-- run(- `git clone --depth 1 --branch gh-pages --single-branch ${remoteUrl} ${tmpDir}`,- {cwd: REPO_ROOT},- );-- const targetDir = path.join(tmpDir, deployPath);- fs.mkdirSync(targetDir, {recursive: true});- fs.copyFileSync(reportHtml, path.join(targetDir, 'index.html'));+ fs.copyFileSync(reportHtml, path.join(tmpDir, 'index.html'));- // Deploy previews if they existconst previewsDir = path.join(VIBE_DIR, 'results', iteration, 'previews');if (fs.existsSync(previewsDir)) {- const targetPreviewsDir = path.join(targetDir, 'previews');+ const targetPreviewsDir = path.join(tmpDir, 'previews');copyDirRecursive(previewsDir, targetPreviewsDir);const previewCount = countFiles(targetPreviewsDir, '.html');console.log(` ✓ ${previewCount} preview pages copied`);}- // Deploy screenshots if they exist locally (from GHA artifact download)- // Also check if screenshots were already deployed to gh-pages by the- // vibe-screenshots workflow's deploy-screenshots job.- const targetScreenshotsDir = path.join(targetDir, 'screenshots');+ const targetScreenshotsDir = path.join(tmpDir, 'screenshots');let totalScreenshots = 0;-- // First: check if gh-pages already has screenshots (from GHA deploy-screenshots job)- if (- fs.existsSync(targetScreenshotsDir) &&- countFiles(targetScreenshotsDir, '.png') > 0- ) {- totalScreenshots = countFiles(targetScreenshotsDir, '.png');- console.log(- ` ✓ ${totalScreenshots} screenshots found on gh-pages (from GHA)`,- );- }-- // Second: copy any local screenshots (may add to or overwrite gh-pages ones)for (const id of [iteration, baseline, html, astryxTailwind].filter(Boolean,) as string[]) {@@ -214,38 +192,23 @@ async function main() {}}- // If screenshots exist (from either source), inject manifest into report HTML- // so the report app can render them. The report HTML may have been built- // without screenshot data if screenshots weren't available locally during build.if (totalScreenshots > 0 &&- fs.existsSync(path.join(targetDir, 'index.html'))+ fs.existsSync(path.join(tmpDir, 'index.html'))) {const manifestPath = path.join(targetScreenshotsDir, 'manifest.json');if (fs.existsSync(manifestPath)) {injectScreenshotsIntoReport(- path.join(targetDir, 'index.html'),+ path.join(tmpDir, 'index.html'),manifestPath,);}}- updateReportsIndex(tmpDir);-- run('git add .', {cwd: tmpDir});-- const status = runSilent('git status --porcelain', {cwd: tmpDir});- if (!status) {- console.log(' ℹ️ No changes to deploy (report already exists)');- return;- }-- const commitMsg = baseline- ? `report: ${iteration} (vs ${baseline})`- : `report: ${iteration}`;-- run(`git commit -m "${commitMsg}"`, {cwd: tmpDir});- run('git push origin gh-pages', {cwd: tmpDir});+ run(+ `node .github/scripts/gh-pages-publisher.mjs vibe-report --report-id ${shellQuote(iteration)} --source ${shellQuote(tmpDir)}`,+ {cwd: REPO_ROOT},+ );const repoUrl = getRepoUrl();const reportUrl = repoUrl@@ -352,60 +315,6 @@ function countFiles(dir: string, ext: string): number {return count;}-function updateReportsIndex(ghPagesDir: string): void {- const reportsDir = path.join(ghPagesDir, 'reports');- if (!fs.existsSync(reportsDir)) {- return;- }-- const entries = fs- .readdirSync(reportsDir, {withFileTypes: true})- .filter(e => e.isDirectory())- .map(e => e.name)- .sort()- .reverse();-- const html = `<!DOCTYPE html>-<html lang="en">-<head>- <meta charset="UTF-8">- <meta name="viewport" content="width=device-width, initial-scale=1.0">- <title>Astryx Vibe Test Reports</title>- <style>- body {- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;- max-width: 600px;- margin: 40px auto;- padding: 0 20px;- color: #1a1a1a;- }- h1 { font-size: 1.5rem; margin-bottom: 0.5rem; }- p { color: #666; margin-bottom: 2rem; }- ul { list-style: none; padding: 0; }- li { margin-bottom: 0.5rem; }- a {- color: #0969da;- text-decoration: none;- padding: 8px 12px;- display: inline-block;- border-radius: 6px;- transition: background 0.15s;- }- a:hover { background: #f0f4f8; }- </style>-</head>-<body>- <h1>📊 Astryx Vibe Test Reports</h1>- <p>Evaluation reports comparing Astryx, baseline, and raw HTML targets.</p>- <ul>- ${entries.map(name => `<li><a href="${name}/">${name}</a></li>`).join('\n ')}- </ul>-</body>-</html>`;-- fs.writeFileSync(path.join(reportsDir, 'index.html'), html);-}-function getRepoUrl(): string | null {try {const remote = runSilent('git remote get-url origin', {cwd: REPO_ROOT});