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

[16.x][ci] Allow configuring the base URL for preview builds (#95829)

parent 6734ad3d
...@@ -980,7 +980,7 @@ function generatePrTarballSection(actionInfo) { ...@@ -980,7 +980,7 @@ function generatePrTarballSection(actionInfo) {
<summary><strong>📎 Tarball URL</strong></summary> <summary><strong>📎 Tarball URL</strong></summary>
\`\`\` \`\`\`
https://vercel-packages.vercel.app/next/commits/${actionInfo.githubHeadSha}/next ${actionInfo.previewBuildsBaseUrl}/commits/${actionInfo.githubHeadSha}/next
\`\`\` \`\`\`
</details> </details>
......
...@@ -16,6 +16,7 @@ module.exports = function actionInfo() { ...@@ -16,6 +16,7 @@ module.exports = function actionInfo() {
GITHUB_REPOSITORY, GITHUB_REPOSITORY,
GITHUB_EVENT_PATH, GITHUB_EVENT_PATH,
PR_STATS_COMMENT_TOKEN, PR_STATS_COMMENT_TOKEN,
PREVIEW_BUILDS_BASE_URL,
} = process.env } = process.env
delete process.env.GITHUB_TOKEN delete process.env.GITHUB_TOKEN
...@@ -63,6 +64,8 @@ module.exports = function actionInfo() { ...@@ -63,6 +64,8 @@ module.exports = function actionInfo() {
isRelease: isRelease:
GITHUB_REPOSITORY === 'vercel/next.js' && GITHUB_REPOSITORY === 'vercel/next.js' &&
(GITHUB_REF || '').includes('canary'), (GITHUB_REF || '').includes('canary'),
previewBuildsBaseUrl:
PREVIEW_BUILDS_BASE_URL || 'https://vercel-packages.vercel.app/next',
} }
if (info.isRelease) { if (info.isRelease) {
......
...@@ -581,7 +581,7 @@ jobs: ...@@ -581,7 +581,7 @@ jobs:
- name: Create tarballs - name: Create tarballs
# github.event.after is available on push and pull_request#synchronize events. # github.event.after is available on push and pull_request#synchronize events.
# For workflow_dispatch events, github.sha is the head commit. # For workflow_dispatch events, github.sha is the head commit.
run: node scripts/create-preview-tarballs.js "${{ github.event.after || github.sha }}" "${{ runner.temp }}/preview-tarballs" run: node scripts/create-preview-tarballs.js "${{ github.event.after || github.sha }}" "${{ runner.temp }}/preview-tarballs" "${{ vars.PREVIEW_BUILDS_BASE_URL }}"
- name: Upload tarballs - name: Upload tarballs
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
......
...@@ -743,7 +743,8 @@ jobs: ...@@ -743,7 +743,8 @@ jobs:
node scripts/test-new-tests.mjs \ node scripts/test-new-tests.mjs \
--flake-detection \ --flake-detection \
--mode dev \ --mode dev \
--group ${{ matrix.group }} --group ${{ matrix.group }} \
--preview-builds-base-url "${{ vars.PREVIEW_BUILDS_BASE_URL }}"
stepName: 'test-new-tests-dev-${{matrix.group}}' stepName: 'test-new-tests-dev-${{matrix.group}}'
timeout_minutes: 60 # Increase the default timeout as tests are intentionally run multiple times to detect flakes timeout_minutes: 60 # Increase the default timeout as tests are intentionally run multiple times to detect flakes
...@@ -768,7 +769,8 @@ jobs: ...@@ -768,7 +769,8 @@ jobs:
node scripts/test-new-tests.mjs \ node scripts/test-new-tests.mjs \
--flake-detection \ --flake-detection \
--mode start \ --mode start \
--group ${{ matrix.group }} --group ${{ matrix.group }} \
--preview-builds-base-url "${{ vars.PREVIEW_BUILDS_BASE_URL }}"
stepName: 'test-new-tests-start-${{matrix.group}}' stepName: 'test-new-tests-start-${{matrix.group}}'
timeout_minutes: 60 # Increase the default timeout as tests are intentionally run multiple times to detect flakes timeout_minutes: 60 # Increase the default timeout as tests are intentionally run multiple times to detect flakes
secrets: inherit secrets: inherit
...@@ -794,7 +796,8 @@ jobs: ...@@ -794,7 +796,8 @@ jobs:
export __NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES=true export __NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES=true
node scripts/test-new-tests.mjs \ node scripts/test-new-tests.mjs \
--mode deploy \ --mode deploy \
--group ${{ matrix.group }} --group ${{ matrix.group }} \
--preview-builds-base-url "${{ vars.PREVIEW_BUILDS_BASE_URL }}"
stepName: 'test-new-tests-deploy-${{matrix.group}}' stepName: 'test-new-tests-deploy-${{matrix.group}}'
secrets: inherit secrets: inherit
...@@ -823,7 +826,8 @@ jobs: ...@@ -823,7 +826,8 @@ jobs:
export NEXT_E2E_TEST_TIMEOUT=240000 export NEXT_E2E_TEST_TIMEOUT=240000
node scripts/test-new-tests.mjs \ node scripts/test-new-tests.mjs \
--mode deploy \ --mode deploy \
--group ${{ matrix.group }} --group ${{ matrix.group }} \
--preview-builds-base-url "${{ vars.PREVIEW_BUILDS_BASE_URL }}"
stepName: 'test-new-tests-deploy-cache-components-${{matrix.group}}' stepName: 'test-new-tests-deploy-cache-components-${{matrix.group}}'
secrets: inherit secrets: inherit
......
...@@ -123,6 +123,9 @@ env: ...@@ -123,6 +123,9 @@ env:
VERCEL_ADAPTER_TEST_TEAM: vtest314-next-adapter-e2e-tests VERCEL_ADAPTER_TEST_TEAM: vtest314-next-adapter-e2e-tests
VERCEL_TURBOPACK_TEST_TOKEN: ${{ secrets.VERCEL_TURBOPACK_TEST_TOKEN }} VERCEL_TURBOPACK_TEST_TOKEN: ${{ secrets.VERCEL_TURBOPACK_TEST_TOKEN }}
VERCEL_TURBOPACK_TEST_TEAM: vtest314-next-turbo-e2e-tests VERCEL_TURBOPACK_TEST_TEAM: vtest314-next-turbo-e2e-tests
# Read token for the auth-protected preview-builds npm mirror, used by deploy
# tests to install Next.js artifacts during the remote build.
PREVIEW_BUILDS_READ_TOKEN: ${{ secrets.PREVIEW_BUILDS_READ_TOKEN }}
NEXT_TEST_PREFER_OFFLINE: 1 NEXT_TEST_PREFER_OFFLINE: 1
NEXT_CI_RUNNER: ${{ inputs.runs_on_labels }} NEXT_CI_RUNNER: ${{ inputs.runs_on_labels }}
NEXT_TEST_PROXY_ADDRESS: ${{ inputs.overrideProxyAddress || '' }} NEXT_TEST_PROXY_ADDRESS: ${{ inputs.overrideProxyAddress || '' }}
......
...@@ -78,6 +78,7 @@ jobs: ...@@ -78,6 +78,7 @@ jobs:
TURBO_TEAM: ${{ env.TURBO_TEAM }} TURBO_TEAM: ${{ env.TURBO_TEAM }}
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_CACHE: ${{ env.TURBO_CACHE }} TURBO_CACHE: ${{ env.TURBO_CACHE }}
PREVIEW_BUILDS_BASE_URL: ${{ vars.PREVIEW_BUILDS_BASE_URL }}
- name: Upload stats results - name: Upload stats results
if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }} if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }}
......
...@@ -128,6 +128,7 @@ jobs: ...@@ -128,6 +128,7 @@ jobs:
NEXT_TEST_DEPLOY_SCRIPT_PATH="${{ github.event.inputs.deployScriptPath || '' }}" \ NEXT_TEST_DEPLOY_SCRIPT_PATH="${{ github.event.inputs.deployScriptPath || '' }}" \
NEXT_TEST_DEPLOY_LOGS_SCRIPT_PATH="${{ github.event.inputs.deployLogsScriptPath || '' }}" \ NEXT_TEST_DEPLOY_LOGS_SCRIPT_PATH="${{ github.event.inputs.deployLogsScriptPath || '' }}" \
NEXT_TEST_CLEANUP_SCRIPT_PATH="${{ github.event.inputs.cleanupScriptPath || '' }}" \ NEXT_TEST_CLEANUP_SCRIPT_PATH="${{ github.event.inputs.cleanupScriptPath || '' }}" \
NEXT_TEST_PREVIEW_BUILDS_BASE_URL="${{ vars.PREVIEW_BUILDS_BASE_URL }}" \
node run-tests.js --timings --require-timings -g ${{ matrix.group }} -c 2 --type e2e node run-tests.js --timings --require-timings -g ${{ matrix.group }} -c 2 --type e2e
testTimingsArtifact: 'test-timings' testTimingsArtifact: 'test-timings'
skipNativeBuild: 'yes' skipNativeBuild: 'yes'
...@@ -173,6 +174,7 @@ jobs: ...@@ -173,6 +174,7 @@ jobs:
NEXT_TEST_DEPLOY_SCRIPT_PATH="${{ github.event.inputs.deployScriptPath || '' }}" \ NEXT_TEST_DEPLOY_SCRIPT_PATH="${{ github.event.inputs.deployScriptPath || '' }}" \
NEXT_TEST_DEPLOY_LOGS_SCRIPT_PATH="${{ github.event.inputs.deployLogsScriptPath || '' }}" \ NEXT_TEST_DEPLOY_LOGS_SCRIPT_PATH="${{ github.event.inputs.deployLogsScriptPath || '' }}" \
NEXT_TEST_CLEANUP_SCRIPT_PATH="${{ github.event.inputs.cleanupScriptPath || '' }}" \ NEXT_TEST_CLEANUP_SCRIPT_PATH="${{ github.event.inputs.cleanupScriptPath || '' }}" \
NEXT_TEST_PREVIEW_BUILDS_BASE_URL="${{ vars.PREVIEW_BUILDS_BASE_URL }}" \
node run-tests.js --timings --require-timings -g ${{ matrix.group }} -c 2 --type e2e node run-tests.js --timings --require-timings -g ${{ matrix.group }} -c 2 --type e2e
testTimingsArtifact: 'test-timings' testTimingsArtifact: 'test-timings'
skipNativeBuild: 'yes' skipNativeBuild: 'yes'
...@@ -216,6 +218,7 @@ jobs: ...@@ -216,6 +218,7 @@ jobs:
NEXT_EXTERNAL_TESTS_FILTERS="test/deploy-tests-manifest.json" \ NEXT_EXTERNAL_TESTS_FILTERS="test/deploy-tests-manifest.json" \
NEXT_TEST_VERSION="${{ github.event.inputs.nextVersion || needs.setup.outputs.next-version || 'canary' }}" \ NEXT_TEST_VERSION="${{ github.event.inputs.nextVersion || needs.setup.outputs.next-version || 'canary' }}" \
VERCEL_CLI_VERSION="${{ github.event.inputs.vercelCliVersion || 'vercel@latest' }}" \ VERCEL_CLI_VERSION="${{ github.event.inputs.vercelCliVersion || 'vercel@latest' }}" \
NEXT_TEST_PREVIEW_BUILDS_BASE_URL="${{ vars.PREVIEW_BUILDS_BASE_URL }}" \
node run-tests.js --timings --require-timings -g ${{ matrix.group }} -c 2 --type e2e node run-tests.js --timings --require-timings -g ${{ matrix.group }} -c 2 --type e2e
testTimingsArtifact: 'test-timings' testTimingsArtifact: 'test-timings'
skipNativeBuild: 'yes' skipNativeBuild: 'yes'
......
...@@ -8,7 +8,9 @@ async function main() { ...@@ -8,7 +8,9 @@ async function main() {
const [ const [
githubHeadSha, githubHeadSha,
tarballDirectory = path.join(os.tmpdir(), 'vercel-nextjs-preview-tarballs'), tarballDirectory = path.join(os.tmpdir(), 'vercel-nextjs-preview-tarballs'),
baseUrlArg,
] = process.argv.slice(2) ] = process.argv.slice(2)
const baseUrl = baseUrlArg || 'https://vercel-packages.vercel.app/next'
const repoRoot = path.resolve(__dirname, '..') const repoRoot = path.resolve(__dirname, '..')
await fs.mkdir(tarballDirectory, { recursive: true }) await fs.mkdir(tarballDirectory, { recursive: true })
...@@ -87,13 +89,13 @@ async function main() { ...@@ -87,13 +89,13 @@ async function main() {
for (const packageInfo of packages) { for (const packageInfo of packages) {
packagesByVersion.set( packagesByVersion.set(
packageInfo.name, packageInfo.name,
`https://vercel-packages.vercel.app/next/commits/${githubHeadSha}/${packageInfo.name}` `${baseUrl}/commits/${githubHeadSha}/${packageInfo.name}`
) )
} }
for (const nextSwcPackageName of nextSwcPackageNames) { for (const nextSwcPackageName of nextSwcPackageNames) {
packagesByVersion.set( packagesByVersion.set(
nextSwcPackageName, nextSwcPackageName,
`https://vercel-packages.vercel.app/next/commits/${githubHeadSha}/${nextSwcPackageName}` `${baseUrl}/commits/${githubHeadSha}/${nextSwcPackageName}`
) )
} }
......
...@@ -14,11 +14,14 @@ async function main() { ...@@ -14,11 +14,14 @@ async function main() {
const argv = await yargs(process.argv.slice(2)) const argv = await yargs(process.argv.slice(2))
.string('mode') .string('mode')
.string('group') .string('group')
.string('preview-builds-base-url')
.boolean('flake-detection').argv .boolean('flake-detection').argv
const testMode = argv.mode const testMode = argv.mode
const isFlakeDetectionMode = argv['flake-detection'] const isFlakeDetectionMode = argv['flake-detection']
const attempts = isFlakeDetectionMode ? 3 : 1 const attempts = isFlakeDetectionMode ? 3 : 1
const previewBuildsBaseUrl =
argv['preview-builds-base-url'] || 'https://vercel-packages.vercel.app/next'
if (testMode && !['dev', 'deploy', 'start'].includes(testMode)) { if (testMode && !['dev', 'deploy', 'start'].includes(testMode)) {
throw new Error( throw new Error(
...@@ -92,16 +95,21 @@ async function main() { ...@@ -92,16 +95,21 @@ async function main() {
// PR number endpoint (which resolves the PR to a SHA on every request). // PR number endpoint (which resolves the PR to a SHA on every request).
const nextTestVersion = const nextTestVersion =
testMode === 'deploy' testMode === 'deploy'
? `https://vercel-packages.vercel.app/next/commits/${commitSha}/next` ? `${previewBuildsBaseUrl}/commits/${commitSha}/next`
: undefined : undefined
const previewBuildsReadToken = process.env.PREVIEW_BUILDS_READ_TOKEN
if (nextTestVersion) { if (nextTestVersion) {
console.log(`Verifying artifacts for commit ${commitSha}`) console.log(`Verifying artifacts for commit ${commitSha}`)
// Attempt to fetch the deploy artifacts for the commit // Attempt to fetch the deploy artifacts for the commit
// These might take a moment to become available, so we'll retry a few times // These might take a moment to become available, so we'll retry a few times
const fetchHeaders = previewBuildsReadToken
? { Authorization: `Bearer ${previewBuildsReadToken}` }
: undefined
const fetchWithRetry = async (url, retries = 5, timeout = 5000) => { const fetchWithRetry = async (url, retries = 5, timeout = 5000) => {
for (let i = 0; i < retries; i++) { for (let i = 0; i < retries; i++) {
const res = await fetch(url) const res = await fetch(url, { headers: fetchHeaders })
if (res.ok) { if (res.ok) {
return res return res
} else if (i < retries - 1) { } else if (i < retries - 1) {
...@@ -159,6 +167,7 @@ async function main() { ...@@ -159,6 +167,7 @@ async function main() {
...process.env, ...process.env,
NEXT_TEST_MODE: testMode, NEXT_TEST_MODE: testMode,
NEXT_TEST_VERSION: nextTestVersion, NEXT_TEST_VERSION: nextTestVersion,
NEXT_TEST_PREVIEW_BUILDS_BASE_URL: previewBuildsBaseUrl,
NEXT_EXTERNAL_TESTS_FILTERS, NEXT_EXTERNAL_TESTS_FILTERS,
NEXT_FLAKE_DETECTION: '1', NEXT_FLAKE_DETECTION: '1',
IS_TURBOPACK_TEST: '1', IS_TURBOPACK_TEST: '1',
...@@ -179,6 +188,7 @@ async function main() { ...@@ -179,6 +188,7 @@ async function main() {
NEXT_EXTERNAL_TESTS_FILTERS, NEXT_EXTERNAL_TESTS_FILTERS,
NEXT_TEST_MODE: testMode, NEXT_TEST_MODE: testMode,
NEXT_TEST_VERSION: nextTestVersion, NEXT_TEST_VERSION: nextTestVersion,
NEXT_TEST_PREVIEW_BUILDS_BASE_URL: previewBuildsBaseUrl,
IS_WEBPACK_TEST: '1', IS_WEBPACK_TEST: '1',
}, },
}) })
......
...@@ -189,6 +189,8 @@ export class NextDeployInstance extends NextInstance { ...@@ -189,6 +189,8 @@ export class NextDeployInstance extends NextInstance {
super.setup(parentSpan) super.setup(parentSpan)
await super.createTestDir({ parentSpan, skipInstall: true }) await super.createTestDir({ parentSpan, skipInstall: true })
await this.writeMirrorNpmrcIfNecessary()
const existingDeployUrl = process.env.NEXT_TEST_DEPLOY_URL?.trim() const existingDeployUrl = process.env.NEXT_TEST_DEPLOY_URL?.trim()
const customDeployScriptPath = const customDeployScriptPath =
process.env.NEXT_TEST_DEPLOY_SCRIPT_PATH?.trim() process.env.NEXT_TEST_DEPLOY_SCRIPT_PATH?.trim()
...@@ -443,6 +445,36 @@ export class NextDeployInstance extends NextInstance { ...@@ -443,6 +445,36 @@ export class NextDeployInstance extends NextInstance {
// output other unrelated logs to stderr. // output other unrelated logs to stderr.
} }
// When the preview-builds npm mirror is auth-protected, the deploy build
// installs Next.js artifacts from it and needs credentials. We write an
// `.npmrc` with a read token (provided as a CI secret) so the remote install
// can authenticate. Only written when the token is set, so unprotected and
// local deploy runs are unaffected.
private async writeMirrorNpmrcIfNecessary(): Promise<void> {
const token = process.env.PREVIEW_BUILDS_READ_TOKEN
const baseUrlRaw = process.env.NEXT_TEST_PREVIEW_BUILDS_BASE_URL
if (!token || !baseUrlRaw) {
require('console').log(
`Skipping .npmrc write for preview-builds mirror: missing token or base URL`
)
return
}
const baseUrl = new URL(baseUrlRaw)
// Derive the npmrc auth key from the mirror base URL: strip the scheme and
// ensure a trailing slash so it matches requests to that registry path.
const registryKey = `//${baseUrl.host}${baseUrl.pathname.replace(/\/?$/, '/')}`
require('console').log(
`Writing .npmrc for preview-builds mirror: ${registryKey}`
)
await fs.writeFile(
path.join(this.testDir, '.npmrc'),
`${registryKey}:_authToken=${token}\n`
)
}
private async configureProxyAddress(): Promise<void> { private async configureProxyAddress(): Promise<void> {
// If configured, we should configure the `/etc/hosts` file to point the // If configured, we should configure the `/etc/hosts` file to point the
// deployment domain to the specified proxy address. // deployment domain to the specified proxy address.
......
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