From d3d2fb5c7a3f87af29602c884e81987819286e7c Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Tue, 29 Oct 2024 19:57:15 +0100 Subject: [PATCH] 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 --- .github/workflows/e2e-report.yml | 2 +- .github/workflows/test-e2e.yml | 2 +- tests/netlify-deploy.ts | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e-report.yml b/.github/workflows/e2e-report.yml index 61239180e5..b3c22c4402 100644 --- a/.github/workflows/e2e-report.yml +++ b/.github/workflows/e2e-report.yml @@ -31,7 +31,7 @@ jobs: id: get-run-id run: | if [ "${{ inputs.use-branch }}" == "true" ]; then - 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) + E2E_RUN_ID=$(gh run list -w test-e2e.yml -s success -b $GITHUB_REF_NAME --json databaseId --jq ".[0].databaseId" --repo $GITHUB_REPOSITORY) else E2E_RUN_ID=$(gh run list -w test-e2e.yml -e schedule -s success --json databaseId --jq ".[0].databaseId" --repo $GITHUB_REPOSITORY) fi diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index 6d6ab29334..ddd2f6a534 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -28,7 +28,7 @@ env: DATADOG_TRACE_NEXTJS_TEST: true DATADOG_API_KEY: foo TEST_CONCURRENCY: 2 - NEXT_E2E_TEST_TIMEOUT: 300000 + NEXT_E2E_TEST_TIMEOUT: 600000 NEXT_TELEMETRY_DISABLED: 1 NEXT_SKIP_NATIVE_POSTINSTALL: 1 TURBO_API: ${{ secrets.TURBO_API }} diff --git a/tests/netlify-deploy.ts b/tests/netlify-deploy.ts index cbc6ab4982..13664acebe 100644 --- a/tests/netlify-deploy.ts +++ b/tests/netlify-deploy.ts @@ -35,6 +35,7 @@ export class NextDeployInstance extends NextInstance { private _cliOutput: string private _buildId: string private _deployId: string + private _shouldDeleteDeploy: boolean = false public get buildId() { // get deployment ID via fetch since we can't access @@ -50,6 +51,9 @@ export class NextDeployInstance extends NextInstance { this._buildId = process.env.BUILD_ID return } + + const setupStartTime = Date.now() + // create the test site await super.createTestDir({ parentSpan, skipInstall: true }) @@ -146,6 +150,7 @@ export class NextDeployInstance extends NextInstance { this._url = url this._parsedUrl = new URL(this._url) this._deployId = deployID + this._shouldDeleteDeploy = !process.env.NEXT_TEST_SKIP_CLEANUP this._cliOutput = deployRes.stdout + deployRes.stderr require('console').log(`Deployment URL: ${this._url}`) @@ -169,6 +174,32 @@ export class NextDeployInstance extends NextInstance { ).trim() require('console').log(`Got buildId: ${this._buildId}`) + require('console').log(`Setup time: ${(Date.now() - setupStartTime) / 1000.0}s`) + } + + public async destroy(): Promise { + if (this._shouldDeleteDeploy) { + require('console').log(`Deleting project with deploy_id ${this._deployId}`) + + const deleteResponse = await execa('npx', [ + 'ntl', + 'api', + 'deleteDeploy', + '--data', + `{ "deploy_id": "${this._deployId}" }`, + ]) + + if (deleteResponse.exitCode !== 0) { + require('console').error( + `Failed to delete deploy ${deleteResponse.stdout} ${deleteResponse.stderr} (${deleteResponse.exitCode})`, + ) + } else { + require('console').log(`Successfully deleted deploy with deploy_id ${this._deployId}`) + this._shouldDeleteDeploy = false + } + } + + await super.destroy() } public get cliOutput() {