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

[test] Authenticate deploy tests via VERCEL_TOKEN instead of shared auth.json (#99846)

Deploy tests now authenticate the Vercel CLI via the `VERCEL_TOKEN` env
var instead of writing a shared `$HOME/.vercel/auth.json` and passing
`--global-config` to every CLI invocation.

This reduces the chance of a read/write race on the shared auth.json.
I've never seen this with our current concurrency limits (2) but we saw
it immediately when bumping to 8
(https://github.com/vercel/next.js/actions/runs/37704518620/job/113083223389#step:35:386)

---------
Co-authored-by: 's avatarClaude Code <noreply@anthropic.com>
parent b2490553
import { nextTestSetup } from 'e2e-utils'
// trigger deploy tests v1
describe('hello-world', () => {
const { next } = nextTestSetup({
files: __dirname,
......
import os from 'os'
import path from 'path'
import dns from 'dns'
import execa from 'execa'
......@@ -417,27 +416,25 @@ export class NextDeployInstance extends NextInstance {
// the flag is enough to force plain-URL output for both link and deploy.
vercelFlags.push('--non-interactive=false')
if (process.env.RUNNER_DEBUG === '1') {
vercelFlags.push('--debug')
}
// If the token is available in the environment, use it as the token in the
// environment.
// environment. The CLI reads `VERCEL_TOKEN` (since vercel@50.12.1) and then
// neither reads nor writes the shared `auth.json`, which keeps parallel
// test jobs from racing on a non-atomically written credentials file.
if (TEST_TOKEN) {
vercelEnv.TOKEN = TEST_TOKEN
vercelEnv.VERCEL_TOKEN = TEST_TOKEN
}
// create auth file in CI
// validate auth is configured in CI
if (process.env.NEXT_TEST_JOB) {
if (!TEST_TOKEN && !TEST_TEAM_NAME) {
throw new Error(
'Missing TEST_TOKEN and TEST_TEAM_NAME environment variables for CI'
)
}
const vcConfigDir = path.join(os.homedir(), '.vercel')
await fs.ensureDir(vcConfigDir)
await fs.writeFile(
path.join(vcConfigDir, 'auth.json'),
JSON.stringify({ token: TEST_TOKEN })
)
vercelFlags.push('--global-config', vcConfigDir)
}
require('console').log(`Linking project at ${this.testDir}`)
......
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