284 lines
9.4 KiB
YAML
284 lines
9.4 KiB
YAML
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:
|
||
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: E2E (start + test + teardown)
|
||
run: |
|
||
set -euxo pipefail
|
||
|
||
export PORT="${PORT:-3010}"
|
||
export HOST="127.0.0.1"
|
||
mkdir -p .next
|
||
|
||
# ensure build exists
|
||
test -d .next || { echo "❌ Missing .next build output"; exit 1; }
|
||
|
||
echo "🚀 Starting Next.js server for E2E testing..."
|
||
|
||
# Start Next directly with node so $! is the real node PID
|
||
node node_modules/next/dist/bin/next start -p "$PORT" -H "$HOST" > .next/runner.log 2>&1 &
|
||
SVPID=$!
|
||
echo "$SVPID" > .next/runner.pid
|
||
echo "🌐 Server PID: $SVPID"
|
||
|
||
# Wait for readiness
|
||
echo "⏳ Waiting for server to be ready..."
|
||
npx wait-on -t 120000 "tcp:$HOST:$PORT"
|
||
curl -fsS "http://$HOST:$PORT" >/dev/null
|
||
echo "✅ App is responding at http://$HOST:$PORT"
|
||
|
||
# Run tests
|
||
echo "🧪 Running E2E tests for ${{ matrix.browser }}..."
|
||
BASE_URL="http://$HOST:$PORT" npx playwright test --project=${{ matrix.browser }} --reporter=list
|
||
|
||
# Teardown
|
||
echo "🧹 Cleaning up server..."
|
||
kill "$SVPID" 2>/dev/null || true
|
||
echo "✅ Server cleanup complete"
|
||
env:
|
||
NEXT_TELEMETRY_DISABLED: "1"
|
||
NODE_ENV: production
|
||
NODE_OPTIONS: "--max-old-space-size=4096"
|
||
|
||
# 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
|
||
|
||
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)
|
||
|
||
- name: Visual Regression (start + test + teardown)
|
||
run: |
|
||
set -euxo pipefail
|
||
|
||
export PORT="${PORT:-3010}"
|
||
export HOST="127.0.0.1"
|
||
mkdir -p .next
|
||
|
||
# ensure build exists
|
||
test -d .next || { echo "❌ Missing .next build output"; exit 1; }
|
||
|
||
echo "🚀 Starting Next.js server for visual regression testing..."
|
||
|
||
# Start Next directly with node so $! is the real node PID
|
||
node node_modules/next/dist/bin/next start -p "$PORT" -H "$HOST" > .next/runner.log 2>&1 &
|
||
SVPID=$!
|
||
echo "$SVPID" > .next/runner.pid
|
||
echo "🌐 Server PID: $SVPID"
|
||
|
||
# Wait for readiness
|
||
echo "⏳ Waiting for server to be ready..."
|
||
npx wait-on -t 120000 "tcp:$HOST:$PORT"
|
||
curl -fsS "http://$HOST:$PORT" >/dev/null
|
||
echo "✅ App is responding at http://$HOST:$PORT"
|
||
|
||
# Seed snapshots on main branch only (one-time setup)
|
||
if [ "${{ gitea.ref }}" = "refs/heads/main" ]; then
|
||
echo "🌱 Seeding snapshots on main branch..."
|
||
PLAYWRIGHT_UPDATE_SNAPSHOTS=1 npx playwright test tests/e2e/visual-regression.spec.ts --project=chromium
|
||
fi
|
||
|
||
# Run visual regression tests
|
||
echo "🧪 Running visual regression tests..."
|
||
BASE_URL="http://$HOST:$PORT" npx playwright test tests/e2e/visual-regression.spec.ts
|
||
|
||
# Teardown
|
||
echo "🧹 Cleaning up server..."
|
||
kill "$SVPID" 2>/dev/null || true
|
||
echo "✅ Server cleanup complete"
|
||
env:
|
||
NEXT_TELEMETRY_DISABLED: "1"
|
||
NODE_ENV: production
|
||
NODE_OPTIONS: "--max-old-space-size=4096"
|
||
|
||
- 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
|
||
|
||
- name: Stop app
|
||
if: always()
|
||
run: |
|
||
if [ -f .next/runner.pid ]; then
|
||
kill $(cat .next/runner.pid) 2>/dev/null || true
|
||
fi
|
||
|
||
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
|
||
|
||
- 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)
|
||
|
||
- name: Install portable Chrome (x64 to match Rosetta Node)
|
||
run: |
|
||
# Install x64 Chrome explicitly
|
||
npx @puppeteer/browsers install chrome@stable --platform mac_x64 -P .cache/puppeteer
|
||
# Compute the executable path for that platform
|
||
CHROME_PATH="$(npx @puppeteer/browsers executable-path chrome@stable --platform mac_x64 -P .cache/puppeteer)"
|
||
echo "Using Chrome at: $CHROME_PATH"
|
||
"$CHROME_PATH" --version
|
||
# Make it available to later steps *and* this shell
|
||
echo "CHROME_PATH=$CHROME_PATH" >> "$GITHUB_ENV"
|
||
export CHROME_PATH
|
||
|
||
- name: Performance (start + test + teardown)
|
||
run: |
|
||
set -euxo pipefail
|
||
|
||
export PORT=3010 HOST=127.0.0.1
|
||
mkdir -p .next
|
||
test -d .next || { echo "❌ Missing .next build output"; exit 1; }
|
||
|
||
echo "🚀 Starting Next.js server for performance testing..."
|
||
node node_modules/next/dist/bin/next start -p "$PORT" -H "$HOST" > .next/runner.log 2>&1 &
|
||
SVPID=$!
|
||
npx wait-on -t 120000 "tcp:$HOST:$PORT"
|
||
curl -fsS "http://$HOST:$PORT" >/dev/null
|
||
echo "✅ App is responding at http://$HOST:$PORT"
|
||
|
||
echo "Node arch: $(node -p "process.arch")"
|
||
echo "Chrome: $CHROME_PATH"
|
||
"$CHROME_PATH" --version
|
||
|
||
# Run LHCI against the x64 Chrome we installed
|
||
npx lhci autorun --chrome-path="$CHROME_PATH" --collect.url=http://$HOST:$PORT/
|
||
|
||
kill "$SVPID" 2>/dev/null || true
|
||
env:
|
||
NEXT_TELEMETRY_DISABLED: "1"
|
||
NODE_ENV: production
|
||
NODE_OPTIONS: "--max-old-space-size=4096"
|
||
|
||
- 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
|