Unverified Commit f18e6885 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Add custom cleanup script support for deploy tests (#90696)

## Summary
- Adds `cleanupScriptPath` workflow dispatch input and
`NEXT_TEST_CLEANUP_SCRIPT_PATH` env var to `test_e2e_deploy_release.yml`
(webpack + turbopack jobs)
- Adds `cleanupUsingCustomScript()` method to `NextDeployInstance`
following the same pattern as the existing deploy and logs scripts
- Calls the cleanup script in `destroy()` before existing teardown logic

---------
Co-authored-by: 's avatarVercel <vercel[bot]@users.noreply.github.com>
parent c2a27526
...@@ -27,6 +27,10 @@ on: ...@@ -27,6 +27,10 @@ on:
description: Custom deploy logs script path (NEXT_TEST_DEPLOY_LOGS_SCRIPT_PATH) description: Custom deploy logs script path (NEXT_TEST_DEPLOY_LOGS_SCRIPT_PATH)
default: '' default: ''
type: string type: string
cleanupScriptPath:
description: Custom cleanup script path (NEXT_TEST_CLEANUP_SCRIPT_PATH)
default: ''
type: string
env: env:
DD_ENV: 'ci' DD_ENV: 'ci'
...@@ -122,6 +126,7 @@ jobs: ...@@ -122,6 +126,7 @@ jobs:
VERCEL_CLI_VERSION="${{ github.event.inputs.vercelCliVersion || 'vercel@latest' }}" \ VERCEL_CLI_VERSION="${{ github.event.inputs.vercelCliVersion || 'vercel@latest' }}" \
NEXT_TEST_DEPLOY_SCRIPT_PATH="${{ github.event.inputs.deployScriptPath || '' }}" \ NEXT_TEST_DEPLOY_SCRIPT_PATH="${{ github.event.inputs.deployScriptPath || '' }}" \
NEXT_TEST_DEPLOY_LOGS_SCRIPT_PATH="${{ github.event.inputs.deployLogsScriptPath || '' }}" \ NEXT_TEST_DEPLOY_LOGS_SCRIPT_PATH="${{ github.event.inputs.deployLogsScriptPath || '' }}" \
NEXT_TEST_CLEANUP_SCRIPT_PATH="${{ github.event.inputs.cleanupScriptPath || '' }}" \
node run-tests.js --timings --require-timings -g ${{ matrix.group }} -c 2 --type e2e node run-tests.js --timings --require-timings -g ${{ matrix.group }} -c 2 --type e2e
testTimingsArtifact: 'test-timings' testTimingsArtifact: 'test-timings'
skipNativeBuild: 'yes' skipNativeBuild: 'yes'
...@@ -166,6 +171,7 @@ jobs: ...@@ -166,6 +171,7 @@ jobs:
VERCEL_CLI_VERSION="${{ github.event.inputs.vercelCliVersion || 'vercel@latest' }}" \ VERCEL_CLI_VERSION="${{ github.event.inputs.vercelCliVersion || 'vercel@latest' }}" \
NEXT_TEST_DEPLOY_SCRIPT_PATH="${{ github.event.inputs.deployScriptPath || '' }}" \ NEXT_TEST_DEPLOY_SCRIPT_PATH="${{ github.event.inputs.deployScriptPath || '' }}" \
NEXT_TEST_DEPLOY_LOGS_SCRIPT_PATH="${{ github.event.inputs.deployLogsScriptPath || '' }}" \ NEXT_TEST_DEPLOY_LOGS_SCRIPT_PATH="${{ github.event.inputs.deployLogsScriptPath || '' }}" \
NEXT_TEST_CLEANUP_SCRIPT_PATH="${{ github.event.inputs.cleanupScriptPath || '' }}" \
node run-tests.js --timings --require-timings -g ${{ matrix.group }} -c 2 --type e2e node run-tests.js --timings --require-timings -g ${{ matrix.group }} -c 2 --type e2e
testTimingsArtifact: 'test-timings' testTimingsArtifact: 'test-timings'
skipNativeBuild: 'yes' skipNativeBuild: 'yes'
......
...@@ -123,6 +123,34 @@ export class NextDeployInstance extends NextInstance { ...@@ -123,6 +123,34 @@ export class NextDeployInstance extends NextInstance {
return logsRes.stdout + logsRes.stderr return logsRes.stdout + logsRes.stderr
} }
private async cleanupUsingCustomScript(): Promise<void> {
const cleanupScriptPath = process.env.NEXT_TEST_CLEANUP_SCRIPT_PATH!
require('console').log(
`Running cleanup using custom script: ${cleanupScriptPath}`
)
const scriptEnv = {
...process.env,
NEXT_TEST_DIR: this.testDir,
NEXT_TEST_DEPLOY_URL: this._url,
...this.env,
}
const cleanupRes = await execa(cleanupScriptPath, [], {
cwd: this.testDir,
env: scriptEnv,
reject: false,
stderr: 'inherit',
})
if (cleanupRes.exitCode !== 0) {
throw new Error(
`Custom cleanup script failed: ${cleanupRes.stdout} ${cleanupRes.stderr} (${cleanupRes.exitCode})`
)
}
}
private parseIdsFromCliOuput(): void { private parseIdsFromCliOuput(): void {
const buildId = this._cliOutput.match(/BUILD_ID: (.+)/)?.[1]?.trim() const buildId = this._cliOutput.match(/BUILD_ID: (.+)/)?.[1]?.trim()
if (!buildId) { if (!buildId) {
...@@ -438,6 +466,18 @@ export class NextDeployInstance extends NextInstance { ...@@ -438,6 +466,18 @@ export class NextDeployInstance extends NextInstance {
} }
public async destroy() { public async destroy() {
// Run custom cleanup script if provided
const customCleanupScriptPath =
process.env.NEXT_TEST_CLEANUP_SCRIPT_PATH?.trim()
if (customCleanupScriptPath) {
await this.cleanupUsingCustomScript().catch((err) => {
require('console').error(
'Error running custom cleanup script, continuing with destroy:',
err
)
})
}
// If configured, we should remove the proxy address from the hosts file. // If configured, we should remove the proxy address from the hosts file.
if (this._writtenHostsLine) { if (this._writtenHostsLine) {
const trimmed = this._writtenHostsLine.trim() const trimmed = this._writtenHostsLine.trim()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment