mirror of
https://gitee.com/actions-mirror/cache.git
synced 2024-11-27 21:10:42 +08:00
eb78578266
* Allow for multiple line-delimited paths to cache * Add initial minimatch support * Use @actions/glob for pattern matching * Cache multiple entries using --files-from tar input remove known failing test Quote tar paths Add salt to test cache Try reading input files from manifest bump salt Run test on macos more testing Run caching tests on 3 platforms Run tests on self-hosted Apparently cant reference hosted runners by name Bump salt wait for some time after save more timing out smarter waiting Cache in tmp dir that won't be deleted Use child_process instead of actions/exec Revert tempDir hack bump salt more logging More console logging Use filepath to with cacheHttpClient Test cache restoration Revert temp dir hack debug logging clean up cache.yml testing Bump salt change debug output build actions * unit test coverage for caching multiple dirs * Ensure there's a locateable test folder at homedir * Clean up code * Version cache with all inputs * Unit test getCacheVersion * Include keys in getCacheEntry request * Clean import orders * Use fs promises in actionUtils tests * Update import order for to fix linter errors * Fix remaining linter error * Remove platform-specific test code * Add lerna example for caching multiple dirs * Lerna example updated to v2 Co-Authored-By: Josh Gross <joshmgross@github.com> Co-authored-by: Josh Gross <joshmgross@github.com>
86 lines
2.3 KiB
TypeScript
86 lines
2.3 KiB
TypeScript
import * as exec from "@actions/exec";
|
|
import * as io from "@actions/io";
|
|
import { promises as fs } from "fs";
|
|
import * as path from "path";
|
|
|
|
import { CacheFilename } from "../src/constants";
|
|
import * as tar from "../src/tar";
|
|
|
|
jest.mock("@actions/exec");
|
|
jest.mock("@actions/io");
|
|
|
|
function getTempDir(): string {
|
|
return path.join(__dirname, "_temp", "tar");
|
|
}
|
|
|
|
beforeAll(async () => {
|
|
jest.spyOn(io, "which").mockImplementation(tool => {
|
|
return Promise.resolve(tool);
|
|
});
|
|
|
|
process.env["GITHUB_WORKSPACE"] = process.cwd();
|
|
await jest.requireActual("@actions/io").rmRF(getTempDir());
|
|
});
|
|
|
|
afterAll(async () => {
|
|
delete process.env["GITHUB_WORKSPACE"];
|
|
await jest.requireActual("@actions/io").rmRF(getTempDir());
|
|
});
|
|
|
|
test("extract tar", async () => {
|
|
const mkdirMock = jest.spyOn(io, "mkdirP");
|
|
const execMock = jest.spyOn(exec, "exec");
|
|
|
|
const archivePath = "cache.tar";
|
|
const workspace = process.env["GITHUB_WORKSPACE"];
|
|
|
|
await tar.extractTar(archivePath);
|
|
|
|
expect(mkdirMock).toHaveBeenCalledWith(workspace);
|
|
|
|
const IS_WINDOWS = process.platform === "win32";
|
|
const tarPath = IS_WINDOWS
|
|
? `${process.env["windir"]}\\System32\\tar.exe`
|
|
: "tar";
|
|
expect(execMock).toHaveBeenCalledTimes(1);
|
|
expect(execMock).toHaveBeenCalledWith(
|
|
`"${tarPath}"`,
|
|
["-xz", "-f", archivePath, "-P", "-C", workspace],
|
|
{ cwd: undefined }
|
|
);
|
|
});
|
|
|
|
test("create tar", async () => {
|
|
const execMock = jest.spyOn(exec, "exec");
|
|
|
|
const archiveFolder = getTempDir();
|
|
const workspace = process.env["GITHUB_WORKSPACE"];
|
|
const sourceDirectories = ["~/.npm/cache", `${workspace}/dist`];
|
|
|
|
await fs.mkdir(archiveFolder, { recursive: true });
|
|
|
|
await tar.createTar(archiveFolder, sourceDirectories);
|
|
|
|
const IS_WINDOWS = process.platform === "win32";
|
|
const tarPath = IS_WINDOWS
|
|
? `${process.env["windir"]}\\System32\\tar.exe`
|
|
: "tar";
|
|
|
|
expect(execMock).toHaveBeenCalledTimes(1);
|
|
expect(execMock).toHaveBeenCalledWith(
|
|
`"${tarPath}"`,
|
|
[
|
|
"-cz",
|
|
"-f",
|
|
CacheFilename,
|
|
"-C",
|
|
workspace,
|
|
"--files-from",
|
|
"manifest.txt"
|
|
],
|
|
{
|
|
cwd: archiveFolder
|
|
}
|
|
);
|
|
});
|