1
0
Fork 0
mirror of https://code.forgejo.org/actions/cache.git synced 2025-04-19 19:46:17 +02:00
This commit is contained in:
J.W. Jagersma 2020-02-09 00:40:58 +01:00
parent 78a4b2143b
commit 1e5552f09c
No known key found for this signature in database
GPG key ID: C807344D537B62B4
2 changed files with 24 additions and 17 deletions

View file

@ -25,14 +25,15 @@ test("extract tar", async () => {
const tarPath = IS_WINDOWS
? `${process.env["windir"]}\\System32\\tar.exe`
: "tar";
let tarParams = ["-xz", "-f", archivePath, "-C", targetDirectory];
let tarExec = `${tarPath}`;
if (!IS_WINDOWS) {
tarExec = "sudo";
tarParams = [`${tarPath}`, ...tarParams];
}
expect(execMock).toHaveBeenCalledTimes(1);
expect(execMock).toHaveBeenCalledWith(`"${tarPath}"`, [
"-xz",
"-f",
archivePath,
"-C",
targetDirectory
]);
expect(execMock).toHaveBeenCalledWith(`"${tarExec}"`, tarParams);
});
test("create tar", async () => {
@ -46,13 +47,13 @@ test("create tar", async () => {
const tarPath = IS_WINDOWS
? `${process.env["windir"]}\\System32\\tar.exe`
: "tar";
let tarParams = ["-cz", "-f", archivePath, "-C", sourceDirectory, "."];
let tarExec = `${tarPath}`;
if (!IS_WINDOWS) {
tarExec = "sudo";
tarParams = [`${tarPath}`, ...tarParams];
}
expect(execMock).toHaveBeenCalledTimes(1);
expect(execMock).toHaveBeenCalledWith(`"${tarPath}"`, [
"-cz",
"-f",
archivePath,
"-C",
sourceDirectory,
"."
]);
expect(execMock).toHaveBeenCalledWith(`"${tarExec}"`, tarParams);
});

View file

@ -15,10 +15,16 @@ async function getTarPath(): Promise<string> {
}
async function execTar(args: string[]): Promise<void> {
const IS_WINDOWS = process.platform === "win32";
try {
await exec(`"${await getTarPath()}"`, args);
const tarPath = await getTarPath();
let tarExec = tarPath;
if (!IS_WINDOWS) {
tarExec = "sudo";
args = [`${tarPath}`, ...args];
}
await exec(`"${tarExec}"`, args);
} catch (error) {
const IS_WINDOWS = process.platform === "win32";
if (IS_WINDOWS) {
throw new Error(
`Tar failed with error: ${error?.message}. Ensure BSD tar is installed and on the PATH.`