name: Storybook on: pull_request: paths: - "apps/storybook/**" - "packages/ui/src/stories/**" - "packages/ui-app/src/stories/**" - "packages/ui-subframe/src/stories/**" - "packages/ui-mock/src/stories/**" - ".gitea/workflows/storybook.yml" workflow_dispatch: env: TOOLCTRL_GITEA_HOST_IP: ${{ vars.TOOLCTRL_GITEA_HOST_IP }} PLAYWRIGHT_BROWSERS_PATH: .cache/ms-playwright jobs: build-storybook: name: Build static Storybook runs-on: toolctrl-ci timeout-minutes: 20 steps: - name: Resolve internal Gitea host run: | if [ -n "${TOOLCTRL_GITEA_HOST_IP:-}" ]; then if ! TOOLCTRL_GITEA_HOST_IP="$TOOLCTRL_GITEA_HOST_IP" node -e 'process.exit(require("node:net").isIP(process.env.TOOLCTRL_GITEA_HOST_IP || "") ? 0 : 1)'; then echo "TOOLCTRL_GITEA_HOST_IP must be a single IPv4 or IPv6 token" exit 1 fi printf '%s git.tool-ctrl.de\n' "$TOOLCTRL_GITEA_HOST_IP" >> /etc/hosts fi - name: Checkout code uses: actions/checkout@v4 - name: Enable Corepack run: corepack enable - name: Prepare pnpm 10.33.0 run: corepack prepare pnpm@10.33.0 --activate - name: Configure pnpm store run: pnpm config set store-dir .pnpm-store - name: Cache pnpm store uses: actions/cache@v4 with: path: .pnpm-store key: ${{ runner.os }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }} restore-keys: | ${{ runner.os }}-pnpm- - name: Install dependencies run: pnpm install --frozen-lockfile - name: Build Storybook static site run: pnpm --filter @toolctrl/storybook build-storybook - name: Upload static Storybook artifact uses: actions/upload-artifact@v3 with: name: storybook-static path: apps/storybook/storybook-static retention-days: 14 test-storybook: name: Storybook test-runner (a11y gate) needs: build-storybook runs-on: toolctrl-ci timeout-minutes: 25 steps: - name: Resolve internal Gitea host run: | if [ -n "${TOOLCTRL_GITEA_HOST_IP:-}" ]; then if ! TOOLCTRL_GITEA_HOST_IP="$TOOLCTRL_GITEA_HOST_IP" node -e 'process.exit(require("node:net").isIP(process.env.TOOLCTRL_GITEA_HOST_IP || "") ? 0 : 1)'; then echo "TOOLCTRL_GITEA_HOST_IP must be a single IPv4 or IPv6 token" exit 1 fi printf '%s git.tool-ctrl.de\n' "$TOOLCTRL_GITEA_HOST_IP" >> /etc/hosts fi - name: Checkout code uses: actions/checkout@v4 - name: Enable Corepack run: corepack enable - name: Prepare pnpm 10.33.0 run: corepack prepare pnpm@10.33.0 --activate - name: Configure pnpm store run: pnpm config set store-dir .pnpm-store - name: Cache pnpm store uses: actions/cache@v4 with: path: .pnpm-store key: ${{ runner.os }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }} restore-keys: | ${{ runner.os }}-pnpm- - name: Install dependencies run: pnpm install --frozen-lockfile - name: Download built Storybook uses: actions/download-artifact@v3 with: name: storybook-static path: apps/storybook/storybook-static - name: Cache Playwright browsers uses: actions/cache@v4 with: path: .cache/ms-playwright key: ${{ runner.os }}-playwright-${{ hashFiles('pnpm-lock.yaml') }} restore-keys: | ${{ runner.os }}-playwright- - name: Install Playwright Chromium run: pnpm --filter @toolctrl/storybook exec playwright install --with-deps chromium - name: Serve static Storybook and run test-runner with a11y gate run: | set -euo pipefail pnpm --filter @toolctrl/storybook exec http-server storybook-static --port 6006 --silent & SERVER_PID=$! trap "kill $SERVER_PID 2>/dev/null || true" EXIT pnpm --filter @toolctrl/storybook exec wait-on http://127.0.0.1:6006 --timeout 60000 TARGET_URL=http://127.0.0.1:6006 pnpm --filter @toolctrl/storybook test:storybook visual-regression: name: Storybook visual-regression (Lost-Pixel) needs: build-storybook runs-on: toolctrl-ci timeout-minutes: 20 steps: - name: Resolve internal Gitea host run: | if [ -n "${TOOLCTRL_GITEA_HOST_IP:-}" ]; then if ! TOOLCTRL_GITEA_HOST_IP="$TOOLCTRL_GITEA_HOST_IP" node -e 'process.exit(require("node:net").isIP(process.env.TOOLCTRL_GITEA_HOST_IP || "") ? 0 : 1)'; then echo "TOOLCTRL_GITEA_HOST_IP must be a single IPv4 or IPv6 token" exit 1 fi printf '%s git.tool-ctrl.de\n' "$TOOLCTRL_GITEA_HOST_IP" >> /etc/hosts fi - name: Checkout code uses: actions/checkout@v4 - name: Check for committed Lost-Pixel baseline id: baseline run: | set -euo pipefail if ls apps/storybook/.lostpixel/baseline/*.png >/dev/null 2>&1; then echo "present=true" >> "$GITHUB_OUTPUT" else echo "present=false" >> "$GITHUB_OUTPUT" echo "No Lost-Pixel baseline committed yet — skipping visual-regression. Run 'pnpm --filter @toolctrl/storybook visual-regression:update' and commit apps/storybook/.lostpixel/baseline/*.png to enable this gate." fi - name: Enable Corepack if: steps.baseline.outputs.present == 'true' run: corepack enable - name: Prepare pnpm 10.33.0 if: steps.baseline.outputs.present == 'true' run: corepack prepare pnpm@10.33.0 --activate - name: Configure pnpm store if: steps.baseline.outputs.present == 'true' run: pnpm config set store-dir .pnpm-store - name: Cache pnpm store if: steps.baseline.outputs.present == 'true' uses: actions/cache@v4 with: path: .pnpm-store key: ${{ runner.os }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }} restore-keys: | ${{ runner.os }}-pnpm- - name: Install dependencies if: steps.baseline.outputs.present == 'true' run: pnpm install --frozen-lockfile - name: Download built Storybook if: steps.baseline.outputs.present == 'true' uses: actions/download-artifact@v3 with: name: storybook-static path: apps/storybook/storybook-static - name: Cache Playwright browsers if: steps.baseline.outputs.present == 'true' uses: actions/cache@v4 with: path: .cache/ms-playwright key: ${{ runner.os }}-playwright-${{ hashFiles('pnpm-lock.yaml') }} restore-keys: | ${{ runner.os }}-playwright- - name: Install Playwright Chromium if: steps.baseline.outputs.present == 'true' run: pnpm --filter @toolctrl/storybook exec playwright install --with-deps chromium - name: Run Lost-Pixel visual-regression diff if: steps.baseline.outputs.present == 'true' run: pnpm --filter @toolctrl/storybook visual-regression - name: Upload Lost-Pixel diff images if: steps.baseline.outputs.present == 'true' && failure() uses: actions/upload-artifact@v3 with: name: lost-pixel-diff path: apps/storybook/.lostpixel/difference retention-days: 14