mirror of
https://github.com/github/codeql-action.git
synced 2026-10-03 17:41:28 +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,
|
contents: string,
|
||||||
body: (filePath: string) => Promise<T> | T,
|
body: (filePath: string) => Promise<T> | T,
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
const tmpDir = fs.mkdtempSync(
|
return withTmpDir(async (tmpDir) => {
|
||||||
path.join(os.tmpdir(), "changetool-validate-test-"),
|
|
||||||
);
|
|
||||||
try {
|
|
||||||
const filePath = path.join(tmpDir, baseFileName);
|
const filePath = path.join(tmpDir, baseFileName);
|
||||||
fs.writeFileSync(filePath, contents);
|
fs.writeFileSync(filePath, contents);
|
||||||
return await body(filePath);
|
return body(filePath);
|
||||||
} finally {
|
});
|
||||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user