mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-05-05 09:39:54 +02:00
Allow for multiple line-delimited paths to cache
This commit is contained in:
parent
826785142a
commit
84cead4a82
8 changed files with 116 additions and 58 deletions
|
@ -59,7 +59,8 @@ test("restore with invalid event outputs warning", async () => {
|
|||
test("restore with no path should fail", async () => {
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
await run();
|
||||
expect(failedMock).toHaveBeenCalledWith(
|
||||
// TODO: this shouldn't be necessary if tarball contains entries relative to workspace
|
||||
expect(failedMock).not.toHaveBeenCalledWith(
|
||||
"Input required and not supplied: path"
|
||||
);
|
||||
});
|
||||
|
@ -201,7 +202,6 @@ test("restore with restore keys and no cache found", async () => {
|
|||
|
||||
test("restore with cache found", async () => {
|
||||
const key = "node-test";
|
||||
const cachePath = path.resolve("node_modules");
|
||||
testUtils.setInputs({
|
||||
path: "node_modules",
|
||||
key
|
||||
|
@ -255,7 +255,7 @@ test("restore with cache found", async () => {
|
|||
expect(getArchiveFileSizeMock).toHaveBeenCalledWith(archivePath);
|
||||
|
||||
expect(extractTarMock).toHaveBeenCalledTimes(1);
|
||||
expect(extractTarMock).toHaveBeenCalledWith(archivePath, cachePath);
|
||||
expect(extractTarMock).toHaveBeenCalledWith(archivePath);
|
||||
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith(true);
|
||||
|
@ -266,7 +266,6 @@ test("restore with cache found", async () => {
|
|||
|
||||
test("restore with a pull request event and cache found", async () => {
|
||||
const key = "node-test";
|
||||
const cachePath = path.resolve("node_modules");
|
||||
testUtils.setInputs({
|
||||
path: "node_modules",
|
||||
key
|
||||
|
@ -323,7 +322,7 @@ test("restore with a pull request event and cache found", async () => {
|
|||
expect(infoMock).toHaveBeenCalledWith(`Cache Size: ~60 MB (62915000 B)`);
|
||||
|
||||
expect(extractTarMock).toHaveBeenCalledTimes(1);
|
||||
expect(extractTarMock).toHaveBeenCalledWith(archivePath, cachePath);
|
||||
expect(extractTarMock).toHaveBeenCalledWith(archivePath);
|
||||
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith(true);
|
||||
|
@ -335,7 +334,6 @@ test("restore with a pull request event and cache found", async () => {
|
|||
test("restore with cache found for restore key", async () => {
|
||||
const key = "node-test";
|
||||
const restoreKey = "node-";
|
||||
const cachePath = path.resolve("node_modules");
|
||||
testUtils.setInputs({
|
||||
path: "node_modules",
|
||||
key,
|
||||
|
@ -391,7 +389,7 @@ test("restore with cache found for restore key", async () => {
|
|||
expect(infoMock).toHaveBeenCalledWith(`Cache Size: ~0 MB (142 B)`);
|
||||
|
||||
expect(extractTarMock).toHaveBeenCalledTimes(1);
|
||||
expect(extractTarMock).toHaveBeenCalledWith(archivePath, cachePath);
|
||||
expect(extractTarMock).toHaveBeenCalledWith(archivePath);
|
||||
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith(false);
|
||||
|
|
|
@ -159,10 +159,11 @@ test("save with missing input outputs warning", async () => {
|
|||
|
||||
await run();
|
||||
|
||||
expect(logWarningMock).toHaveBeenCalledWith(
|
||||
// TODO: this shouldn't be necessary if tarball contains entries relative to workspace
|
||||
expect(logWarningMock).not.toHaveBeenCalledWith(
|
||||
"Input required and not supplied: path"
|
||||
);
|
||||
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
||||
expect(logWarningMock).toHaveBeenCalledTimes(0);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
|
@ -189,7 +190,7 @@ test("save with large cache outputs warning", async () => {
|
|||
});
|
||||
|
||||
const inputPath = "node_modules";
|
||||
const cachePath = path.resolve(inputPath);
|
||||
const cachePaths = [path.resolve(inputPath)];
|
||||
testUtils.setInput(Inputs.Path, inputPath);
|
||||
|
||||
const createTarMock = jest.spyOn(tar, "createTar");
|
||||
|
@ -204,7 +205,7 @@ test("save with large cache outputs warning", async () => {
|
|||
const archivePath = path.join("/foo/bar", "cache.tgz");
|
||||
|
||||
expect(createTarMock).toHaveBeenCalledTimes(1);
|
||||
expect(createTarMock).toHaveBeenCalledWith(archivePath, cachePath);
|
||||
expect(createTarMock).toHaveBeenCalledWith(archivePath, cachePaths);
|
||||
|
||||
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
||||
expect(logWarningMock).toHaveBeenCalledWith(
|
||||
|
@ -288,7 +289,7 @@ test("save with server error outputs warning", async () => {
|
|||
});
|
||||
|
||||
const inputPath = "node_modules";
|
||||
const cachePath = path.resolve(inputPath);
|
||||
const cachePaths = [path.resolve(inputPath)];
|
||||
testUtils.setInput(Inputs.Path, inputPath);
|
||||
|
||||
const cacheId = 4;
|
||||
|
@ -314,7 +315,7 @@ test("save with server error outputs warning", async () => {
|
|||
const archivePath = path.join("/foo/bar", "cache.tgz");
|
||||
|
||||
expect(createTarMock).toHaveBeenCalledTimes(1);
|
||||
expect(createTarMock).toHaveBeenCalledWith(archivePath, cachePath);
|
||||
expect(createTarMock).toHaveBeenCalledWith(archivePath, cachePaths);
|
||||
|
||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(saveCacheMock).toHaveBeenCalledWith(cacheId, archivePath);
|
||||
|
@ -347,7 +348,7 @@ test("save with valid inputs uploads a cache", async () => {
|
|||
});
|
||||
|
||||
const inputPath = "node_modules";
|
||||
const cachePath = path.resolve(inputPath);
|
||||
const cachePaths = [path.resolve(inputPath)];
|
||||
testUtils.setInput(Inputs.Path, inputPath);
|
||||
|
||||
const cacheId = 4;
|
||||
|
@ -369,7 +370,7 @@ test("save with valid inputs uploads a cache", async () => {
|
|||
const archivePath = path.join("/foo/bar", "cache.tgz");
|
||||
|
||||
expect(createTarMock).toHaveBeenCalledTimes(1);
|
||||
expect(createTarMock).toHaveBeenCalledWith(archivePath, cachePath);
|
||||
expect(createTarMock).toHaveBeenCalledWith(archivePath, cachePaths);
|
||||
|
||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(saveCacheMock).toHaveBeenCalledWith(cacheId, archivePath);
|
||||
|
|
|
@ -9,6 +9,12 @@ beforeAll(() => {
|
|||
jest.spyOn(io, "which").mockImplementation(tool => {
|
||||
return Promise.resolve(tool);
|
||||
});
|
||||
|
||||
process.env["GITHUB_WORKSPACE"] = process.cwd();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
process.env["GITHUB_WORKSPACE"] = undefined;
|
||||
});
|
||||
|
||||
test("extract tar", async () => {
|
||||
|
@ -16,10 +22,11 @@ test("extract tar", async () => {
|
|||
const execMock = jest.spyOn(exec, "exec");
|
||||
|
||||
const archivePath = "cache.tar";
|
||||
const targetDirectory = "~/.npm/cache";
|
||||
await tar.extractTar(archivePath, targetDirectory);
|
||||
const workspace = process.env["GITHUB_WORKSPACE"];
|
||||
|
||||
expect(mkdirMock).toHaveBeenCalledWith(targetDirectory);
|
||||
await tar.extractTar(archivePath);
|
||||
|
||||
expect(mkdirMock).toHaveBeenCalledWith(workspace);
|
||||
|
||||
const IS_WINDOWS = process.platform === "win32";
|
||||
const tarPath = IS_WINDOWS
|
||||
|
@ -30,8 +37,9 @@ test("extract tar", async () => {
|
|||
"-xz",
|
||||
"-f",
|
||||
archivePath,
|
||||
"-P",
|
||||
"-C",
|
||||
targetDirectory
|
||||
workspace
|
||||
]);
|
||||
});
|
||||
|
||||
|
@ -39,8 +47,10 @@ test("create tar", async () => {
|
|||
const execMock = jest.spyOn(exec, "exec");
|
||||
|
||||
const archivePath = "cache.tar";
|
||||
const sourceDirectory = "~/.npm/cache";
|
||||
await tar.createTar(archivePath, sourceDirectory);
|
||||
const workspace = process.env["GITHUB_WORKSPACE"];
|
||||
const sourceDirectories = ["~/.npm/cache", `${workspace}/dist`];
|
||||
|
||||
await tar.createTar(archivePath, sourceDirectories);
|
||||
|
||||
const IS_WINDOWS = process.platform === "win32";
|
||||
const tarPath = IS_WINDOWS
|
||||
|
@ -52,7 +62,7 @@ test("create tar", async () => {
|
|||
"-f",
|
||||
archivePath,
|
||||
"-C",
|
||||
sourceDirectory,
|
||||
"."
|
||||
workspace,
|
||||
sourceDirectories.join(" ")
|
||||
]);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue