name: Lighthouse CI on: pull_request: paths: - 'api/**' - 'client/**' - 'config/**' - 'packages/**' - 'e2e/**' - 'package.json' - 'package-lock.json' - '.github/workflows/lighthouse.yml' - '.github/actions/mongodb-binary/**' - '!**.md' workflow_dispatch: permissions: contents: read pull-requests: write concurrency: group: lighthouse-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true jobs: lighthouse: runs-on: ubuntu-latest timeout-minutes: 20 env: E2E_CHROMIUM_CHANNEL: chromium LIGHTHOUSE_CHROME_FLAGS: --no-sandbox steps: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: node-version: '24.22.3' cache: npm - name: Test Lighthouse failure reporting run: node --test e2e/lighthouse.test.mts # Shares the E2E workflows' exact key and path list: one installed tree # per lockfile, never a tree from another lockfile. - name: Restore node_modules cache id: cache-node-modules uses: actions/cache/restore@v5 with: path: | node_modules client/node_modules packages/client/node_modules packages/chat/node_modules packages/data-provider/node_modules packages/data-schemas/node_modules packages/api/node_modules packages/channel-gateway/node_modules api/node_modules key: node-modules-e2e-${{ runner.os }}-24.22.3-${{ hashFiles('package-lock.json') }} - name: Install dependencies id: install-dependencies if: steps.cache-node-modules.outputs.cache-hit != 'true' run: npm ci # Saved before the audit runs, so nothing the build or the app writes can # end up in the tree other jobs restore. - name: Save node_modules cache if: steps.install-dependencies.outcome == 'success' continue-on-error: true uses: actions/cache/save@v5 with: path: | node_modules client/node_modules packages/client/node_modules packages/chat/node_modules packages/data-provider/node_modules packages/data-schemas/node_modules packages/api/node_modules packages/channel-gateway/node_modules api/node_modules key: ${{ steps.cache-node-modules.outputs.cache-primary-key }} - name: Provision MongoDB memory-server binary uses: ./.github/actions/mongodb-binary - name: Install lockfile-pinned Chromium run: npx playwright install --no-shell chromium # The audit keeps the lockfile-pinned Chromium build, so its download above stays fatal. # Its system packages do not: the runner's own Chrome already brings every library # Chromium links, and what `--with-deps` installed on top were nine optional font packages # (22MB from the Ubuntu mirror) that no budget reads. With the mirror unreachable, apt # failed the combined command before any audit ran. - name: Install optional Chromium system packages (best effort) timeout-minutes: 4 continue-on-error: true run: .github/scripts/install-playwright-fonts.sh chromium - name: Select Lighthouse browser run: | chrome=$(node -p "require('@playwright/test').chromium.executablePath()") "$chrome" --version echo "CHROME_PATH=$chrome" >> "$GITHUB_ENV" - run: npm run e2e:prepare - name: Audit serial database latency id: audit shell: bash run: | set -o pipefail npm run lighthouse:run 2>&1 | tee lighthouse-ci.log - name: Comment Lighthouse findings if: ${{ failure() && steps.audit.outcome == 'failure' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository }} env: GH_TOKEN: ${{ github.token }} PR_NUMBER: ${{ github.event.pull_request.number }} run: | { echo 'Lighthouse CI failed. The last 80 log lines contain the measured budgets and assertion failures.' echo echo '```text' tail -n 80 lighthouse-ci.log echo '```' echo echo "[Open the full run]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID)" } > lighthouse-comment.md gh pr comment "$PR_NUMBER" --body-file lighthouse-comment.md # A debugging aid that no job downloads, so a failed or stalled upload must not fail the # audit: see the note on the e2e_shards uploads in playwright-mock.yml. - name: Upload Lighthouse reports if: ${{ !cancelled() }} timeout-minutes: 3 continue-on-error: true uses: actions/upload-artifact@v6 with: name: lighthouse path: | .lighthouse/ lighthouse-ci.log include-hidden-files: true retention-days: 7