Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add deploy cleanup step for Vercel tests #2699

Merged
merged 4 commits into from
Oct 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: add deploy cleanup step for Vercel tests
pieh committed Oct 25, 2024
commit 4299ce4fff7a4f518341fccdbe826b8be00a30f8
31 changes: 31 additions & 0 deletions tests/netlify-deploy.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

learning - why do we need to set this to false in the end? will it keep attempting and looping if we don't?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should not, this is just in case - I was looking at base class we extend - it does have some checks that look if something was deleted / destroyed already - there they throw:

https://github.com/vercel/next.js/blob/2e28c965279de90ce4bfca673196c27dd6117027/test/lib/next-modes/base.ts#L425-L428

but I didn't want to play with this as I don't fully know the contract that Vercel tests have with those modules - so this just felt safe way to just avoid wasting time on calling API to delete deploy that was already deleted in case this is called multiple times (deleteDeploy api call is not immediate - it takes couple seconds to finish so just no point in calling it again)

}
}

await super.destroy()
}

public get cliOutput() {