Unverified Commit 0cb1c404 authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

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
parent cbcd5988
...@@ -47,7 +47,7 @@ jobs: ...@@ -47,7 +47,7 @@ jobs:
- run: npm i -g vercel@latest - 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 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" - 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"
......
...@@ -36,7 +36,11 @@ export async function generateProjects() { ...@@ -36,7 +36,11 @@ export async function generateProjects() {
{ {
title: 'Resetting project', title: 'Resetting project',
task: async () => { 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() { ...@@ -73,7 +77,11 @@ export async function generateProjects() {
{ {
title: 'Resetting project', title: 'Resetting project',
task: async () => { task: async () => {
await resetProject(TEST_TEAM_NAME, HEAD_PROJECT_NAME) await resetProject({
teamId: TEST_TEAM_NAME,
projectName: HEAD_PROJECT_NAME,
disableDeploymentProtection: true,
})
}, },
}, },
{ {
......
...@@ -4,10 +4,12 @@ export const TEST_PROJECT_NAME = 'vtest314-e2e-tests' ...@@ -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_TEAM_NAME = process.env.VERCEL_TEST_TEAM
export const TEST_TOKEN = process.env.VERCEL_TEST_TOKEN export const TEST_TOKEN = process.env.VERCEL_TEST_TOKEN
export async function resetProject( export async function resetProject({
teamId = TEST_TEAM_NAME, 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 // TODO: error/bail if existing deployments are pending
const deleteRes = await fetch( const deleteRes = await fetch(
`https://vercel.com/api/v8/projects/${encodeURIComponent( `https://vercel.com/api/v8/projects/${encodeURIComponent(
...@@ -46,12 +48,46 @@ export async function resetProject( ...@@ -46,12 +48,46 @@ export async function resetProject(
if (!createRes.ok) { if (!createRes.ok) {
throw new Error( throw new Error(
`Failed to create project got status ${ `Failed to create project. Got status: ${
createRes.status createRes.status
}, ${await createRes.text()}` }, ${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( console.log(
`Successfully created fresh Vercel project ${teamId}/${projectName}` `Successfully created fresh Vercel project ${teamId}/${projectName}`
) )
......
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)
import { resetProject } from './reset-project.mjs'
resetProject().catch(console.error)
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