mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-05-10 19:19:54 +02:00
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
This commit is contained in:
parent
db235cfc56
commit
e0d1942524
11 changed files with 157 additions and 80 deletions
|
@ -18,3 +18,5 @@ export enum Events {
|
|||
Push = "push",
|
||||
PullRequest = "pull_request"
|
||||
}
|
||||
|
||||
export const CacheFilename = "cache.tgz";
|
||||
|
|
12
src/save.ts
12
src/save.ts
|
@ -1,7 +1,7 @@
|
|||
import * as core from "@actions/core";
|
||||
import * as path from "path";
|
||||
import * as cacheHttpClient from "./cacheHttpClient";
|
||||
import { Events, Inputs, State } from "./constants";
|
||||
import { Events, Inputs, State, CacheFilename } from "./constants";
|
||||
import { createTar } from "./tar";
|
||||
import * as utils from "./utils/actionUtils";
|
||||
|
||||
|
@ -43,7 +43,7 @@ async function run(): Promise<void> {
|
|||
return;
|
||||
}
|
||||
core.debug(`Cache ID: ${cacheId}`);
|
||||
const cachePaths = await utils.expandPaths(
|
||||
const cachePaths = await utils.resolvePaths(
|
||||
core
|
||||
.getInput(Inputs.Path)
|
||||
.split("\n")
|
||||
|
@ -53,13 +53,11 @@ async function run(): Promise<void> {
|
|||
core.debug("Cache Paths:");
|
||||
core.debug(`${JSON.stringify(cachePaths)}`);
|
||||
|
||||
const archivePath = path.join(
|
||||
await utils.createTempDirectory(),
|
||||
"cache.tgz"
|
||||
);
|
||||
const archiveFolder = await utils.createTempDirectory();
|
||||
const archivePath = path.join(archiveFolder, CacheFilename);
|
||||
core.debug(`Archive Path: ${archivePath}`);
|
||||
|
||||
await createTar(archivePath, cachePaths);
|
||||
await createTar(archiveFolder, cachePaths);
|
||||
|
||||
const fileSizeLimit = 5 * 1024 * 1024 * 1024; // 5GB per repo limit
|
||||
const archiveFileSize = utils.getArchiveFileSize(archivePath);
|
||||
|
|
27
src/tar.ts
27
src/tar.ts
|
@ -1,6 +1,8 @@
|
|||
import { exec } from "@actions/exec";
|
||||
import * as io from "@actions/io";
|
||||
import { existsSync } from "fs";
|
||||
import * as path from "path";
|
||||
import { CacheFilename } from "./constants";
|
||||
import { exec } from "@actions/exec";
|
||||
import { existsSync, writeFileSync } from "fs";
|
||||
|
||||
async function getTarPath(): Promise<string> {
|
||||
// Explicitly use BSD Tar on Windows
|
||||
|
@ -14,10 +16,12 @@ async function getTarPath(): Promise<string> {
|
|||
return await io.which("tar", true);
|
||||
}
|
||||
|
||||
async function execTar(args: string[]): Promise<void> {
|
||||
async function execTar(args: string[], cwd?: string): Promise<void> {
|
||||
try {
|
||||
await exec(`"${await getTarPath()}"`, args);
|
||||
await exec(`"${await getTarPath()}"`, args, { cwd: cwd });
|
||||
} catch (error) {
|
||||
console.log("error", error);
|
||||
|
||||
const IS_WINDOWS = process.platform === "win32";
|
||||
if (IS_WINDOWS) {
|
||||
throw new Error(
|
||||
|
@ -41,18 +45,25 @@ export async function extractTar(archivePath: string): Promise<void> {
|
|||
}
|
||||
|
||||
export async function createTar(
|
||||
archivePath: string,
|
||||
archiveFolder: string,
|
||||
sourceDirectories: string[]
|
||||
): Promise<void> {
|
||||
// TODO: will want to stream sourceDirectories into tar
|
||||
const manifestFilename = "manifest.txt";
|
||||
writeFileSync(
|
||||
path.join(archiveFolder, manifestFilename),
|
||||
sourceDirectories.join("\n")
|
||||
);
|
||||
|
||||
const workingDirectory = getWorkingDirectory();
|
||||
const args = [
|
||||
"-cz",
|
||||
"-f",
|
||||
archivePath,
|
||||
CacheFilename,
|
||||
"-C",
|
||||
workingDirectory,
|
||||
sourceDirectories.join(" ")
|
||||
"--files-from",
|
||||
manifestFilename
|
||||
];
|
||||
await execTar(args);
|
||||
await execTar(args, archiveFolder);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ export async function createTempDirectory(): Promise<string> {
|
|||
}
|
||||
tempDirectory = path.join(baseLocation, "actions", "temp");
|
||||
}
|
||||
|
||||
const dest = path.join(tempDirectory, uuidV4.default());
|
||||
await io.mkdirP(dest);
|
||||
return dest;
|
||||
|
@ -82,17 +83,21 @@ export function logWarning(message: string): void {
|
|||
core.info(`${warningPrefix}${message}`);
|
||||
}
|
||||
|
||||
export async function expandPaths(patterns: string[]): Promise<string[]> {
|
||||
export async function resolvePaths(patterns: string[]): Promise<string[]> {
|
||||
const paths: string[] = [];
|
||||
const workspace = process.env["GITHUB_WORKSPACE"] ?? process.cwd();
|
||||
const globber = await glob.create(patterns.join("\n"), {
|
||||
implicitDescendants: false
|
||||
});
|
||||
|
||||
const globber = await glob.create(patterns.join("\n"));
|
||||
const files = await globber.glob();
|
||||
for await (const file of globber.globGenerator()) {
|
||||
const relativeFile = path.relative(workspace, file);
|
||||
core.debug(`Matched: ${relativeFile}`);
|
||||
// Paths are made relative so the tar entries are all relative to the root of the workspace.
|
||||
paths.push(`${relativeFile}`);
|
||||
}
|
||||
|
||||
paths.push(...files);
|
||||
|
||||
// Convert paths to relative paths here?
|
||||
return paths.map(x => path.relative(workspace, x));
|
||||
return paths;
|
||||
}
|
||||
|
||||
export function getSupportedEvents(): string[] {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue