mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-05-10 19:19: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
|
@ -19,10 +19,10 @@ async function run(): Promise<void> {
|
|||
return;
|
||||
}
|
||||
|
||||
const cachePath = utils.resolvePath(
|
||||
core.getInput(Inputs.Path, { required: true })
|
||||
);
|
||||
core.debug(`Cache Path: ${cachePath}`);
|
||||
// const cachePath = utils.resolvePath(
|
||||
// core.getInput(Inputs.Path, { required: true })
|
||||
// );
|
||||
// core.debug(`Cache Path: ${cachePath}`);
|
||||
|
||||
const primaryKey = core.getInput(Inputs.Key, { required: true });
|
||||
core.saveState(State.CacheKey, primaryKey);
|
||||
|
@ -87,7 +87,7 @@ async function run(): Promise<void> {
|
|||
)} MB (${archiveFileSize} B)`
|
||||
);
|
||||
|
||||
await extractTar(archivePath, cachePath);
|
||||
await extractTar(archivePath);
|
||||
|
||||
const isExactKeyMatch = utils.isExactKeyMatch(
|
||||
primaryKey,
|
||||
|
|
14
src/save.ts
14
src/save.ts
|
@ -43,10 +43,14 @@ async function run(): Promise<void> {
|
|||
return;
|
||||
}
|
||||
core.debug(`Cache ID: ${cacheId}`);
|
||||
const cachePath = utils.resolvePath(
|
||||
core.getInput(Inputs.Path, { required: true })
|
||||
);
|
||||
core.debug(`Cache Path: ${cachePath}`);
|
||||
const cachePaths = core
|
||||
.getInput(Inputs.Path)
|
||||
.split("\n")
|
||||
.filter(x => x !== "")
|
||||
.map(x => utils.resolvePath(x));
|
||||
|
||||
core.debug("Cache Paths:");
|
||||
core.debug(`${JSON.stringify(cachePaths)}`);
|
||||
|
||||
const archivePath = path.join(
|
||||
await utils.createTempDirectory(),
|
||||
|
@ -54,7 +58,7 @@ async function run(): Promise<void> {
|
|||
);
|
||||
core.debug(`Archive Path: ${archivePath}`);
|
||||
|
||||
await createTar(archivePath, cachePath);
|
||||
await createTar(archivePath, cachePaths);
|
||||
|
||||
const fileSizeLimit = 5 * 1024 * 1024 * 1024; // 5GB per repo limit
|
||||
const archiveFileSize = utils.getArchiveFileSize(archivePath);
|
||||
|
|
26
src/tar.ts
26
src/tar.ts
|
@ -28,20 +28,30 @@ async function execTar(args: string[]): Promise<void> {
|
|||
}
|
||||
}
|
||||
|
||||
export async function extractTar(
|
||||
archivePath: string,
|
||||
targetDirectory: string
|
||||
): Promise<void> {
|
||||
function getWorkingDirectory(): string {
|
||||
return process.env["GITHUB_WORKSPACE"] ?? process.cwd();
|
||||
}
|
||||
|
||||
export async function extractTar(archivePath: string): Promise<void> {
|
||||
// Create directory to extract tar into
|
||||
await io.mkdirP(targetDirectory);
|
||||
const args = ["-xz", "-f", archivePath, "-C", targetDirectory];
|
||||
const workingDirectory = getWorkingDirectory();
|
||||
await io.mkdirP(workingDirectory);
|
||||
const args = ["-xz", "-f", archivePath, "-P", "-C", workingDirectory];
|
||||
await execTar(args);
|
||||
}
|
||||
|
||||
export async function createTar(
|
||||
archivePath: string,
|
||||
sourceDirectory: string
|
||||
sourceDirectories: string[]
|
||||
): Promise<void> {
|
||||
const args = ["-cz", "-f", archivePath, "-C", sourceDirectory, "."];
|
||||
const workingDirectory = getWorkingDirectory();
|
||||
const args = [
|
||||
"-cz",
|
||||
"-f",
|
||||
archivePath,
|
||||
"-C",
|
||||
workingDirectory,
|
||||
sourceDirectories.join(" ")
|
||||
];
|
||||
await execTar(args);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue