diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index 2f27326..00c8ef0 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -47,15 +47,27 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: { node-version: 20, cache: npm } - - name: Cache Playwright + - run: npm ci + - name: Compute Playwright version + id: pw + run: echo "version=$(node -p \"require('@playwright/test/package.json').version\")" >> "$GITHUB_OUTPUT" + + - name: Cache Playwright browsers + id: pw-cache uses: actions/cache@v4 with: - path: ~/.cache/ms-playwright - key: ms-playwright-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }} - - run: npm ci - - run: npx playwright install ${{ matrix.browser }} - env: - PLAYWRIGHT_BROWSERS_PATH: ~/.cache/ms-playwright + # macOS and Linux paths are included; missing paths are ignored. + path: | + ~/Library/Caches/ms-playwright + ~/.cache/ms-playwright + key: playwright-${{ runner.os }}-${{ steps.pw.outputs.version }}-${{ hashFiles('package-lock.json') }} + restore-keys: | + playwright-${{ runner.os }}-${{ steps.pw.outputs.version }}- + playwright-${{ runner.os }}- + + - name: Install Playwright (only if cache miss) + if: steps.pw-cache.outputs.cache-hit != 'true' + run: npx playwright install --with-deps ${{ matrix.browser }} - run: npm run build - name: E2E (start + test + teardown) @@ -116,15 +128,27 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: { node-version: 20, cache: npm } - - name: Cache Playwright + - run: npm ci + - name: Compute Playwright version + id: pw + run: echo "version=$(node -p \"require('@playwright/test/package.json').version\")" >> "$GITHUB_OUTPUT" + + - name: Cache Playwright browsers + id: pw-cache uses: actions/cache@v4 with: - path: ~/.cache/ms-playwright - key: ms-playwright-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }} - - run: npm ci - - run: npx playwright install - env: - PLAYWRIGHT_BROWSERS_PATH: ~/.cache/ms-playwright + # macOS and Linux paths are included; missing paths are ignored. + path: | + ~/Library/Caches/ms-playwright + ~/.cache/ms-playwright + key: playwright-${{ runner.os }}-${{ steps.pw.outputs.version }}-${{ hashFiles('package-lock.json') }} + restore-keys: | + playwright-${{ runner.os }}-${{ steps.pw.outputs.version }}- + playwright-${{ runner.os }}- + + - name: Install Playwright (only if cache miss) + if: steps.pw-cache.outputs.cache-hit != 'true' + run: npx playwright install --with-deps - run: npm run build # 1) Sanity check that the build exists - name: Verify Next build output @@ -205,9 +229,10 @@ jobs: run: npm i -D @lhci/cli - name: Build application - run: npm run build + run: + npm run build - # 1) Sanity check that the build exists + # 1) Sanity check that the build exists - name: Verify Next build output run: | set -euxo pipefail @@ -216,33 +241,38 @@ jobs: - name: Install Chrome via Puppeteer (mac_arm) run: | + # Install Chrome (arm64) into a local cache set -euxo pipefail mkdir -p .cache/puppeteer - echo "Installing Chrome for mac_arm platform..." - npx @puppeteer/browsers install chrome@stable \ - --platform=mac_arm \ - --path .cache/puppeteer - echo "Chrome installation complete. Getting executable path..." - CHROME_PATH=$(npx @puppeteer/browsers executable-path chrome@stable --platform=mac_arm --path .cache/puppeteer) - echo "Chrome executable path: $CHROME_PATH" + # 1) Install and capture the build id that was actually installed + INSTALL_OUT="$(npx @puppeteer/browsers install chrome@stable --platform=mac_arm --path .cache/puppeteer)" + echo "$INSTALL_OUT" - # Verify the path is not empty + # INSTALL_OUT looks like: "chrome@140.0.7339.80 /abs/path/to/.../Google Chrome for Testing" + BUILD_ID="$(printf '%s\n' "$INSTALL_OUT" | awk '{print $1}' | cut -d@ -f2)" + echo "Detected Chrome build: $BUILD_ID" + + # 2) Ask for the executable path using the explicit build id + CHROME_PATH="$(npx @puppeteer/browsers executable-path chrome@"$BUILD_ID" --platform=mac_arm --path .cache/puppeteer || true)" + echo "Chrome executable path (via CLI): ${CHROME_PATH:-}" + + # 3) Fallback: resolve the binary directly from the cache if the CLI returned empty if [ -z "$CHROME_PATH" ]; then - echo "❌ Chrome path is empty after installation" - ls -la .cache/puppeteer/ || true + CHROME_PATH="$(/usr/bin/find ".cache/puppeteer/chrome" -type f -path "*/chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing" -print -quit || true)" + echo "Chrome executable path (via find): ${CHROME_PATH:-}" + fi + + # 4) Hard fail if still empty + if [ -z "$CHROME_PATH" ] || [ ! -x "$CHROME_PATH" ]; then + echo "❌ Chrome path is empty or not executable" + ls -la .cache/puppeteer || true exit 1 fi - # Verify the executable exists - if [ ! -f "$CHROME_PATH" ]; then - echo "❌ Chrome executable not found at: $CHROME_PATH" - ls -la .cache/puppeteer/ || true - exit 1 - fi - - echo "✅ Chrome installed successfully at: $CHROME_PATH" + # 5) Export for subsequent steps in this job and later ones echo "CHROME_PATH=$CHROME_PATH" >> "$GITHUB_ENV" + "$CHROME_PATH" --version || true - name: Ensure arm64 Node for Lighthouse run: | @@ -324,15 +354,27 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: { node-version: 20, cache: npm } - - name: Cache Playwright + - run: npm ci + - name: Compute Playwright version + id: pw + run: echo "version=$(node -p \"require('@playwright/test/package.json').version\")" >> "$GITHUB_OUTPUT" + + - name: Cache Playwright browsers + id: pw-cache uses: actions/cache@v4 with: - path: ~/.cache/ms-playwright - key: ms-playwright-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }} - - run: npm ci - - run: npx playwright install - env: - PLAYWRIGHT_BROWSERS_PATH: ~/.cache/ms-playwright + # macOS and Linux paths are included; missing paths are ignored. + path: | + ~/Library/Caches/ms-playwright + ~/.cache/ms-playwright + key: playwright-${{ runner.os }}-${{ steps.pw.outputs.version }}-${{ hashFiles('package-lock.json') }} + restore-keys: | + playwright-${{ runner.os }}-${{ steps.pw.outputs.version }}- + playwright-${{ runner.os }}- + + - name: Install Playwright (only if cache miss) + if: steps.pw-cache.outputs.cache-hit != 'true' + run: npx playwright install --with-deps - run: npm run build - name: Start app + wait run: |