8000 chore: add script to cleanup dangling old deploys (#78) · opennextjs/opennextjs-netlify@7a4bfc8 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7a4bfc8

Browse files
authored
chore: add script to cleanup dangling old deploys (#78)
1 parent fcd57d1 commit 7a4bfc8

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,40 @@ How to add new integration test scenarios to the application:
1919
> Currently the tests require a built version of the `dist/run/handlers/cache.cjs` so you need to
2020
> run `npm run build` before executing the integration tests. In addition, the integration tests
2121
> need to be prepared before first use. You can do this by running `npm run pretest`.
22+
23+
### E2E testing
24+
25+
> **Prerequisite**
26+
>
27+
> Needs the `netlify-cli` installed and being logged in having access to Netlify Testing
28+
> Organization
29+
30+
The e2e tests can be invoked with `npm run e2e` and perform a full e2e test. This means they do the
31+
following:
32+
33+
1. Building the next-runtime (just running `npm run build` in the repository)
34+
2. Creating a temp directory and copying the provided fixture over to the directory.
35+
3. Packing the runtime with `npm pack` to the temp directory.
36+
4. Installing the runtime from the created zip artifact of `npm pack` (this is like installing a
37+
node_module from the registry)
38+
5. Creating a `netlify.toml` inside the temp directory of the fixture and adding the runtime as a
39+
plugin.
40+
6. Running `netlify deploy --build` invoking the runtime. This will use the
41+
[next-runtime-testing](https://app.netlify.com/sites/next-runtime-testing/overview) as site to
42+
deploy to.
43+
7. Using the `deployId` and `url` of the deployed site to run some
44+
[playwright](https://playwright.dev/) tests against, asserting the correctness of the runtime.
45+
8. After the tests where run successfully, it will delete the deployment again and clean everything
46+
up. In case of a failure, the deploy won't be cleaned up to leave it for troubleshooting
47+
purposes.
48+
49+
#### cleanup old deploys
50+
51+
To cleanup old and dangling deploys from failed builds you can run the following script:
52+
53+
```bash
54+
npx tsx ./tools/e2e/cleanup-deploys.ts
55+
```
56+
57+
This will cleanup all created deploys on the
58+
[next-runtime-testing](https://app.netlify.com/sites/next-runtime-testing/overview) site.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/utils/create-e2e-fixture.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { cpus } from 'os'
99
import pLimit from 'p-limit'
1010

1111
// This is the netlify testing application
12-
const SITE_ID = 'ee859ce9-44a7-46be-830b-ead85e445e53'
12+
export const SITE_ID = 'ee859ce9-44a7-46be-830b-ead85e445e53'
1313

1414
export interface DeployResult {
1515
deployID: string
@@ -113,7 +113,7 @@ async function deploySite(cwd: string): Promise<DeployResult> {
113113
return { url, deployID, logs: output }
114114
}
115115

116-
async function deleteDeploy(deploy_id?: string): Promise<void> {
116+
export async function deleteDeploy(deploy_id?: string): Promise<void> {
117117
if (deploy_id) {
118118
console.log(`♻️ Delete Deploy ${deploy_id}...`)
119119
const cmd = `ntl api deleteDeploy --data='{"deploy_id":"${deploy_id}"}'`

tools/e2e/cleanup-deploys.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { exec } from 'child_process'
2+
import { SITE_ID, deleteDeploy } from '../../tests/utils/create-e2e-fixture.js'
3+
4+
const runCommand = (cmd: string) =>
5+
new Promise<string>((resolve, reject) =>
6+
exec(cmd, (err, stdout) => (err ? reject(err) : resolve(stdout))),
7+
)
8+
9+
const output = await runCommand(`ntl api listSiteDeploys --data='{"site_id":"${SITE_ID}"}'`)
10+
const deploys = JSON.parse(output)
11+
12+
await Promise.allSettled(deploys.map((deploy) => deleteDeploy(deploy.id)))

0 commit comments

Comments
 (0)
0