Files
Ncurator/scripts/release/workspace.mjs
T
Yoan Huang bc7794813f Refactor E2E tests to improve resource management and cleanup
- Introduced E2EResourceScope for managing resources during E2E tests.
- Updated test cases to register resources and handle disposal in a structured manner.
- Enhanced error handling during resource disposal to capture and report errors.
- Modified workspace setup functions to ensure proper cleanup after tests.
- Adjusted imports and added necessary utility functions for resource management.
2026-07-21 22:56:50 +08:00

36 lines
927 B
JavaScript

import { mkdir, rm } from 'node:fs/promises'
import os from 'node:os'
import path from 'node:path'
import process from 'node:process'
export const prepareReleaseWorkspace = async ({ releaseTag, defaultRootName, keepWork }) => {
const workRoot = path.resolve(
String(process.env.NCURATOR_RELEASE_WORK_ROOT || '').trim() ||
path.join(os.tmpdir(), defaultRootName)
)
const workDirectory = path.join(workRoot, releaseTag)
await rm(workDirectory, {
recursive: true,
force: true,
maxRetries: 10,
retryDelay: 500
})
await mkdir(workDirectory, { recursive: true })
return {
workDirectory,
dispose: async () => {
if (keepWork) {
process.stdout.write(`[release] kept work directory ${workDirectory}\n`)
return
}
await rm(workDirectory, {
recursive: true,
force: true,
maxRetries: 10,
retryDelay: 500
})
}
}
}