Unverified Commit dd904bb7 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[ci] Upload adapter test results via GitHub Actions OIDC (#100400)

Switches the adapter test-results upload from a shared secret to GitHub
Actions OIDC.

Requires https://github.com/vercel/front/pull/92017

## test plan

- [x] [e2e deploy tests fail upload because not dispatched on a
tag](https://github.com/vercel/next.js/actions/runs/39380276061) ->
https://vercel.com/vercel/next-site/logs?panelState=opened&search=%22%2Fapi%2Fadapter-test-results%22&timeline=past12Hours

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: 's avatarClaude Code <noreply@anthropic.com>
parent 4550be40
...@@ -351,6 +351,10 @@ jobs: ...@@ -351,6 +351,10 @@ jobs:
github.repository_owner == 'vercel' && github.repository_owner == 'vercel' &&
!startsWith(needs.setup.outputs.next-version, 'http') !startsWith(needs.setup.outputs.next-version, 'http')
}} }}
permissions:
contents: read
# Minting a GitHub OIDC token to authenticate the results upload.
id-token: write
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout
...@@ -375,11 +379,6 @@ jobs: ...@@ -375,11 +379,6 @@ jobs:
- name: Upload adapter test results - name: Upload adapter test results
run: | run: |
if [ -z "${ADAPTER_TEST_RESULTS_SECRET:-}" ]; then
echo "ADAPTER_TEST_RESULTS_SECRET is not configured, skipping upload"
exit 0
fi
if [ ! -d adapter-test-results ]; then if [ ! -d adapter-test-results ]; then
echo "No adapter test artifact directory found, skipping upload" echo "No adapter test artifact directory found, skipping upload"
exit 0 exit 0
...@@ -391,8 +390,4 @@ jobs: ...@@ -391,8 +390,4 @@ jobs:
fi fi
node scripts/upload-adapter-test-results.mjs \ node scripts/upload-adapter-test-results.mjs \
--results-root adapter-test-results \ --results-root adapter-test-results
--provider vercel \
--commit-sha "${{ github.sha }}"
env:
ADAPTER_TEST_RESULTS_SECRET: ${{ secrets.ADAPTER_TEST_RESULTS_SECRET }}
...@@ -131,8 +131,53 @@ jobs: ...@@ -131,8 +131,53 @@ jobs:
NEXT_TEST_DEPLOY_LOGS_SCRIPT_PATH: ${{ github.workspace }}/adapter/scripts/e2e-logs.sh NEXT_TEST_DEPLOY_LOGS_SCRIPT_PATH: ${{ github.workspace }}/adapter/scripts/e2e-logs.sh
NEXT_TEST_CLEANUP_SCRIPT_PATH: ${{ github.workspace }}/adapter/scripts/e2e-cleanup.sh NEXT_TEST_CLEANUP_SCRIPT_PATH: ${{ github.workspace }}/adapter/scripts/e2e-cleanup.sh
run: node run-tests.js --timings -g ${{ matrix.group }} -c 2 --type e2e run: node run-tests.js --timings -g ${{ matrix.group }} -c 2 --type e2e
- name: Save test results
if: always()
uses: actions/upload-artifact@v4
with:
name: adapter-test-results-${{ strategy.job-index }}
path: '**/*.results.json'
retention-days: 1
upload-results:
name: Report results to nextjs.org
needs: test
if: always()
runs-on: ubuntu-latest
permissions:
contents: read
# Minting a GitHub OIDC token to authenticate the results upload.
id-token: write
steps:
- uses: actions/checkout@v4
with:
repository: vercel/next.js
ref: ${{ inputs.nextjsRef || 'canary' }}
path: nextjs
- uses: actions/setup-node@v4
with: { node-version: '20' }
- uses: actions/download-artifact@v4
with:
pattern: adapter-test-results-*
path: adapter-test-results
merge-multiple: true
- name: Upload adapter test results
working-directory: nextjs
run: node scripts/upload-adapter-test-results.mjs --results-root ../adapter-test-results
``` ```
## Reporting results to nextjs.org
The `upload-results` job above sends your results to the adapter test-results endpoint, which powers the [Adapter Support by Provider](https://nextjs.org/docs/app/api-reference/adapters/supported-providers) matrix.
The upload authenticates with a GitHub Actions OIDC token, so it needs the `id-token: write` permission shown above. No secret is issued or stored: the provider name and commit SHA are derived from the token claims, which means results can only be attributed to the repository and workflow that produced them.
**Getting listed:** the matrix is open to adapters in the [Ecosystem Working Group](https://nextjs.org/ecosystem-working-group). See [Deploying to Platforms](/docs/app/guides/deploying-to-platforms) for how verified adapters and the working group operate. Your repository and workflow are registered as part of that process. Your results appear on the matrix after your next workflow run. Until then the upload returns `403 Forbidden`.
The test harness looks for these environment variables: The test harness looks for these environment variables:
- `NEXT_TEST_DEPLOY_SCRIPT_PATH`: Path to the executable that builds and deploys the isolated test app - `NEXT_TEST_DEPLOY_SCRIPT_PATH`: Path to the executable that builds and deploys the isolated test app
......
...@@ -5,7 +5,6 @@ import { spawn } from 'node:child_process' ...@@ -5,7 +5,6 @@ import { spawn } from 'node:child_process'
const RESULT_FILE_SUFFIX = '.results.json' const RESULT_FILE_SUFFIX = '.results.json'
const DEFAULT_ENDPOINT = 'https://nextjs.org/api/adapter-test-results' const DEFAULT_ENDPOINT = 'https://nextjs.org/api/adapter-test-results'
const COMMIT_SHA_PATTERN = /^[0-9a-f]{7,40}$/i
const BOOLEAN_ARGS = new Set(['help', 'dry-run']) const BOOLEAN_ARGS = new Set(['help', 'dry-run'])
const IGNORED_DIRECTORIES = new Set([ const IGNORED_DIRECTORIES = new Set([
'.git', '.git',
...@@ -26,17 +25,15 @@ function usage() { ...@@ -26,17 +25,15 @@ function usage() {
'', '',
'Usage:', 'Usage:',
' node scripts/upload-adapter-test-results.mjs \\', ' node scripts/upload-adapter-test-results.mjs \\',
' --results-root ~/dev/next.js \\', ' --results-root adapter-test-results',
' --provider vercel \\',
' --secret "$ADAPTER_TEST_RESULTS_SECRET" \\',
' --commit-sha "$(git -C ~/dev/next.js rev-parse HEAD)"',
'', '',
'Required:', 'Auth: GitHub Actions OIDC. Mints an OIDC token and sends it as a Bearer',
' --provider <name> or ADAPTER_TEST_RESULTS_PROVIDER', 'token. Requires a GitHub Actions job with `id-token: write`. Provider and',
' --secret <secret> or ADAPTER_TEST_RESULTS_SECRET', 'commit SHA are derived server-side from the token claims.',
' --commit-sha <sha> or ADAPTER_TEST_RESULTS_COMMIT_SHA or GITHUB_SHA',
'', '',
'Optional:', 'Optional:',
' --audience <url> or ADAPTER_TEST_RESULTS_AUDIENCE;',
' default: the endpoint URL',
` --results-root <path> default: ${process.cwd()}`, ` --results-root <path> default: ${process.cwd()}`,
` --endpoint <url> default: ${DEFAULT_ENDPOINT}`, ` --endpoint <url> default: ${DEFAULT_ENDPOINT}`,
' --zip-out <path> write zip to disk before upload', ' --zip-out <path> write zip to disk before upload',
...@@ -206,6 +203,26 @@ async function createArchive(resultsRoot, files) { ...@@ -206,6 +203,26 @@ async function createArchive(resultsRoot, files) {
} }
} }
async function mintGitHubActionsOidcToken(audience) {
const requestUrl = process.env.ACTIONS_ID_TOKEN_REQUEST_URL
const requestToken = process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN
if (!requestUrl || !requestToken) {
return null
}
const url = new URL(requestUrl)
url.searchParams.set('audience', audience)
const response = await fetch(url, {
headers: { Authorization: `Bearer ${requestToken}` },
})
if (!response.ok) {
throw new Error(
`Failed to mint GitHub OIDC token: ${response.status} ${await response.text()}`
)
}
const { value } = await response.json()
return value
}
async function main() { async function main() {
const args = parseArgs(process.argv) const args = parseArgs(process.argv)
...@@ -214,18 +231,12 @@ async function main() { ...@@ -214,18 +231,12 @@ async function main() {
return return
} }
const provider =
args.provider || process.env.ADAPTER_TEST_RESULTS_PROVIDER || ''
const secret = args.secret || process.env.ADAPTER_TEST_RESULTS_SECRET || ''
const commitSha =
args['commit-sha'] ||
process.env.ADAPTER_TEST_RESULTS_COMMIT_SHA ||
process.env.GITHUB_SHA ||
''
const endpoint = const endpoint =
args.endpoint || args.endpoint ||
process.env.ADAPTER_TEST_RESULTS_ENDPOINT || process.env.ADAPTER_TEST_RESULTS_ENDPOINT ||
DEFAULT_ENDPOINT DEFAULT_ENDPOINT
const audience =
args.audience || process.env.ADAPTER_TEST_RESULTS_AUDIENCE || endpoint
const inputRoot = args['results-root'] || process.cwd() const inputRoot = args['results-root'] || process.cwd()
const resultsRoot = path.resolve(resolvePathWithHome(String(inputRoot))) const resultsRoot = path.resolve(resolvePathWithHome(String(inputRoot)))
const zipOutArg = args['zip-out'] const zipOutArg = args['zip-out']
...@@ -234,24 +245,6 @@ async function main() { ...@@ -234,24 +245,6 @@ async function main() {
: null : null
const dryRun = Boolean(args['dry-run']) const dryRun = Boolean(args['dry-run'])
if (!provider) {
throw new Error(
'Missing provider. Pass --provider or ADAPTER_TEST_RESULTS_PROVIDER.'
)
}
if (!secret) {
throw new Error(
'Missing secret. Pass --secret or ADAPTER_TEST_RESULTS_SECRET.'
)
}
if (!commitSha || !COMMIT_SHA_PATTERN.test(String(commitSha))) {
throw new Error(
'Invalid commit SHA. Pass --commit-sha (7-40 hex chars), ADAPTER_TEST_RESULTS_COMMIT_SHA, or GITHUB_SHA.'
)
}
const stat = await fs.stat(resultsRoot).catch(() => null) const stat = await fs.stat(resultsRoot).catch(() => null)
if (!stat || !stat.isDirectory()) { if (!stat || !stat.isDirectory()) {
throw new Error( throw new Error(
...@@ -281,15 +274,21 @@ async function main() { ...@@ -281,15 +274,21 @@ async function main() {
return return
} }
const headers = { 'content-type': 'application/zip' }
console.log(`Auth: GitHub Actions OIDC (audience ${audience})`)
const oidcToken = await mintGitHubActionsOidcToken(audience)
if (!oidcToken) {
throw new Error(
'GitHub Actions OIDC token unavailable. Run in a GitHub Actions job with `id-token: write`.'
)
}
headers.authorization = `Bearer ${oidcToken}`
console.log(`Uploading to: ${endpoint}`) console.log(`Uploading to: ${endpoint}`)
const response = await fetch(endpoint, { const response = await fetch(endpoint, {
method: 'POST', method: 'POST',
headers: { headers,
'content-type': 'application/zip',
'x-adapter-test-results-provider': String(provider),
'x-adapter-test-results-secret': String(secret),
'x-adapter-test-results-commit-sha': String(commitSha),
},
body: archive, body: archive,
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment