-
Notifications
You must be signed in to change notification settings - Fork 88
chore: delete e2e deploys in afterAll #2004
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ff314f9
chore: delete test deploys in afterAll call
LekoArts b654c69
chore: add netlify-cli to devDeps
LekoArts de3f8ea
chore: update next-deploy
LekoArts 2cc7301
chore: cache npm in action
LekoArts f2b3bb5
Merge branch 'main' into delete-e2e-deploys
LekoArts d161470
chore: update netlify-cli dep
LekoArts 13ae1c5
chore: revert netlify-cli devDep
LekoArts 7c7c4e4
chore: install netlify-cli in CI
LekoArts 94dbe13
chore: revert lock file change
LekoArts 01d12df
Merge branch 'main' into delete-e2e-deploys
LekoArts be93b5e
Merge branch 'main' into delete-e2e-deploys
LekoArts 39c0e97
Merge branch 'main' into delete-e2e-deploys
LekoArts 424ec05
fix: review comments from nick
LekoArts c95f408
Merge branch 'main' into delete-e2e-deploys
LekoArts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,20 @@ import fs from 'fs-extra' | |
import { platform } from 'os' | ||
import { NextInstance } from './base' | ||
|
||
type DeployRes = { | ||
name: string | ||
site_id: string | ||
site_name: string | ||
deploy_id: string | ||
deploy_url: string | ||
logs: string | ||
} | ||
|
||
export class NextDeployInstance extends NextInstance { | ||
private _cliOutput: string | ||
private _buildId: string | ||
private _deployId: string | ||
private _netlifySiteId: string | ||
|
||
public get buildId() { | ||
return this._buildId | ||
|
@@ -28,22 +39,23 @@ export class NextDeployInstance extends NextInstance { | |
cwd: this.testDir, | ||
stdio: 'inherit', | ||
}) | ||
// ensure Netlify CLI is installed | ||
// Netlify CLI should be installed, but just making sure | ||
try { | ||
const res = await execa('ntl', ['--version']) | ||
console.log(`Using Netlify CLI version:`, res.stdout) | ||
} catch (_) { | ||
console.log(`Installing Netlify CLI`) | ||
await execa('npm', ['i', '-g', 'netlify-cli@latest'], { | ||
stdio: 'inherit', | ||
}) | ||
throw new Error(`You need to have netlify-cli installed. | ||
|
||
You can do this by running: "npm install -g netlify-cli@latest" or "yarn global add netlify-cli@latest"`) | ||
} | ||
|
||
const NETLIFY_SITE_ID = process.env.NETLIFY_SITE_ID || '1d5a5c76-d445-4ae5-b694-b0d3f2e2c395' | ||
console.log(`Deploys site for test: ${testName}`) | ||
|
||
this._netlifySiteId = process.env.NETLIFY_SITE_ID || '1d5a5c76-d445-4ae5-b694-b0d3f2e2c395' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the default site ID There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Who knows... 😆 That code was already there, I only moved it |
||
|
||
try { | ||
const statRes = await execa('ntl', ['status', '--json'], { | ||
env: { NETLIFY_SITE_ID, NODE_ENV: 'production' }, | ||
await execa('ntl', ['status', '--json'], { | ||
env: { NETLIFY_SITE_ID: this._netlifySiteId, NODE_ENV: 'production' }, | ||
}) | ||
} catch (err) { | ||
if (err.message.includes("You don't appear to be in a folder that is linked to a site")) { | ||
|
@@ -58,7 +70,7 @@ export class NextDeployInstance extends NextInstance { | |
cwd: this.testDir, | ||
reject: false, | ||
env: { | ||
NETLIFY_SITE_ID, | ||
NETLIFY_SITE_ID: this._netlifySiteId, | ||
NODE_ENV: 'production', | ||
DISABLE_IPX: platform() === 'linux' ? undefined : '1', | ||
}, | ||
|
@@ -68,8 +80,9 @@ export class NextDeployInstance extends NextInstance { | |
throw new Error(`Failed to deploy project ${deployRes.stdout} ${deployRes.stderr} (${deployRes.exitCode})`) | ||
} | ||
try { | ||
const data = JSON.parse(deployRes.stdout) | ||
const data: DeployRes = JSON.parse(deployRes.stdout) | ||
this._url = data.deploy_url | ||
this._deployId = data.deploy_id | ||
console.log(`Deployed to ${this._url}`, data) | ||
this._parsedUrl = new URL(this._url) | ||
} catch (err) { | ||
|
@@ -89,6 +102,37 @@ export class NextDeployInstance extends NextInstance { | |
// no-op as the deployment is created during setup() | ||
} | ||
|
||
public async destroy(): Promise<void> { | ||
if (this.isDestroyed) { | ||
throw new Error(`next instance already destroyed`) | ||
LekoArts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// During setup() the test site is deployed to Netlify | ||
// Once testing is complete, we should delete the deploy again | ||
|
||
if (!process.env.NEXT_TEST_SKIP_CLEANUP) { | ||
console.log(`Deleting project with deploy_id ${this._deployId}`) | ||
|
||
const deleteRes = await execa('ntl', ['api', 'deleteDeploy', '--data', `{ "deploy_id": "${this._deployId}" }`]) | ||
|
||
if (deleteRes.exitCode !== 0) { | ||
LekoArts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
throw new Error(`Failed to delete project ${deleteRes.stdout} ${deleteRes.stderr} (${deleteRes.exitCode})`) | ||
} | ||
|
||
console.log(`Successfully deleted project with deploy_id ${this._deployId}`) | ||
} | ||
|
||
// Code below is copied from the base NextInstance class | ||
|
||
this.isDestroyed = true | ||
this.emit('destroy', []) | ||
|
||
if (!process.env.NEXT_TEST_SKIP_CLEANUP) { | ||
await fs.remove(this.testDir) | ||
} | ||
require('console').log(`destroyed next instance`) | ||
} | ||
|
||
public async patchFile(filename: string, content: string): Promise<void> { | ||
throw new Error('patchFile is not available in deploy test mode') | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.