mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-04-25 04:45:32 +00:00
Release v1.1
This commit is contained in:
parent
cffae9552b
commit
4c4974aff1
14 changed files with 959 additions and 373 deletions
38
src/save.ts
38
src/save.ts
|
@ -1,9 +1,8 @@
|
|||
import * as core from "@actions/core";
|
||||
import { exec } from "@actions/exec";
|
||||
import * as io from "@actions/io";
|
||||
import * as path from "path";
|
||||
import * as cacheHttpClient from "./cacheHttpClient";
|
||||
import { Events, Inputs, State } from "./constants";
|
||||
import { createTar } from "./tar";
|
||||
import * as utils from "./utils/actionUtils";
|
||||
|
||||
async function run(): Promise<void> {
|
||||
|
@ -35,6 +34,15 @@ async function run(): Promise<void> {
|
|||
return;
|
||||
}
|
||||
|
||||
core.debug("Reserving Cache");
|
||||
const cacheId = await cacheHttpClient.reserveCache(primaryKey);
|
||||
if (cacheId == -1) {
|
||||
core.info(
|
||||
`Unable to reserve cache with key ${primaryKey}, another job may be creating this cache.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
core.debug(`Cache ID: ${cacheId}`);
|
||||
const cachePath = utils.resolvePath(
|
||||
core.getInput(Inputs.Path, { required: true })
|
||||
);
|
||||
|
@ -46,38 +54,22 @@ async function run(): Promise<void> {
|
|||
);
|
||||
core.debug(`Archive Path: ${archivePath}`);
|
||||
|
||||
// http://man7.org/linux/man-pages/man1/tar.1.html
|
||||
// tar [-options] <name of the tar archive> [files or directories which to add into archive]
|
||||
const IS_WINDOWS = process.platform === "win32";
|
||||
const args = IS_WINDOWS
|
||||
? [
|
||||
"-cz",
|
||||
"--force-local",
|
||||
"-f",
|
||||
archivePath.replace(/\\/g, "/"),
|
||||
"-C",
|
||||
cachePath.replace(/\\/g, "/"),
|
||||
"."
|
||||
]
|
||||
: ["-cz", "-f", archivePath, "-C", cachePath, "."];
|
||||
await createTar(archivePath, cachePath);
|
||||
|
||||
const tarPath = await io.which("tar", true);
|
||||
core.debug(`Tar Path: ${tarPath}`);
|
||||
await exec(`"${tarPath}"`, args);
|
||||
|
||||
const fileSizeLimit = 400 * 1024 * 1024; // 400MB
|
||||
const fileSizeLimit = 2 * 1024 * 1024 * 1024; // 2GB per repo limit
|
||||
const archiveFileSize = utils.getArchiveFileSize(archivePath);
|
||||
core.debug(`File Size: ${archiveFileSize}`);
|
||||
if (archiveFileSize > fileSizeLimit) {
|
||||
utils.logWarning(
|
||||
`Cache size of ~${Math.round(
|
||||
archiveFileSize / (1024 * 1024)
|
||||
)} MB (${archiveFileSize} B) is over the 400MB limit, not saving cache.`
|
||||
)} MB (${archiveFileSize} B) is over the 2GB limit, not saving cache.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
await cacheHttpClient.saveCache(primaryKey, archivePath);
|
||||
core.debug(`Saving Cache (ID: ${cacheId})`);
|
||||
await cacheHttpClient.saveCache(cacheId, archivePath);
|
||||
} catch (error) {
|
||||
utils.logWarning(error.message);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue