From c8620cd3ea14d8e29bba7cf61c961fe35c09cd74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Mon, 16 Nov 2026 14:06:48 +0000 Subject: [PATCH 1/5] ci(e2e): run on Vercel deploys again and pass Deployment Protection with OIDC Amp-Thread-ID: https://ampcode.com/threads/T-01a1d4e0-41a0-7295-89c7-113254d46fe1 --- .github/workflows/e2e.yml | 79 ++++++++++++++++++++++++++++++--------- playwright.config.ts | 6 ++- 2 files changed, 66 insertions(+), 19 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index ca5380ad3..a5da7daa4 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -12,18 +12,37 @@ on: permissions: {} jobs: + # On `deployment_status`, only run for production deploys and for deploys of a commit at the head of a branch in this + # repo, never for a fork PR's. Vercel sets `deployment.ref` to the commit SHA for every deploy, so it can't tell them apart. + trusted: + if: github.event_name == 'workflow_dispatch' || github.event.deployment_status.state == 'success' + runs-on: ubuntu-slim + permissions: + contents: read + outputs: + trusted: ${{ steps.check.outputs.trusted }} + steps: + - id: check + run: | + if [ "$EVENT_NAME" = workflow_dispatch ] || [ "$ENVIRONMENT" = Production ] || + [ "$(gh api "repos/$GITHUB_REPOSITORY/commits/$SHA/branches-where-head" --jq length)" != 0 ]; then + echo trusted=true >> "$GITHUB_OUTPUT" + fi + env: + GH_TOKEN: ${{ github.token }} + EVENT_NAME: ${{ github.event_name }} + ENVIRONMENT: ${{ github.event.deployment.environment }} + SHA: ${{ github.event.deployment.sha }} + e2e: + needs: trusted + if: needs.trusted.outputs.trusted == 'true' environment: name: ${{ github.event.deployment.environment || 'Production' }} url: ${{ github.event.inputs.url || github.event.deployment_status.environment_url }} - # On `deployment_status`, only run for deploys of a branch in this repo. Vercel sets - # `deployment.ref` to the branch name for same-repo deploys and to the bare SHA for - # fork-PR deploys, so `ref == sha` indicates an untrusted source. - if: | - github.event_name == 'workflow_dispatch' || - (github.event.deployment_status.state == 'success' && - github.event.deployment.ref != github.event.deployment.sha) runs-on: ubuntu-latest + permissions: + id-token: write steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: @@ -32,24 +51,40 @@ jobs: with: cache: true - run: pnpm exec playwright install + # Vercel lets this workflow through Deployment Protection with its OIDC token (Settings > Deployment Protection > + # Trusted Sources). The token expires after about 5 minutes, so each job fetches it right before using it. + - name: Get the OIDC token + id: oidc + run: | + token=$(curl -sSf -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -r .value) + echo "::add-mask::$token" + echo "token=$token" >> "$GITHUB_OUTPUT" - name: Run Playwright E2E tests run: pnpm test:browser env: BASE_URL: ${{ github.event.inputs.url || github.event.deployment_status.environment_url }} + VERCEL_TRUSTED_OIDC_TOKEN: ${{ steps.oidc.outputs.token }} lighthouse: + needs: trusted + if: needs.trusted.outputs.trusted == 'true' environment: name: ${{ github.event.deployment.environment || 'Production' }} url: ${{ github.event.inputs.url || github.event.deployment_status.environment_url }} - if: | - github.event_name == 'workflow_dispatch' || - (github.event.deployment_status.state == 'success' && - github.event.deployment.ref != github.event.deployment.sha) runs-on: ubuntu-latest + permissions: + id-token: write steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false + - name: Get the OIDC token + id: oidc + run: | + token=$(curl -sSf -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -r .value) + echo "::add-mask::$token" + echo "token=$token" >> "$GITHUB_OUTPUT" + # Lighthouse copies its settings, the header included, into the public report: the token has expired by then. - name: Audit URLs using Lighthouse uses: treosh/lighthouse-ci-action@3e7e23fb74242897f95c0ba9cabad3d0227b9b18 # v12 with: @@ -58,22 +93,30 @@ jobs: temporaryPublicStorage: true env: LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }} + LHCI_COLLECT__SETTINGS__EXTRA_HEADERS: '{"x-vercel-trusted-oidc-idp-token":"${{ steps.oidc.outputs.token }}"}' warmup: + needs: trusted + if: needs.trusted.outputs.trusted == 'true' environment: name: ${{ github.event.deployment.environment || 'Production' }} url: ${{ github.event.inputs.url || github.event.deployment_status.environment_url }} - if: | - github.event_name == 'workflow_dispatch' || - (github.event.deployment_status.state == 'success' && - github.event.deployment.ref != github.event.deployment.sha) runs-on: ubuntu-slim + permissions: + id-token: write steps: + - name: Get the OIDC token + id: oidc + run: | + token=$(curl -sSf -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -r .value) + echo "::add-mask::$token" + echo "token=$token" >> "$GITHUB_OUTPUT" - name: warmup jobs, sponsors and modules run: | - curl -sS "$BASE_URL/api/jobs" - curl -sS "$BASE_URL/api/sponsors" - curl -sS "$BASE_URL/api/v1/modules" + curl -sS -H "x-vercel-trusted-oidc-idp-token: $TOKEN" "$BASE_URL/api/jobs" + curl -sS -H "x-vercel-trusted-oidc-idp-token: $TOKEN" "$BASE_URL/api/sponsors" + curl -sS -H "x-vercel-trusted-oidc-idp-token: $TOKEN" "$BASE_URL/api/v1/modules" env: BASE_URL: ${{ github.event.inputs.url || github.event.deployment_status.environment_url }} + TOKEN: ${{ steps.oidc.outputs.token }} diff --git a/playwright.config.ts b/playwright.config.ts index 272159cf6..19faace5c 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -7,6 +7,10 @@ export default defineConfig({ // TODO: fix issues with local testing with `@nuxt/content` // tests against deployment nuxt.com by default host: process.env.BASE_URL || 'https://nuxt.com' - } + }, + // Set by the e2e workflow to get through Vercel Deployment Protection on preview deployments + extraHTTPHeaders: process.env.VERCEL_TRUSTED_OIDC_TOKEN + ? { 'x-vercel-trusted-oidc-idp-token': process.env.VERCEL_TRUSTED_OIDC_TOKEN } + : undefined } }) From 04c910408884de0bdc5c3a5e4824f0a093a5b55e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Mon, 16 Nov 2026 14:26:11 +0000 Subject: [PATCH 2/5] ci(e2e): remove the OIDC token from the Lighthouse report before uploading it Amp-Thread-ID: https://ampcode.com/threads/T-01a1d4e0-41a0-7295-89c7-113254d46fe1 --- .github/workflows/e2e.yml | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index a5da7daa4..20382978b 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -84,16 +84,31 @@ jobs: token=$(curl -sSf -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -r .value) echo "::add-mask::$token" echo "token=$token" >> "$GITHUB_OUTPUT" - # Lighthouse copies its settings, the header included, into the public report: the token has expired by then. - - name: Audit URLs using Lighthouse - uses: treosh/lighthouse-ci-action@3e7e23fb74242897f95c0ba9cabad3d0227b9b18 # v12 - with: - urls: ${{ github.event.inputs.url || github.event.deployment_status.environment_url }} - uploadArtifacts: true - temporaryPublicStorage: true + - name: Audit the URL with Lighthouse + run: npx --yes @lhci/cli@0.15.1 collect --url="$URL" --numberOfRuns=1 env: - LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }} + URL: ${{ github.event.inputs.url || github.event.deployment_status.environment_url }} LHCI_COLLECT__SETTINGS__EXTRA_HEADERS: '{"x-vercel-trusted-oidc-idp-token":"${{ steps.oidc.outputs.token }}"}' + # Lighthouse copies its settings, the header included, into the report, and the token is still valid for a few + # minutes: drop it before the report goes public. The upload regenerates the HTML report from the JSON. + - name: Remove the OIDC token from the report + run: | + for lhr in .lighthouseci/lhr-*.json; do + jq 'del(.configSettings.extraHeaders)' "$lhr" > "$lhr.tmp" && mv "$lhr.tmp" "$lhr" + done + rm .lighthouseci/lhr-*.html + ! grep -rqF "$TOKEN" .lighthouseci + env: + TOKEN: ${{ steps.oidc.outputs.token }} + - name: Upload the report + run: npx --yes @lhci/cli@0.15.1 upload --target=temporary-public-storage + env: + LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }} + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: lighthouse-results + path: .lighthouseci + include-hidden-files: true warmup: needs: trusted From 9db25aa95b2f562e332f77784bb793cb6ff1423d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Mon, 16 Nov 2026 14:39:14 +0000 Subject: [PATCH 3/5] ci(e2e): fail closed on lookup errors and send the OIDC token only to the deployment Amp-Thread-ID: https://ampcode.com/threads/T-01a1d4e0-41a0-7295-89c7-113254d46fe1 --- .github/workflows/e2e.yml | 11 +++++++---- playwright.config.ts | 6 +----- test/browser/fixtures.ts | 20 ++++++++++++++++++++ test/browser/interactions.spec.ts | 2 +- test/browser/modules.spec.ts | 2 +- test/browser/pages.spec.ts | 2 +- 6 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 test/browser/fixtures.ts diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 20382978b..b93551ff9 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -25,7 +25,7 @@ jobs: - id: check run: | if [ "$EVENT_NAME" = workflow_dispatch ] || [ "$ENVIRONMENT" = Production ] || - [ "$(gh api "repos/$GITHUB_REPOSITORY/commits/$SHA/branches-where-head" --jq length)" != 0 ]; then + [ "$(gh api "repos/$GITHUB_REPOSITORY/commits/$SHA/branches-where-head" --jq length)" -gt 0 ]; then echo trusted=true >> "$GITHUB_OUTPUT" fi env: @@ -56,7 +56,8 @@ jobs: - name: Get the OIDC token id: oidc run: | - token=$(curl -sSf -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -r .value) + token=$(curl -sSf -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -er .value) + test -n "$token" echo "::add-mask::$token" echo "token=$token" >> "$GITHUB_OUTPUT" - name: Run Playwright E2E tests @@ -81,7 +82,8 @@ jobs: - name: Get the OIDC token id: oidc run: | - token=$(curl -sSf -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -r .value) + token=$(curl -sSf -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -er .value) + test -n "$token" echo "::add-mask::$token" echo "token=$token" >> "$GITHUB_OUTPUT" - name: Audit the URL with Lighthouse @@ -124,7 +126,8 @@ jobs: - name: Get the OIDC token id: oidc run: | - token=$(curl -sSf -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -r .value) + token=$(curl -sSf -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -er .value) + test -n "$token" echo "::add-mask::$token" echo "token=$token" >> "$GITHUB_OUTPUT" - name: warmup jobs, sponsors and modules diff --git a/playwright.config.ts b/playwright.config.ts index 19faace5c..272159cf6 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -7,10 +7,6 @@ export default defineConfig({ // TODO: fix issues with local testing with `@nuxt/content` // tests against deployment nuxt.com by default host: process.env.BASE_URL || 'https://nuxt.com' - }, - // Set by the e2e workflow to get through Vercel Deployment Protection on preview deployments - extraHTTPHeaders: process.env.VERCEL_TRUSTED_OIDC_TOKEN - ? { 'x-vercel-trusted-oidc-idp-token': process.env.VERCEL_TRUSTED_OIDC_TOKEN } - : undefined + } } }) diff --git a/test/browser/fixtures.ts b/test/browser/fixtures.ts new file mode 100644 index 000000000..b0540422b --- /dev/null +++ b/test/browser/fixtures.ts @@ -0,0 +1,20 @@ +import { test as base } from '@nuxt/test-utils/playwright' + +export { expect } from '@nuxt/test-utils/playwright' + +// Set by the e2e workflow to get through Vercel Deployment Protection. Only requests to the deployment under test get +// it, so third-party resources never see it. A redirect keeps the header, which the deployment's own redirects need +// (`/docs` redirects to `/docs/getting-started/introduction`). +const token = process.env.VERCEL_TRUSTED_OIDC_TOKEN +const origin = process.env.BASE_URL && new URL(process.env.BASE_URL).origin + +export const test = base.extend({ + context: async ({ context }, use) => { + if (token && origin) { + await context.route(url => url.origin === origin, route => route.continue({ + headers: { ...route.request().headers(), 'x-vercel-trusted-oidc-idp-token': token } + })) + } + await use(context) + } +}) diff --git a/test/browser/interactions.spec.ts b/test/browser/interactions.spec.ts index 3b33a395a..62e9c09cd 100644 --- a/test/browser/interactions.spec.ts +++ b/test/browser/interactions.spec.ts @@ -1,4 +1,4 @@ -import { expect, test } from '@nuxt/test-utils/playwright' +import { expect, test } from './fixtures' test.describe('User Interactions', () => { test('CTA buttons on homepage navigate correctly', async ({ page, goto }) => { diff --git a/test/browser/modules.spec.ts b/test/browser/modules.spec.ts index 88e54f565..e073e6d5a 100644 --- a/test/browser/modules.spec.ts +++ b/test/browser/modules.spec.ts @@ -1,4 +1,4 @@ -import { expect, test } from '@nuxt/test-utils/playwright' +import { expect, test } from './fixtures' test.describe('Modules Page', () => { test('loads successfully with module listing', async ({ page, goto }) => { diff --git a/test/browser/pages.spec.ts b/test/browser/pages.spec.ts index b80cce984..e2514431c 100644 --- a/test/browser/pages.spec.ts +++ b/test/browser/pages.spec.ts @@ -1,4 +1,4 @@ -import { expect, test } from '@nuxt/test-utils/playwright' +import { expect, test } from './fixtures' test.describe('Homepage', () => { test('has a visible hero description', async ({ page, goto }) => { From 96f080191c0a7bd84b3199b70c3aa9130670f8c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Mon, 16 Nov 2026 15:04:24 +0000 Subject: [PATCH 4/5] test(e2e): give assertions 15s for cold preview deployments Amp-Thread-ID: https://ampcode.com/threads/T-01a1d4e0-41a0-7295-89c7-113254d46fe1 --- playwright.config.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/playwright.config.ts b/playwright.config.ts index 272159cf6..27e0f4113 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -2,6 +2,9 @@ import { defineConfig } from '@playwright/test' import type { ConfigOptions } from '@nuxt/test-utils/playwright' export default defineConfig({ + // A fresh preview deployment renders its first payloads cold: `/docs/4.x/getting-started/installation/_payload.json` + // took 4.7 s, past the default 5 s once the click and route chunk are added. + expect: { timeout: 15_000 }, use: { nuxt: { // TODO: fix issues with local testing with `@nuxt/content` From 2946f9bd601cd026e8d9327d87efcda519ed80fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Mon, 16 Nov 2026 15:16:44 +0000 Subject: [PATCH 5/5] ci(e2e): warm up the tested pages before e2e and Lighthouse run Amp-Thread-ID: https://ampcode.com/threads/T-01a1d4e0-41a0-7295-89c7-113254d46fe1 --- .github/workflows/e2e.yml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index b93551ff9..a25bc2197 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -35,7 +35,7 @@ jobs: SHA: ${{ github.event.deployment.sha }} e2e: - needs: trusted + needs: [trusted, warmup] if: needs.trusted.outputs.trusted == 'true' environment: name: ${{ github.event.deployment.environment || 'Production' }} @@ -67,7 +67,7 @@ jobs: VERCEL_TRUSTED_OIDC_TOKEN: ${{ steps.oidc.outputs.token }} lighthouse: - needs: trusted + needs: [trusted, warmup] if: needs.trusted.outputs.trusted == 'true' environment: name: ${{ github.event.deployment.environment || 'Production' }} @@ -112,6 +112,8 @@ jobs: path: .lighthouseci include-hidden-files: true + # Runs before `e2e` and `lighthouse`: a fresh deployment has an empty ISR cache and cold functions, and its first + # renders took up to 4.7 s, enough to time out Playwright assertions and to skew Lighthouse. warmup: needs: trusted if: needs.trusted.outputs.trusted == 'true' @@ -130,11 +132,15 @@ jobs: test -n "$token" echo "::add-mask::$token" echo "token=$token" >> "$GITHUB_OUTPUT" - - name: warmup jobs, sponsors and modules + # The jobs, sponsors and modules APIs, then the pages `test/browser` visits, and the payload of the docs page the + # homepage "Get started" link opens client-side. + - name: warmup APIs and tested pages run: | - curl -sS -H "x-vercel-trusted-oidc-idp-token: $TOKEN" "$BASE_URL/api/jobs" - curl -sS -H "x-vercel-trusted-oidc-idp-token: $TOKEN" "$BASE_URL/api/sponsors" - curl -sS -H "x-vercel-trusted-oidc-idp-token: $TOKEN" "$BASE_URL/api/v1/modules" + for path in /api/jobs /api/sponsors /api/v1/modules \ + / /templates /updates /showcase /team /blog /enterprise /enterprise/agencies /sponsors /modules \ + /docs/4.x/getting-started/installation /docs/4.x/getting-started/installation/_payload.json; do + curl -sS -o /dev/null -w "%{http_code} %{time_total}s $path\n" -H "x-vercel-trusted-oidc-idp-token: $TOKEN" "$BASE_URL$path" + done env: BASE_URL: ${{ github.event.inputs.url || github.event.deployment_status.environment_url }} TOKEN: ${{ steps.oidc.outputs.token }}