mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-04-19 19:46:17 +02:00
Organize code
This commit is contained in:
parent
36ce21c4a4
commit
8d6737458a
3 changed files with 14 additions and 15 deletions
|
@ -3,7 +3,7 @@ import * as io from "@actions/io";
|
|||
import { promises as fs } from "fs";
|
||||
import * as path from "path";
|
||||
|
||||
import { CacheFilename } from "../src/constants";
|
||||
import { CacheFilename, ManifestFilename } from "../src/constants";
|
||||
import * as tar from "../src/tar";
|
||||
|
||||
jest.mock("@actions/exec");
|
||||
|
@ -32,11 +32,11 @@ test("extract tar", async () => {
|
|||
const execMock = jest.spyOn(exec, "exec");
|
||||
|
||||
const archivePath = "cache.tar";
|
||||
const workspace = process.env["GITHUB_WORKSPACE"];
|
||||
const workingDirectory = process.env["GITHUB_WORKSPACE"];
|
||||
|
||||
await tar.extractTar(archivePath);
|
||||
|
||||
expect(mkdirMock).toHaveBeenCalledWith(workspace);
|
||||
expect(mkdirMock).toHaveBeenCalledWith(workingDirectory);
|
||||
|
||||
const IS_WINDOWS = process.platform === "win32";
|
||||
const tarPath = IS_WINDOWS
|
||||
|
@ -52,7 +52,7 @@ test("extract tar", async () => {
|
|||
archivePath,
|
||||
"-P",
|
||||
"-C",
|
||||
workspace
|
||||
workingDirectory
|
||||
],
|
||||
{ cwd: undefined }
|
||||
);
|
||||
|
@ -62,8 +62,8 @@ 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`];
|
||||
const workingDirectory = process.env["GITHUB_WORKSPACE"];
|
||||
const sourceDirectories = ["~/.npm/cache", `${workingDirectory}/dist`];
|
||||
|
||||
await fs.mkdir(archiveFolder, { recursive: true });
|
||||
|
||||
|
@ -83,12 +83,10 @@ test("create tar", async () => {
|
|||
"-cf",
|
||||
CacheFilename,
|
||||
"-C",
|
||||
workspace,
|
||||
workingDirectory,
|
||||
"--files-from",
|
||||
"manifest.txt"
|
||||
ManifestFilename
|
||||
],
|
||||
{
|
||||
cwd: archiveFolder
|
||||
}
|
||||
{ cwd: archiveFolder }
|
||||
);
|
||||
});
|
||||
|
|
|
@ -20,3 +20,5 @@ export enum Events {
|
|||
}
|
||||
|
||||
export const CacheFilename = "cache.tar.zst";
|
||||
|
||||
export const ManifestFilename = "manifest.txt";
|
||||
|
|
|
@ -3,7 +3,7 @@ import * as io from "@actions/io";
|
|||
import { existsSync, writeFileSync } from "fs";
|
||||
import * as path from "path";
|
||||
|
||||
import { CacheFilename } from "./constants";
|
||||
import { CacheFilename, ManifestFilename } from "./constants";
|
||||
|
||||
async function getTarPath(): Promise<string> {
|
||||
// Explicitly use BSD Tar on Windows
|
||||
|
@ -56,9 +56,8 @@ export async function createTar(
|
|||
sourceDirectories: string[]
|
||||
): Promise<void> {
|
||||
// Write source directories to manifest.txt to avoid command length limits
|
||||
const manifestFilename = "manifest.txt";
|
||||
writeFileSync(
|
||||
path.join(archiveFolder, manifestFilename),
|
||||
path.join(archiveFolder, ManifestFilename),
|
||||
sourceDirectories.join("\n")
|
||||
);
|
||||
|
||||
|
@ -71,7 +70,7 @@ export async function createTar(
|
|||
"-C",
|
||||
workingDirectory,
|
||||
"--files-from",
|
||||
manifestFilename
|
||||
ManifestFilename
|
||||
];
|
||||
await execTar(args, archiveFolder);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue