name: CI Pipeline run-name: ${{ gitea.actor }} triggered CI pipeline on: workflow_dispatch: {} push: branches: [main, develop] # only direct pushes/merges to protected branches pull_request: branches: [main, develop] # PRs into main/develop types: [opened, reopened, synchronize] jobs: canary: runs-on: [self-hosted, macos-latest] steps: - run: | echo "PATH=$PATH" which node && node -v uname -a echo "Runner labels OK βœ…" test: runs-on: [self-hosted, macos-latest] strategy: matrix: { node-version: [18, 20] } env: NODE_OPTIONS: "--max_old_space_size=4096" steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} cache: npm - run: npm ci - run: npm test # If the Codecov Action fails on Gitea, replace this with the bash uploader below - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 with: token: ${{ secrets.CODECOV_TOKEN }} files: ./coverage/lcov.info flags: unittests # Bash uploader alternative (uncomment if the action above has issues) # - name: Upload coverage to Codecov (bash) # run: | # curl -s https://codecov.io/bash > codecov.sh # bash codecov.sh -t "${{ secrets.CODECOV_TOKEN }}" -f coverage/lcov.info -F unittests e2e: runs-on: [self-hosted, macos-latest] strategy: matrix: { browser: [chromium, firefox, webkit] } steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: { node-version: 20, cache: npm } - run: npm ci - run: npx playwright install --with-deps ${{ matrix.browser }} - run: npm run build - name: Start app (background) + healthcheck run: | set -euxo pipefail # pick a port that's unlikely to be busy export PORT="${PORT:-3010}" export HOST="127.0.0.1" # ensure build exists test -d .next || { echo "❌ Missing .next build output"; exit 1; } # start and detach with logs mkdir -p .next nohup npm run start -- -p "$PORT" -H "$HOST" > .next/runner.log 2>&1 & echo $! > .next/runner.pid echo "🌐 PID $(cat .next/runner.pid) listening on http://$HOST:$PORT" # wait for TCP, then HTTP npx wait-on -t 120000 "tcp:$HOST:$PORT" curl -fsS "http://$HOST:$PORT" >/dev/null echo "βœ… App is responding" env: NEXT_TELEMETRY_DISABLED: "1" NODE_ENV: production - name: Show last 200 lines of server log on failure if: failure() run: | echo "––– .next/runner.log (tail) –––" tail -n 200 .next/runner.log || true - name: Run E2E tests run: npx playwright test --project=${{ matrix.browser }} env: CI: true BASE_URL: http://127.0.0.1:3010 # package artifacts (keeps file count small) - name: Package E2E artifacts if: always() run: | tar -czf playwright-${{ matrix.browser }}.tgz playwright-report test-results || true - name: Upload E2E artifacts if: always() uses: actions/upload-artifact@v3 with: name: playwright-results-${{ matrix.browser }} path: playwright-${{ matrix.browser }}.tgz retention-days: 30 - name: Stop app if: always() run: | if [ -f .next/runner.pid ]; then kill $(cat .next/runner.pid) 2>/dev/null || true fi visual-regression: runs-on: [self-hosted, macos-latest] steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: { node-version: 20, cache: npm } - run: npm ci - run: npx playwright install --with-deps - run: npm run build # 1) Sanity check that the build exists - name: Verify Next build output run: | set -euxo pipefail ls -la .next || true test -f .next/BUILD_ID || (echo "No Next build output (.next) – did build fail?" && exit 1) # 2) Start the right kind of server and capture logs - name: Start app (auto-detect start vs export) run: | set -euxo pipefail # prefer production server if Next build exists if [ -f .next/BUILD_ID ]; then # run Next in the foreground for 3s to flush any crash to logs, then background it (NODE_ENV=production NEXT_TELEMETRY_DISABLED=1 \ node --trace-uncaught node_modules/next/dist/bin/next start -p 3000 -H 127.0.0.1 \ ) > server.log 2>&1 & # fall back to static export (if your project uses output: 'export') elif [ -d out ]; then npx --yes http-server out -p 3000 --silent > server.log 2>&1 & else echo "Neither .next nor out/ present – nothing to serve"; cat server.log || true; exit 1 fi echo $! > server.pid sleep 2 echo "----- first server log lines -----" head -n 200 server.log || true echo "----------------------------------" # 3) Fail fast if the process died - name: Check server process run: | set -e PID=$(cat server.pid) if ! ps -p "$PID" > /dev/null; then echo "Server crashed during startup:" cat server.log || true exit 1 fi # 4) Wait for readiness with helpful diagnostics - name: Wait for http://127.0.0.1:3000 run: | set -euxo pipefail for i in $(seq 1 60); do if curl -sf http://127.0.0.1:3000 >/dev/null; then echo "App is up βœ…"; exit 0 fi if [ $i -eq 1 ] || [ $((i%10)) -eq 0 ]; then echo "Still waiting… attempt $i" tail -n 50 server.log || true fi sleep 2 done echo "Timed out waiting for app"; tail -n +1 server.log || true; exit 1 # Seed snapshots on main branch only (one-time setup) - name: Seed snapshots (main only) if: github.ref == 'refs/heads/main' run: PLAYWRIGHT_UPDATE_SNAPSHOTS=1 npx playwright test tests/e2e/visual-regression.spec.ts --project=chromium env: { CI: true } # Run visual regression tests - name: Run visual regression tests run: npx playwright test tests/e2e/visual-regression.spec.ts env: { CI: true } - name: Package visual artifacts if: always() run: | tar -czf visual-regression.tgz test-results tests/e2e/visual-regression.spec.ts-snapshots || true - name: Upload visual artifacts if: always() uses: actions/upload-artifact@v3 with: name: visual-regression-results path: visual-regression.tgz retention-days: 30 performance: runs-on: [self-hosted, macos-latest] steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: { node-version: 20, cache: npm } - run: npm ci - name: Install LHCI run: npm i -D @lhci/cli # Ensure a Chrome binary is available (works on Linux/macOS runners) - name: Install Chrome via Puppeteer (portable) run: | npx @puppeteer/browsers install chrome@stable -P .cache/puppeteer echo "CHROME_PATH=$(npx @puppeteer/browsers executable-path chrome@stable -P .cache/puppeteer)" >> $GITHUB_ENV - name: Build application run: npm run build # 1) Sanity check that the build exists - name: Verify Next build output run: | set -euxo pipefail ls -la .next || true test -f .next/BUILD_ID || (echo "No Next build output (.next) – did build fail?" && exit 1) # 2) Start the right kind of server and capture logs - name: Start app (auto-detect start vs export) run: | set -euxo pipefail # prefer production server if Next build exists if [ -f .next/BUILD_ID ]; then # run Next in the foreground for 3s to flush any crash to logs, then background it (NODE_ENV=production NEXT_TELEMETRY_DISABLED=1 \ node --trace-uncaught node_modules/next/dist/bin/next start -p 3000 -H 127.0.0.1 \ ) > server.log 2>&1 & # fall back to static export (if your project uses output: 'export') elif [ -d out ]; then npx --yes http-server out -p 3000 --silent > server.log 2>&1 & else echo "Neither .next nor out/ present – nothing to serve"; cat server.log || true; exit 1 fi echo $! > server.pid sleep 2 echo "----- first server log lines -----" head -n 200 server.log || true echo "----------------------------------" # 3) Fail fast if the process died - name: Check server process run: | set -e PID=$(cat server.pid) if ! ps -p "$PID" > /dev/null; then echo "Server crashed during startup:" cat server.log || true exit 1 fi # 4) Wait for readiness with helpful diagnostics - name: Wait for http://127.0.0.1:3000 run: | set -euxo pipefail for i in $(seq 1 60); do if curl -sf http://127.0.0.1:3000 >/dev/null; then echo "App is up βœ…"; exit 0 fi if [ $i -eq 1 ] || [ $((i%10)) -eq 0 ]; then echo "Still waiting… attempt $i" tail -n 50 server.log || true fi sleep 2 done echo "Timed out waiting for app"; tail -n +1 server.log || true; exit 1 - name: Run Lighthouse CI run: npx lhci autorun --chrome-path="$CHROME_PATH" env: { CI: true } - name: Upload LHCI results if: always() uses: actions/upload-artifact@v3 with: name: lhci-results path: lhci-results storybook: runs-on: [self-hosted, macos-latest] steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: { node-version: 20, cache: npm } - run: npm ci - run: npm run storybook:build:github - run: npm run test:sb env: { CI: true } lint: runs-on: [self-hosted, macos-latest] steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: { node-version: 20, cache: npm } - run: npm ci - run: npm run lint - run: npx prettier --check "**/*.{js,jsx,ts,tsx,json,css,md}" build: runs-on: [self-hosted, macos-latest] steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: { node-version: 20, cache: npm } - run: npm ci - run: npm run build - run: npm run storybook:build:github