mirror of
https://github.com/actions/cache.git
synced 2025-04-23 06:30:47 +00:00
Clean up args and arrange imports
This commit is contained in:
parent
c0584c42d1
commit
29f7388d53
3 changed files with 29 additions and 24 deletions
|
@ -93,9 +93,11 @@ export async function downloadCache(
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function saveCache(
|
export async function saveCache(
|
||||||
stream: NodeJS.ReadableStream,
|
key: string,
|
||||||
key: string
|
archivePath: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
const stream = fs.createReadStream(archivePath);
|
||||||
|
|
||||||
const cacheUrl = getCacheUrl();
|
const cacheUrl = getCacheUrl();
|
||||||
const token = process.env["ACTIONS_RUNTIME_TOKEN"] || "";
|
const token = process.env["ACTIONS_RUNTIME_TOKEN"] || "";
|
||||||
const bearerCredentialHandler = new BearerCredentialHandler(token);
|
const bearerCredentialHandler = new BearerCredentialHandler(token);
|
||||||
|
|
|
@ -19,7 +19,7 @@ async function run(): Promise<void> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let cachePath = utils.resolvePath(
|
const cachePath = utils.resolvePath(
|
||||||
core.getInput(Inputs.Path, { required: true })
|
core.getInput(Inputs.Path, { required: true })
|
||||||
);
|
);
|
||||||
core.debug(`Cache Path: ${cachePath}`);
|
core.debug(`Cache Path: ${cachePath}`);
|
||||||
|
@ -67,7 +67,7 @@ async function run(): Promise<void> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let archivePath = path.join(
|
const archivePath = path.join(
|
||||||
await utils.createTempDirectory(),
|
await utils.createTempDirectory(),
|
||||||
"cache.tgz"
|
"cache.tgz"
|
||||||
);
|
);
|
||||||
|
@ -90,15 +90,17 @@ async function run(): Promise<void> {
|
||||||
|
|
||||||
// http://man7.org/linux/man-pages/man1/tar.1.html
|
// 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]
|
// tar [-options] <name of the tar archive> [files or directories which to add into archive]
|
||||||
const args = ["-xz"];
|
|
||||||
|
|
||||||
const IS_WINDOWS = process.platform === "win32";
|
const IS_WINDOWS = process.platform === "win32";
|
||||||
if (IS_WINDOWS) {
|
const args = IS_WINDOWS
|
||||||
args.push("--force-local");
|
? [
|
||||||
archivePath = archivePath.replace(/\\/g, "/");
|
"-xz",
|
||||||
cachePath = cachePath.replace(/\\/g, "/");
|
"--force-local",
|
||||||
}
|
"-f",
|
||||||
args.push(...["-f", archivePath, "-C", cachePath]);
|
archivePath.replace(/\\/g, "/"),
|
||||||
|
"-C",
|
||||||
|
cachePath.replace(/\\/g, "/")
|
||||||
|
]
|
||||||
|
: ["-xz", "-f", archivePath, "-C", cachePath];
|
||||||
|
|
||||||
const tarPath = await io.which("tar", true);
|
const tarPath = await io.which("tar", true);
|
||||||
core.debug(`Tar Path: ${tarPath}`);
|
core.debug(`Tar Path: ${tarPath}`);
|
||||||
|
|
25
src/save.ts
25
src/save.ts
|
@ -1,7 +1,6 @@
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import { exec } from "@actions/exec";
|
import { exec } from "@actions/exec";
|
||||||
import * as io from "@actions/io";
|
import * as io from "@actions/io";
|
||||||
import * as fs from "fs";
|
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import * as cacheHttpClient from "./cacheHttpClient";
|
import * as cacheHttpClient from "./cacheHttpClient";
|
||||||
import { Inputs, State } from "./constants";
|
import { Inputs, State } from "./constants";
|
||||||
|
@ -38,22 +37,25 @@ async function run(): Promise<void> {
|
||||||
|
|
||||||
// http://man7.org/linux/man-pages/man1/tar.1.html
|
// 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]
|
// tar [-options] <name of the tar archive> [files or directories which to add into archive]
|
||||||
const args = ["-cz"];
|
|
||||||
const IS_WINDOWS = process.platform === "win32";
|
const IS_WINDOWS = process.platform === "win32";
|
||||||
if (IS_WINDOWS) {
|
const args = IS_WINDOWS
|
||||||
args.push("--force-local");
|
? [
|
||||||
archivePath = archivePath.replace(/\\/g, "/");
|
"-cz",
|
||||||
cachePath = cachePath.replace(/\\/g, "/");
|
"--force-local",
|
||||||
}
|
"-f",
|
||||||
|
archivePath.replace(/\\/g, "/"),
|
||||||
args.push(...["-f", archivePath, "-C", cachePath, "."]);
|
"-C",
|
||||||
|
cachePath.replace(/\\/g, "/"),
|
||||||
|
"."
|
||||||
|
]
|
||||||
|
: ["-cz", "-f", archivePath, "-C", cachePath, "."];
|
||||||
|
|
||||||
const tarPath = await io.which("tar", true);
|
const tarPath = await io.which("tar", true);
|
||||||
core.debug(`Tar Path: ${tarPath}`);
|
core.debug(`Tar Path: ${tarPath}`);
|
||||||
await exec(`"${tarPath}"`, args);
|
await exec(`"${tarPath}"`, args);
|
||||||
|
|
||||||
const fileSizeLimit = 400 * 1024 * 1024; // 400MB
|
const fileSizeLimit = 400 * 1024 * 1024; // 400MB
|
||||||
const archiveFileSize = fs.statSync(archivePath).size;
|
const archiveFileSize = utils.getArchiveFileSize(archivePath);
|
||||||
core.debug(`File Size: ${archiveFileSize}`);
|
core.debug(`File Size: ${archiveFileSize}`);
|
||||||
if (archiveFileSize > fileSizeLimit) {
|
if (archiveFileSize > fileSizeLimit) {
|
||||||
core.warning(
|
core.warning(
|
||||||
|
@ -64,8 +66,7 @@ async function run(): Promise<void> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const stream = fs.createReadStream(archivePath);
|
await cacheHttpClient.saveCache(primaryKey, archivePath);
|
||||||
await cacheHttpClient.saveCache(stream, primaryKey);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.warning(error.message);
|
core.warning(error.message);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue