mirror of
https://github.com/github/codeql-action.git
synced 2026-10-03 09:14:58 +00:00
Reduce duplication by using withTmpDir in withTmpFile
This commit is contained in:
11
src/util.ts
11
src/util.ts
@@ -95,16 +95,11 @@ export async function withTmpFile<T>(
|
||||
contents: string,
|
||||
body: (filePath: string) => Promise<T> | T,
|
||||
): Promise<T> {
|
||||
const tmpDir = fs.mkdtempSync(
|
||||
path.join(os.tmpdir(), "changetool-validate-test-"),
|
||||
);
|
||||
try {
|
||||
return withTmpDir(async (tmpDir) => {
|
||||
const filePath = path.join(tmpDir, baseFileName);
|
||||
fs.writeFileSync(filePath, contents);
|
||||
return await body(filePath);
|
||||
} finally {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
}
|
||||
return body(filePath);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user