Skip to content

Commit d3d2fb5

Browse files
authored
ci: add deploy cleanup step for Vercel tests (#2699)
* test: add deploy cleanup step for Vercel tests * test: increase timeout for Vercel tests * test: bump timeout * ci: allow using test results from runs triggered by pull_request when deploying e2e report using branch results
1 parent 3e745e4 commit d3d2fb5

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

.github/workflows/e2e-report.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
id: get-run-id
3232
run: |
3333
if [ "${{ inputs.use-branch }}" == "true" ]; then
34-
E2E_RUN_ID=$(gh run list -w test-e2e.yml -e workflow_dispatch -s success -b $GITHUB_REF_NAME --json databaseId --jq ".[0].databaseId" --repo $GITHUB_REPOSITORY)
34+
E2E_RUN_ID=$(gh run list -w test-e2e.yml -s success -b $GITHUB_REF_NAME --json databaseId --jq ".[0].databaseId" --repo $GITHUB_REPOSITORY)
3535
else
3636
E2E_RUN_ID=$(gh run list -w test-e2e.yml -e schedule -s success --json databaseId --jq ".[0].databaseId" --repo $GITHUB_REPOSITORY)
3737
fi

.github/workflows/test-e2e.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ env:
2828
DATADOG_TRACE_NEXTJS_TEST: true
2929
DATADOG_API_KEY: foo
3030
TEST_CONCURRENCY: 2
31-
NEXT_E2E_TEST_TIMEOUT: 300000
31+
NEXT_E2E_TEST_TIMEOUT: 600000
3232
NEXT_TELEMETRY_DISABLED: 1
3333
NEXT_SKIP_NATIVE_POSTINSTALL: 1
3434
TURBO_API: ${{ secrets.TURBO_API }}

tests/netlify-deploy.ts

+31
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export class NextDeployInstance extends NextInstance {
3535
private _cliOutput: string
3636
private _buildId: string
3737
private _deployId: string
38+
private _shouldDeleteDeploy: boolean = false
3839

3940
public get buildId() {
4041
// get deployment ID via fetch since we can't access
@@ -50,6 +51,9 @@ export class NextDeployInstance extends NextInstance {
5051
this._buildId = process.env.BUILD_ID
5152
return
5253
}
54+
55+
const setupStartTime = Date.now()
56+
5357
// create the test site
5458
await super.createTestDir({ parentSpan, skipInstall: true })
5559

@@ -146,6 +150,7 @@ export class NextDeployInstance extends NextInstance {
146150
this._url = url
147151
this._parsedUrl = new URL(this._url)
148152
this._deployId = deployID
153+
this._shouldDeleteDeploy = !process.env.NEXT_TEST_SKIP_CLEANUP
149154
this._cliOutput = deployRes.stdout + deployRes.stderr
150155
require('console').log(`Deployment URL: ${this._url}`)
151156

@@ -169,6 +174,32 @@ export class NextDeployInstance extends NextInstance {
169174
).trim()
170175

171176
require('console').log(`Got buildId: ${this._buildId}`)
177+
require('console').log(`Setup time: ${(Date.now() - setupStartTime) / 1000.0}s`)
178+
}
179+
180+
public async destroy(): Promise<void> {
181+
if (this._shouldDeleteDeploy) {
182+
require('console').log(`Deleting project with deploy_id ${this._deployId}`)
183+
184+
const deleteResponse = await execa('npx', [
185+
'ntl',
186+
'api',
187+
'deleteDeploy',
188+
'--data',
189+
`{ "deploy_id": "${this._deployId}" }`,
190+
])
191+
192+
if (deleteResponse.exitCode !== 0) {
193+
require('console').error(
194+
`Failed to delete deploy ${deleteResponse.stdout} ${deleteResponse.stderr} (${deleteResponse.exitCode})`,
195+
)
196+
} else {
197+
require('console').log(`Successfully deleted deploy with deploy_id ${this._deployId}`)
198+
this._shouldDeleteDeploy = false
199+
}
200+
}
201+
202+
await super.destroy()
172203
}
173204

174205
public get cliOutput() {

0 commit comments

Comments
 (0)