ci: disable deployment protection for e2e test project (#58830)

Since we reset the test project on every e2e CI run, deployment protection is automatically enabled by default.

This adds an option to the reset project workflow to disable deployment protection. Our test runners need to be able to hit these pages from an unauthenticated browser in order for the tests to work. 

Verified tests are running properly in [this run](https://github.com/vercel/next.js/actions/runs/6971348806/job/18971225559) (fixing any failing tests themselves are out of scope for this PR; will evaluate once the run finishes)

Closes NEXT-1732
This commit is contained in:
Zack Tanner 2023-11-23 09:41:34 -08:00 committed by GitHub
parent cbcd59889c
commit 0cb1c40400
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 10 deletions

View file

@ -47,7 +47,7 @@ jobs:
- run: npm i -g vercel@latest
- run: node scripts/run-project-reset.mjs
- run: node scripts/run-e2e-test-project-reset.mjs
name: Reset test project
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.35.1-jammy /bin/bash -c "cd /work && NODE_VERSION=${{ env.NODE_LTS_VERSION }} ./scripts/setup-node.sh && corepack enable > /dev/null && NEXT_JUNIT_TEST_REPORT=true DATADOG_API_KEY=${DATADOG_API_KEY} DD_ENV=ci VERCEL_TEST_TOKEN=${{ secrets.VERCEL_TEST_TOKEN }} VERCEL_TEST_TEAM=vtest314-next-e2e-tests NEXT_TEST_JOB=1 NEXT_TEST_MODE=deploy TEST_TIMINGS_TOKEN=${{ secrets.TEST_TIMINGS_TOKEN }} NEXT_TEST_CONTINUE_ON_ERROR=1 xvfb-run node run-tests.js --type e2e --timings -g ${{ matrix.group }}/2 -c 1 >> /proc/1/fd/1"

View file

@ -36,7 +36,11 @@ export async function generateProjects() {
{
title: 'Resetting project',
task: async () => {
await resetProject(TEST_TEAM_NAME, ORIGIN_PROJECT_NAME)
await resetProject({
teamId: TEST_TEAM_NAME,
projectName: ORIGIN_PROJECT_NAME,
disableDeploymentProtection: true,
})
},
},
{
@ -73,7 +77,11 @@ export async function generateProjects() {
{
title: 'Resetting project',
task: async () => {
await resetProject(TEST_TEAM_NAME, HEAD_PROJECT_NAME)
await resetProject({
teamId: TEST_TEAM_NAME,
projectName: HEAD_PROJECT_NAME,
disableDeploymentProtection: true,
})
},
},
{

View file

@ -4,10 +4,12 @@ export const TEST_PROJECT_NAME = 'vtest314-e2e-tests'
export const TEST_TEAM_NAME = process.env.VERCEL_TEST_TEAM
export const TEST_TOKEN = process.env.VERCEL_TEST_TOKEN
export async function resetProject(
export async function resetProject({
teamId = TEST_TEAM_NAME,
projectName = TEST_PROJECT_NAME
) {
projectName = TEST_PROJECT_NAME,
disableDeploymentProtection,
}) {
console.log(`Resetting project ${teamId}/${projectName}`)
// TODO: error/bail if existing deployments are pending
const deleteRes = await fetch(
`https://vercel.com/api/v8/projects/${encodeURIComponent(
@ -46,12 +48,46 @@ export async function resetProject(
if (!createRes.ok) {
throw new Error(
`Failed to create project got status ${
`Failed to create project. Got status: ${
createRes.status
}, ${await createRes.text()}`
)
}
const { id: projectId } = await createRes.json()
if (!projectId) {
throw new Error("Couldn't get projectId from create project response")
}
if (disableDeploymentProtection) {
console.log('Disabling deployment protection...')
const patchRes = await fetch(
`https://vercel.com/api/v8/projects/${encodeURIComponent(
projectId
)}?teamId=${teamId}`,
{
method: 'PATCH',
headers: {
'content-type': 'application/json',
Authorization: `Bearer ${TEST_TOKEN}`,
},
body: JSON.stringify({
ssoProtection: null,
}),
}
)
if (!patchRes.ok) {
throw new Error(
`Failed to disable deployment protection. Got status: ${
patchRes.status
}, ${await patchRes.text()}`
)
}
}
console.log(
`Successfully created fresh Vercel project ${teamId}/${projectName}`
)

View file

@ -0,0 +1,11 @@
import {
resetProject,
TEST_PROJECT_NAME,
TEST_TEAM_NAME,
} from './reset-project.mjs'
resetProject({
projectName: TEST_PROJECT_NAME,
teamId: TEST_TEAM_NAME,
disableDeploymentProtection: true,
}).catch(console.error)

View file

@ -1,3 +0,0 @@
import { resetProject } from './reset-project.mjs'
resetProject().catch(console.error)