mirror of
https://github.com/actions/cache.git
synced 2025-07-04 16:14:50 +02:00
Compare commits
5 Commits
joshmgross
...
v1.0.2
Author | SHA1 | Date | |
---|---|---|---|
44543250bd | |||
6491e51b66 | |||
86dff562ab | |||
0f810ad45a | |||
9d8c7b4041 |
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
This GitHub Action allows caching dependencies and build outputs to improve workflow execution time.
|
This GitHub Action allows caching dependencies and build outputs to improve workflow execution time.
|
||||||
|
|
||||||
<a href="https://github.com/actions/cache/actions?query=workflow%3ATests"><img alt="GitHub Actions status" src="https://github.com/actions/cache/workflows/Tests/badge.svg?branch=master&event=push"></a>
|
<a href="https://github.com/actions/cache"><img alt="GitHub Actions status" src="https://github.com/actions/cache/workflows/Tests/badge.svg?branch=master&event=push"></a>
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
|
@ -162,16 +162,6 @@ test("getCacheState with valid state", () => {
|
|||||||
expect(getStateMock).toHaveBeenCalledTimes(1);
|
expect(getStateMock).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("logWarning logs a message with a warning prefix", () => {
|
|
||||||
const message = "A warning occurred.";
|
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
|
||||||
|
|
||||||
actionUtils.logWarning(message);
|
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(`[warning]${message}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("isValidEvent returns false for unknown event", () => {
|
test("isValidEvent returns false for unknown event", () => {
|
||||||
const event = "foo";
|
const event = "foo";
|
||||||
process.env[Events.Key] = event;
|
process.env[Events.Key] = event;
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
|
import * as exec from "@actions/exec";
|
||||||
|
import * as io from "@actions/io";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import * as cacheHttpClient from "../src/cacheHttpClient";
|
import * as cacheHttpClient from "../src/cacheHttpClient";
|
||||||
import { Events, Inputs } from "../src/constants";
|
import { Events, Inputs } from "../src/constants";
|
||||||
import { ArtifactCacheEntry } from "../src/contracts";
|
import { ArtifactCacheEntry } from "../src/contracts";
|
||||||
import run from "../src/restore";
|
import run from "../src/restore";
|
||||||
import * as tar from "../src/tar";
|
|
||||||
import * as actionUtils from "../src/utils/actionUtils";
|
import * as actionUtils from "../src/utils/actionUtils";
|
||||||
import * as testUtils from "../src/utils/testUtils";
|
import * as testUtils from "../src/utils/testUtils";
|
||||||
|
|
||||||
jest.mock("../src/cacheHttpClient");
|
jest.mock("@actions/exec");
|
||||||
jest.mock("../src/tar");
|
jest.mock("@actions/io");
|
||||||
jest.mock("../src/utils/actionUtils");
|
jest.mock("../src/utils/actionUtils");
|
||||||
|
jest.mock("../src/cacheHttpClient");
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
jest.spyOn(actionUtils, "resolvePath").mockImplementation(filePath => {
|
jest.spyOn(actionUtils, "resolvePath").mockImplementation(filePath => {
|
||||||
@ -33,6 +35,10 @@ beforeAll(() => {
|
|||||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
||||||
return actualUtils.getSupportedEvents();
|
return actualUtils.getSupportedEvents();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
jest.spyOn(io, "which").mockImplementation(tool => {
|
||||||
|
return Promise.resolve(tool);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@ -44,16 +50,14 @@ afterEach(() => {
|
|||||||
delete process.env[Events.Key];
|
delete process.env[Events.Key];
|
||||||
});
|
});
|
||||||
|
|
||||||
test("restore with invalid event outputs warning", async () => {
|
test("restore with invalid event", async () => {
|
||||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
const invalidEvent = "commit_comment";
|
const invalidEvent = "commit_comment";
|
||||||
process.env[Events.Key] = invalidEvent;
|
process.env[Events.Key] = invalidEvent;
|
||||||
await run();
|
await run();
|
||||||
expect(logWarningMock).toHaveBeenCalledWith(
|
expect(failedMock).toHaveBeenCalledWith(
|
||||||
`Event Validation Error: The event type ${invalidEvent} is not supported. Only push, pull_request events are supported at this time.`
|
`Event Validation Error: The event type ${invalidEvent} is not supported. Only push, pull_request events are supported at this time.`
|
||||||
);
|
);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("restore with no path should fail", async () => {
|
test("restore with no path should fail", async () => {
|
||||||
@ -122,6 +126,7 @@ test("restore with no cache found", async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
const infoMock = jest.spyOn(core, "info");
|
||||||
|
const warningMock = jest.spyOn(core, "warning");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
const stateMock = jest.spyOn(core, "saveState");
|
||||||
|
|
||||||
@ -133,6 +138,7 @@ test("restore with no cache found", async () => {
|
|||||||
await run();
|
await run();
|
||||||
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||||
|
expect(warningMock).toHaveBeenCalledTimes(0);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(
|
expect(infoMock).toHaveBeenCalledWith(
|
||||||
@ -147,7 +153,7 @@ test("restore with server error should fail", async () => {
|
|||||||
key
|
key
|
||||||
});
|
});
|
||||||
|
|
||||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
const warningMock = jest.spyOn(core, "warning");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
const stateMock = jest.spyOn(core, "saveState");
|
||||||
|
|
||||||
@ -162,8 +168,8 @@ test("restore with server error should fail", async () => {
|
|||||||
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||||
|
|
||||||
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
expect(warningMock).toHaveBeenCalledTimes(1);
|
||||||
expect(logWarningMock).toHaveBeenCalledWith("HTTP Error Occurred");
|
expect(warningMock).toHaveBeenCalledWith("HTTP Error Occurred");
|
||||||
|
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith(false);
|
expect(setCacheHitOutputMock).toHaveBeenCalledWith(false);
|
||||||
@ -181,6 +187,7 @@ test("restore with restore keys and no cache found", async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
const infoMock = jest.spyOn(core, "info");
|
||||||
|
const warningMock = jest.spyOn(core, "warning");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
const stateMock = jest.spyOn(core, "saveState");
|
||||||
|
|
||||||
@ -192,6 +199,7 @@ test("restore with restore keys and no cache found", async () => {
|
|||||||
await run();
|
await run();
|
||||||
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||||
|
expect(warningMock).toHaveBeenCalledTimes(0);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(
|
expect(infoMock).toHaveBeenCalledWith(
|
||||||
@ -208,6 +216,7 @@ test("restore with cache found", async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
const infoMock = jest.spyOn(core, "info");
|
||||||
|
const warningMock = jest.spyOn(core, "warning");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
const stateMock = jest.spyOn(core, "saveState");
|
||||||
|
|
||||||
@ -239,7 +248,8 @@ test("restore with cache found", async () => {
|
|||||||
.spyOn(actionUtils, "getArchiveFileSize")
|
.spyOn(actionUtils, "getArchiveFileSize")
|
||||||
.mockReturnValue(fileSize);
|
.mockReturnValue(fileSize);
|
||||||
|
|
||||||
const extractTarMock = jest.spyOn(tar, "extractTar");
|
const mkdirMock = jest.spyOn(io, "mkdirP");
|
||||||
|
const execMock = jest.spyOn(exec, "exec");
|
||||||
const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput");
|
const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput");
|
||||||
|
|
||||||
await run();
|
await run();
|
||||||
@ -250,14 +260,28 @@ test("restore with cache found", async () => {
|
|||||||
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1);
|
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1);
|
||||||
expect(downloadCacheMock).toHaveBeenCalledWith(cacheEntry, archivePath);
|
expect(downloadCacheMock).toHaveBeenCalledWith(cacheEntry, archivePath);
|
||||||
expect(getArchiveFileSizeMock).toHaveBeenCalledWith(archivePath);
|
expect(getArchiveFileSizeMock).toHaveBeenCalledWith(archivePath);
|
||||||
|
expect(mkdirMock).toHaveBeenCalledWith(cachePath);
|
||||||
|
|
||||||
expect(extractTarMock).toHaveBeenCalledTimes(1);
|
const IS_WINDOWS = process.platform === "win32";
|
||||||
expect(extractTarMock).toHaveBeenCalledWith(archivePath, cachePath);
|
const args = IS_WINDOWS
|
||||||
|
? [
|
||||||
|
"-xz",
|
||||||
|
"--force-local",
|
||||||
|
"-f",
|
||||||
|
archivePath.replace(/\\/g, "/"),
|
||||||
|
"-C",
|
||||||
|
cachePath.replace(/\\/g, "/")
|
||||||
|
]
|
||||||
|
: ["-xz", "-f", archivePath, "-C", cachePath];
|
||||||
|
|
||||||
|
expect(execMock).toHaveBeenCalledTimes(1);
|
||||||
|
expect(execMock).toHaveBeenCalledWith(`"tar"`, args);
|
||||||
|
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith(true);
|
expect(setCacheHitOutputMock).toHaveBeenCalledWith(true);
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
||||||
|
expect(warningMock).toHaveBeenCalledTimes(0);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -272,6 +296,7 @@ test("restore with a pull request event and cache found", async () => {
|
|||||||
process.env[Events.Key] = Events.PullRequest;
|
process.env[Events.Key] = Events.PullRequest;
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
const infoMock = jest.spyOn(core, "info");
|
||||||
|
const warningMock = jest.spyOn(core, "warning");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
const stateMock = jest.spyOn(core, "saveState");
|
||||||
|
|
||||||
@ -303,7 +328,8 @@ test("restore with a pull request event and cache found", async () => {
|
|||||||
.spyOn(actionUtils, "getArchiveFileSize")
|
.spyOn(actionUtils, "getArchiveFileSize")
|
||||||
.mockReturnValue(fileSize);
|
.mockReturnValue(fileSize);
|
||||||
|
|
||||||
const extractTarMock = jest.spyOn(tar, "extractTar");
|
const mkdirMock = jest.spyOn(io, "mkdirP");
|
||||||
|
const execMock = jest.spyOn(exec, "exec");
|
||||||
const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput");
|
const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput");
|
||||||
|
|
||||||
await run();
|
await run();
|
||||||
@ -315,14 +341,28 @@ test("restore with a pull request event and cache found", async () => {
|
|||||||
expect(downloadCacheMock).toHaveBeenCalledWith(cacheEntry, archivePath);
|
expect(downloadCacheMock).toHaveBeenCalledWith(cacheEntry, archivePath);
|
||||||
expect(getArchiveFileSizeMock).toHaveBeenCalledWith(archivePath);
|
expect(getArchiveFileSizeMock).toHaveBeenCalledWith(archivePath);
|
||||||
expect(infoMock).toHaveBeenCalledWith(`Cache Size: ~60 MB (62915000 B)`);
|
expect(infoMock).toHaveBeenCalledWith(`Cache Size: ~60 MB (62915000 B)`);
|
||||||
|
expect(mkdirMock).toHaveBeenCalledWith(cachePath);
|
||||||
|
|
||||||
expect(extractTarMock).toHaveBeenCalledTimes(1);
|
const IS_WINDOWS = process.platform === "win32";
|
||||||
expect(extractTarMock).toHaveBeenCalledWith(archivePath, cachePath);
|
const args = IS_WINDOWS
|
||||||
|
? [
|
||||||
|
"-xz",
|
||||||
|
"--force-local",
|
||||||
|
"-f",
|
||||||
|
archivePath.replace(/\\/g, "/"),
|
||||||
|
"-C",
|
||||||
|
cachePath.replace(/\\/g, "/")
|
||||||
|
]
|
||||||
|
: ["-xz", "-f", archivePath, "-C", cachePath];
|
||||||
|
|
||||||
|
expect(execMock).toHaveBeenCalledTimes(1);
|
||||||
|
expect(execMock).toHaveBeenCalledWith(`"tar"`, args);
|
||||||
|
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith(true);
|
expect(setCacheHitOutputMock).toHaveBeenCalledWith(true);
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
||||||
|
expect(warningMock).toHaveBeenCalledTimes(0);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -337,6 +377,7 @@ test("restore with cache found for restore key", async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
const infoMock = jest.spyOn(core, "info");
|
||||||
|
const warningMock = jest.spyOn(core, "warning");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
const stateMock = jest.spyOn(core, "saveState");
|
||||||
|
|
||||||
@ -368,7 +409,8 @@ test("restore with cache found for restore key", async () => {
|
|||||||
.spyOn(actionUtils, "getArchiveFileSize")
|
.spyOn(actionUtils, "getArchiveFileSize")
|
||||||
.mockReturnValue(fileSize);
|
.mockReturnValue(fileSize);
|
||||||
|
|
||||||
const extractTarMock = jest.spyOn(tar, "extractTar");
|
const mkdirMock = jest.spyOn(io, "mkdirP");
|
||||||
|
const execMock = jest.spyOn(exec, "exec");
|
||||||
const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput");
|
const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput");
|
||||||
|
|
||||||
await run();
|
await run();
|
||||||
@ -380,9 +422,22 @@ test("restore with cache found for restore key", async () => {
|
|||||||
expect(downloadCacheMock).toHaveBeenCalledWith(cacheEntry, archivePath);
|
expect(downloadCacheMock).toHaveBeenCalledWith(cacheEntry, archivePath);
|
||||||
expect(getArchiveFileSizeMock).toHaveBeenCalledWith(archivePath);
|
expect(getArchiveFileSizeMock).toHaveBeenCalledWith(archivePath);
|
||||||
expect(infoMock).toHaveBeenCalledWith(`Cache Size: ~0 MB (142 B)`);
|
expect(infoMock).toHaveBeenCalledWith(`Cache Size: ~0 MB (142 B)`);
|
||||||
|
expect(mkdirMock).toHaveBeenCalledWith(cachePath);
|
||||||
|
|
||||||
expect(extractTarMock).toHaveBeenCalledTimes(1);
|
const IS_WINDOWS = process.platform === "win32";
|
||||||
expect(extractTarMock).toHaveBeenCalledWith(archivePath, cachePath);
|
const args = IS_WINDOWS
|
||||||
|
? [
|
||||||
|
"-xz",
|
||||||
|
"--force-local",
|
||||||
|
"-f",
|
||||||
|
archivePath.replace(/\\/g, "/"),
|
||||||
|
"-C",
|
||||||
|
cachePath.replace(/\\/g, "/")
|
||||||
|
]
|
||||||
|
: ["-xz", "-f", archivePath, "-C", cachePath];
|
||||||
|
|
||||||
|
expect(execMock).toHaveBeenCalledTimes(1);
|
||||||
|
expect(execMock).toHaveBeenCalledWith(`"tar"`, args);
|
||||||
|
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith(false);
|
expect(setCacheHitOutputMock).toHaveBeenCalledWith(false);
|
||||||
@ -390,5 +445,6 @@ test("restore with cache found for restore key", async () => {
|
|||||||
expect(infoMock).toHaveBeenCalledWith(
|
expect(infoMock).toHaveBeenCalledWith(
|
||||||
`Cache restored from key: ${restoreKey}`
|
`Cache restored from key: ${restoreKey}`
|
||||||
);
|
);
|
||||||
|
expect(warningMock).toHaveBeenCalledTimes(0);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
|
import * as exec from "@actions/exec";
|
||||||
|
import * as io from "@actions/io";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import * as cacheHttpClient from "../src/cacheHttpClient";
|
import * as cacheHttpClient from "../src/cacheHttpClient";
|
||||||
import { Events, Inputs } from "../src/constants";
|
import { Inputs } from "../src/constants";
|
||||||
import { ArtifactCacheEntry } from "../src/contracts";
|
import { ArtifactCacheEntry } from "../src/contracts";
|
||||||
import run from "../src/save";
|
import run from "../src/save";
|
||||||
import * as tar from "../src/tar";
|
|
||||||
import * as actionUtils from "../src/utils/actionUtils";
|
import * as actionUtils from "../src/utils/actionUtils";
|
||||||
import * as testUtils from "../src/utils/testUtils";
|
import * as testUtils from "../src/utils/testUtils";
|
||||||
|
|
||||||
jest.mock("@actions/core");
|
jest.mock("@actions/core");
|
||||||
jest.mock("../src/cacheHttpClient");
|
jest.mock("@actions/exec");
|
||||||
jest.mock("../src/tar");
|
jest.mock("@actions/io");
|
||||||
jest.mock("../src/utils/actionUtils");
|
jest.mock("../src/utils/actionUtils");
|
||||||
|
jest.mock("../src/cacheHttpClient");
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
jest.spyOn(core, "getInput").mockImplementation((name, options) => {
|
jest.spyOn(core, "getInput").mockImplementation((name, options) => {
|
||||||
@ -30,16 +32,6 @@ beforeAll(() => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "isValidEvent").mockImplementation(() => {
|
|
||||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
|
||||||
return actualUtils.isValidEvent();
|
|
||||||
});
|
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "getSupportedEvents").mockImplementation(() => {
|
|
||||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
|
||||||
return actualUtils.getSupportedEvents();
|
|
||||||
});
|
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "resolvePath").mockImplementation(filePath => {
|
jest.spyOn(actionUtils, "resolvePath").mockImplementation(filePath => {
|
||||||
return path.resolve(filePath);
|
return path.resolve(filePath);
|
||||||
});
|
});
|
||||||
@ -47,31 +39,18 @@ beforeAll(() => {
|
|||||||
jest.spyOn(actionUtils, "createTempDirectory").mockImplementation(() => {
|
jest.spyOn(actionUtils, "createTempDirectory").mockImplementation(() => {
|
||||||
return Promise.resolve("/foo/bar");
|
return Promise.resolve("/foo/bar");
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
jest.spyOn(io, "which").mockImplementation(tool => {
|
||||||
process.env[Events.Key] = Events.Push;
|
return Promise.resolve(tool);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
testUtils.clearInputs();
|
testUtils.clearInputs();
|
||||||
delete process.env[Events.Key];
|
|
||||||
});
|
|
||||||
|
|
||||||
test("save with invalid event outputs warning", async () => {
|
|
||||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
const invalidEvent = "commit_comment";
|
|
||||||
process.env[Events.Key] = invalidEvent;
|
|
||||||
await run();
|
|
||||||
expect(logWarningMock).toHaveBeenCalledWith(
|
|
||||||
`Event Validation Error: The event type ${invalidEvent} is not supported. Only push, pull_request events are supported at this time.`
|
|
||||||
);
|
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("save with no primary key in state outputs warning", async () => {
|
test("save with no primary key in state outputs warning", async () => {
|
||||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
const warningMock = jest.spyOn(core, "warning");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
|
|
||||||
const cacheEntry: ArtifactCacheEntry = {
|
const cacheEntry: ArtifactCacheEntry = {
|
||||||
@ -93,15 +72,16 @@ test("save with no primary key in state outputs warning", async () => {
|
|||||||
|
|
||||||
await run();
|
await run();
|
||||||
|
|
||||||
expect(logWarningMock).toHaveBeenCalledWith(
|
expect(warningMock).toHaveBeenCalledWith(
|
||||||
`Error retrieving key from state.`
|
`Error retrieving key from state.`
|
||||||
);
|
);
|
||||||
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
expect(warningMock).toHaveBeenCalledTimes(1);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("save with exact match returns early", async () => {
|
test("save with exact match returns early", async () => {
|
||||||
const infoMock = jest.spyOn(core, "info");
|
const infoMock = jest.spyOn(core, "info");
|
||||||
|
const warningMock = jest.spyOn(core, "warning");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
|
|
||||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||||
@ -122,7 +102,7 @@ test("save with exact match returns early", async () => {
|
|||||||
return primaryKey;
|
return primaryKey;
|
||||||
});
|
});
|
||||||
|
|
||||||
const createTarMock = jest.spyOn(tar, "createTar");
|
const execMock = jest.spyOn(exec, "exec");
|
||||||
|
|
||||||
await run();
|
await run();
|
||||||
|
|
||||||
@ -130,13 +110,14 @@ test("save with exact match returns early", async () => {
|
|||||||
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
|
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(createTarMock).toHaveBeenCalledTimes(0);
|
expect(execMock).toHaveBeenCalledTimes(0);
|
||||||
|
|
||||||
|
expect(warningMock).toHaveBeenCalledTimes(0);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("save with missing input outputs warning", async () => {
|
test("save with missing input outputs warning", async () => {
|
||||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
const warningMock = jest.spyOn(core, "warning");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
|
|
||||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||||
@ -159,15 +140,15 @@ test("save with missing input outputs warning", async () => {
|
|||||||
|
|
||||||
await run();
|
await run();
|
||||||
|
|
||||||
expect(logWarningMock).toHaveBeenCalledWith(
|
expect(warningMock).toHaveBeenCalledWith(
|
||||||
"Input required and not supplied: path"
|
"Input required and not supplied: path"
|
||||||
);
|
);
|
||||||
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
expect(warningMock).toHaveBeenCalledTimes(1);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("save with large cache outputs warning", async () => {
|
test("save with large cache outputs warning", async () => {
|
||||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
const warningMock = jest.spyOn(core, "warning");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
|
|
||||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||||
@ -192,7 +173,7 @@ test("save with large cache outputs warning", async () => {
|
|||||||
const cachePath = path.resolve(inputPath);
|
const cachePath = path.resolve(inputPath);
|
||||||
testUtils.setInput(Inputs.Path, inputPath);
|
testUtils.setInput(Inputs.Path, inputPath);
|
||||||
|
|
||||||
const createTarMock = jest.spyOn(tar, "createTar");
|
const execMock = jest.spyOn(exec, "exec");
|
||||||
|
|
||||||
const cacheSize = 1024 * 1024 * 1024; //~1GB, over the 400MB limit
|
const cacheSize = 1024 * 1024 * 1024; //~1GB, over the 400MB limit
|
||||||
jest.spyOn(actionUtils, "getArchiveFileSize").mockImplementationOnce(() => {
|
jest.spyOn(actionUtils, "getArchiveFileSize").mockImplementationOnce(() => {
|
||||||
@ -203,11 +184,24 @@ test("save with large cache outputs warning", async () => {
|
|||||||
|
|
||||||
const archivePath = path.join("/foo/bar", "cache.tgz");
|
const archivePath = path.join("/foo/bar", "cache.tgz");
|
||||||
|
|
||||||
expect(createTarMock).toHaveBeenCalledTimes(1);
|
const IS_WINDOWS = process.platform === "win32";
|
||||||
expect(createTarMock).toHaveBeenCalledWith(archivePath, cachePath);
|
const args = IS_WINDOWS
|
||||||
|
? [
|
||||||
|
"-cz",
|
||||||
|
"--force-local",
|
||||||
|
"-f",
|
||||||
|
archivePath.replace(/\\/g, "/"),
|
||||||
|
"-C",
|
||||||
|
cachePath.replace(/\\/g, "/"),
|
||||||
|
"."
|
||||||
|
]
|
||||||
|
: ["-cz", "-f", archivePath, "-C", cachePath, "."];
|
||||||
|
|
||||||
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
expect(execMock).toHaveBeenCalledTimes(1);
|
||||||
expect(logWarningMock).toHaveBeenCalledWith(
|
expect(execMock).toHaveBeenCalledWith(`"tar"`, args);
|
||||||
|
|
||||||
|
expect(warningMock).toHaveBeenCalledTimes(1);
|
||||||
|
expect(warningMock).toHaveBeenCalledWith(
|
||||||
"Cache size of ~1024 MB (1073741824 B) is over the 400MB limit, not saving cache."
|
"Cache size of ~1024 MB (1073741824 B) is over the 400MB limit, not saving cache."
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -215,7 +209,7 @@ test("save with large cache outputs warning", async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("save with server error outputs warning", async () => {
|
test("save with server error outputs warning", async () => {
|
||||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
const warningMock = jest.spyOn(core, "warning");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
|
|
||||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||||
@ -240,7 +234,7 @@ test("save with server error outputs warning", async () => {
|
|||||||
const cachePath = path.resolve(inputPath);
|
const cachePath = path.resolve(inputPath);
|
||||||
testUtils.setInput(Inputs.Path, inputPath);
|
testUtils.setInput(Inputs.Path, inputPath);
|
||||||
|
|
||||||
const createTarMock = jest.spyOn(tar, "createTar");
|
const execMock = jest.spyOn(exec, "exec");
|
||||||
|
|
||||||
const saveCacheMock = jest
|
const saveCacheMock = jest
|
||||||
.spyOn(cacheHttpClient, "saveCache")
|
.spyOn(cacheHttpClient, "saveCache")
|
||||||
@ -252,19 +246,33 @@ test("save with server error outputs warning", async () => {
|
|||||||
|
|
||||||
const archivePath = path.join("/foo/bar", "cache.tgz");
|
const archivePath = path.join("/foo/bar", "cache.tgz");
|
||||||
|
|
||||||
expect(createTarMock).toHaveBeenCalledTimes(1);
|
const IS_WINDOWS = process.platform === "win32";
|
||||||
expect(createTarMock).toHaveBeenCalledWith(archivePath, cachePath);
|
const args = IS_WINDOWS
|
||||||
|
? [
|
||||||
|
"-cz",
|
||||||
|
"--force-local",
|
||||||
|
"-f",
|
||||||
|
archivePath.replace(/\\/g, "/"),
|
||||||
|
"-C",
|
||||||
|
cachePath.replace(/\\/g, "/"),
|
||||||
|
"."
|
||||||
|
]
|
||||||
|
: ["-cz", "-f", archivePath, "-C", cachePath, "."];
|
||||||
|
|
||||||
|
expect(execMock).toHaveBeenCalledTimes(1);
|
||||||
|
expect(execMock).toHaveBeenCalledWith(`"tar"`, args);
|
||||||
|
|
||||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
||||||
expect(saveCacheMock).toHaveBeenCalledWith(primaryKey, archivePath);
|
expect(saveCacheMock).toHaveBeenCalledWith(primaryKey, archivePath);
|
||||||
|
|
||||||
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
expect(warningMock).toHaveBeenCalledTimes(1);
|
||||||
expect(logWarningMock).toHaveBeenCalledWith("HTTP Error Occurred");
|
expect(warningMock).toHaveBeenCalledWith("HTTP Error Occurred");
|
||||||
|
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("save with valid inputs uploads a cache", async () => {
|
test("save with valid inputs uploads a cache", async () => {
|
||||||
|
const warningMock = jest.spyOn(core, "warning");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
|
|
||||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||||
@ -289,18 +297,33 @@ test("save with valid inputs uploads a cache", async () => {
|
|||||||
const cachePath = path.resolve(inputPath);
|
const cachePath = path.resolve(inputPath);
|
||||||
testUtils.setInput(Inputs.Path, inputPath);
|
testUtils.setInput(Inputs.Path, inputPath);
|
||||||
|
|
||||||
const createTarMock = jest.spyOn(tar, "createTar");
|
const execMock = jest.spyOn(exec, "exec");
|
||||||
|
|
||||||
const saveCacheMock = jest.spyOn(cacheHttpClient, "saveCache");
|
const saveCacheMock = jest.spyOn(cacheHttpClient, "saveCache");
|
||||||
|
|
||||||
await run();
|
await run();
|
||||||
|
|
||||||
const archivePath = path.join("/foo/bar", "cache.tgz");
|
const archivePath = path.join("/foo/bar", "cache.tgz");
|
||||||
|
|
||||||
expect(createTarMock).toHaveBeenCalledTimes(1);
|
const IS_WINDOWS = process.platform === "win32";
|
||||||
expect(createTarMock).toHaveBeenCalledWith(archivePath, cachePath);
|
const args = IS_WINDOWS
|
||||||
|
? [
|
||||||
|
"-cz",
|
||||||
|
"--force-local",
|
||||||
|
"-f",
|
||||||
|
archivePath.replace(/\\/g, "/"),
|
||||||
|
"-C",
|
||||||
|
cachePath.replace(/\\/g, "/"),
|
||||||
|
"."
|
||||||
|
]
|
||||||
|
: ["-cz", "-f", archivePath, "-C", cachePath, "."];
|
||||||
|
|
||||||
|
expect(execMock).toHaveBeenCalledTimes(1);
|
||||||
|
expect(execMock).toHaveBeenCalledWith(`"tar"`, args);
|
||||||
|
|
||||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
||||||
expect(saveCacheMock).toHaveBeenCalledWith(primaryKey, archivePath);
|
expect(saveCacheMock).toHaveBeenCalledWith(primaryKey, archivePath);
|
||||||
|
|
||||||
|
expect(warningMock).toHaveBeenCalledTimes(0);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
@ -1,60 +0,0 @@
|
|||||||
import * as exec from "@actions/exec";
|
|
||||||
import * as io from "@actions/io";
|
|
||||||
import * as tar from "../src/tar";
|
|
||||||
|
|
||||||
jest.mock("@actions/exec");
|
|
||||||
jest.mock("@actions/io");
|
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
process.env["windir"] = "C:";
|
|
||||||
|
|
||||||
jest.spyOn(io, "which").mockImplementation(tool => {
|
|
||||||
return Promise.resolve(tool);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
delete process.env["windir"];
|
|
||||||
});
|
|
||||||
|
|
||||||
test("extract tar", async () => {
|
|
||||||
const mkdirMock = jest.spyOn(io, "mkdirP");
|
|
||||||
const execMock = jest.spyOn(exec, "exec");
|
|
||||||
|
|
||||||
const archivePath = "cache.tar";
|
|
||||||
const targetDirectory = "~/.npm/cache";
|
|
||||||
await tar.extractTar(archivePath, targetDirectory);
|
|
||||||
|
|
||||||
expect(mkdirMock).toHaveBeenCalledWith(targetDirectory);
|
|
||||||
|
|
||||||
const IS_WINDOWS = process.platform === "win32";
|
|
||||||
const tarPath = IS_WINDOWS ? "C:\\System32\\tar.exe" : "tar";
|
|
||||||
expect(execMock).toHaveBeenCalledTimes(1);
|
|
||||||
expect(execMock).toHaveBeenCalledWith(`"${tarPath}"`, [
|
|
||||||
"-xz",
|
|
||||||
"-f",
|
|
||||||
archivePath,
|
|
||||||
"-C",
|
|
||||||
targetDirectory
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("create tar", async () => {
|
|
||||||
const execMock = jest.spyOn(exec, "exec");
|
|
||||||
|
|
||||||
const archivePath = "cache.tar";
|
|
||||||
const sourceDirectory = "~/.npm/cache";
|
|
||||||
await tar.createTar(archivePath, sourceDirectory);
|
|
||||||
|
|
||||||
const IS_WINDOWS = process.platform === "win32";
|
|
||||||
const tarPath = IS_WINDOWS ? "C:\\System32\\tar.exe" : "tar";
|
|
||||||
expect(execMock).toHaveBeenCalledTimes(1);
|
|
||||||
expect(execMock).toHaveBeenCalledWith(`"${tarPath}"`, [
|
|
||||||
"-cz",
|
|
||||||
"-f",
|
|
||||||
archivePath,
|
|
||||||
"-C",
|
|
||||||
sourceDirectory,
|
|
||||||
"."
|
|
||||||
]);
|
|
||||||
});
|
|
94
dist/restore/index.js
vendored
94
dist/restore/index.js
vendored
@ -1533,12 +1533,11 @@ function getCacheEntry(keys) {
|
|||||||
throw new Error(`Cache service responded with ${response.statusCode}`);
|
throw new Error(`Cache service responded with ${response.statusCode}`);
|
||||||
}
|
}
|
||||||
const cacheResult = response.result;
|
const cacheResult = response.result;
|
||||||
|
core.debug(`Cache Result:`);
|
||||||
|
core.debug(JSON.stringify(cacheResult));
|
||||||
if (!cacheResult || !cacheResult.archiveLocation) {
|
if (!cacheResult || !cacheResult.archiveLocation) {
|
||||||
throw new Error("Cache not found.");
|
throw new Error("Cache not found.");
|
||||||
}
|
}
|
||||||
core.setSecret(cacheResult.archiveLocation);
|
|
||||||
core.debug(`Cache Result:`);
|
|
||||||
core.debug(JSON.stringify(cacheResult));
|
|
||||||
return cacheResult;
|
return cacheResult;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -2209,11 +2208,6 @@ function getCacheState() {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
exports.getCacheState = getCacheState;
|
exports.getCacheState = getCacheState;
|
||||||
function logWarning(message) {
|
|
||||||
const warningPrefix = "[warning]";
|
|
||||||
core.info(`${warningPrefix}${message}`);
|
|
||||||
}
|
|
||||||
exports.logWarning = logWarning;
|
|
||||||
function resolvePath(filePath) {
|
function resolvePath(filePath) {
|
||||||
if (filePath[0] === "~") {
|
if (filePath[0] === "~") {
|
||||||
const home = os.homedir();
|
const home = os.homedir();
|
||||||
@ -2991,20 +2985,20 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const core = __importStar(__webpack_require__(470));
|
const core = __importStar(__webpack_require__(470));
|
||||||
|
const exec_1 = __webpack_require__(986);
|
||||||
|
const io = __importStar(__webpack_require__(1));
|
||||||
const path = __importStar(__webpack_require__(622));
|
const path = __importStar(__webpack_require__(622));
|
||||||
const cacheHttpClient = __importStar(__webpack_require__(154));
|
const cacheHttpClient = __importStar(__webpack_require__(154));
|
||||||
const constants_1 = __webpack_require__(694);
|
const constants_1 = __webpack_require__(694);
|
||||||
const tar_1 = __webpack_require__(943);
|
|
||||||
const utils = __importStar(__webpack_require__(443));
|
const utils = __importStar(__webpack_require__(443));
|
||||||
function run() {
|
function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
// Validate inputs, this can cause task failure
|
// Validate inputs, this can cause task failure
|
||||||
if (!utils.isValidEvent()) {
|
if (!utils.isValidEvent()) {
|
||||||
utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported. Only ${utils
|
core.setFailed(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported. Only ${utils
|
||||||
.getSupportedEvents()
|
.getSupportedEvents()
|
||||||
.join(", ")} events are supported at this time.`);
|
.join(", ")} events are supported at this time.`);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
const cachePath = utils.resolvePath(core.getInput(constants_1.Inputs.Path, { required: true }));
|
const cachePath = utils.resolvePath(core.getInput(constants_1.Inputs.Path, { required: true }));
|
||||||
core.debug(`Cache Path: ${cachePath}`);
|
core.debug(`Cache Path: ${cachePath}`);
|
||||||
@ -3046,13 +3040,30 @@ function run() {
|
|||||||
yield cacheHttpClient.downloadCache(cacheEntry, archivePath);
|
yield cacheHttpClient.downloadCache(cacheEntry, archivePath);
|
||||||
const archiveFileSize = utils.getArchiveFileSize(archivePath);
|
const archiveFileSize = utils.getArchiveFileSize(archivePath);
|
||||||
core.info(`Cache Size: ~${Math.round(archiveFileSize / (1024 * 1024))} MB (${archiveFileSize} B)`);
|
core.info(`Cache Size: ~${Math.round(archiveFileSize / (1024 * 1024))} MB (${archiveFileSize} B)`);
|
||||||
yield tar_1.extractTar(archivePath, cachePath);
|
// Create directory to extract tar into
|
||||||
|
yield io.mkdirP(cachePath);
|
||||||
|
// 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
|
||||||
|
? [
|
||||||
|
"-xz",
|
||||||
|
"--force-local",
|
||||||
|
"-f",
|
||||||
|
archivePath.replace(/\\/g, "/"),
|
||||||
|
"-C",
|
||||||
|
cachePath.replace(/\\/g, "/")
|
||||||
|
]
|
||||||
|
: ["-xz", "-f", archivePath, "-C", cachePath];
|
||||||
|
const tarPath = yield io.which("tar", true);
|
||||||
|
core.debug(`Tar Path: ${tarPath}`);
|
||||||
|
yield exec_1.exec(`"${tarPath}"`, args);
|
||||||
const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheEntry);
|
const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheEntry);
|
||||||
utils.setCacheHitOutput(isExactKeyMatch);
|
utils.setCacheHitOutput(isExactKeyMatch);
|
||||||
core.info(`Cache restored from key: ${cacheEntry && cacheEntry.cacheKey}`);
|
core.info(`Cache restored from key: ${cacheEntry && cacheEntry.cacheKey}`);
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
utils.logWarning(error.message);
|
core.warning(error.message);
|
||||||
utils.setCacheHitOutput(false);
|
utils.setCacheHitOutput(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -5142,63 +5153,6 @@ var personalaccesstoken_1 = __webpack_require__(327);
|
|||||||
exports.PersonalAccessTokenCredentialHandler = personalaccesstoken_1.PersonalAccessTokenCredentialHandler;
|
exports.PersonalAccessTokenCredentialHandler = personalaccesstoken_1.PersonalAccessTokenCredentialHandler;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
|
||||||
|
|
||||||
/***/ 943:
|
|
||||||
/***/ (function(__unusedmodule, exports, __webpack_require__) {
|
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
||||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
|
||||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
||||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
||||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
||||||
});
|
|
||||||
};
|
|
||||||
var __importStar = (this && this.__importStar) || function (mod) {
|
|
||||||
if (mod && mod.__esModule) return mod;
|
|
||||||
var result = {};
|
|
||||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
||||||
result["default"] = mod;
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
const exec_1 = __webpack_require__(986);
|
|
||||||
const io = __importStar(__webpack_require__(1));
|
|
||||||
function extractTar(archivePath, targetDirectory) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
// Create directory to extract tar into
|
|
||||||
yield io.mkdirP(targetDirectory);
|
|
||||||
// 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 args = ["-xz", "-f", archivePath, "-C", targetDirectory];
|
|
||||||
yield exec_1.exec(`"${yield getTarPath()}"`, args);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
exports.extractTar = extractTar;
|
|
||||||
function createTar(archivePath, sourceDirectory) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
// 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 args = ["-cz", "-f", archivePath, "-C", sourceDirectory, "."];
|
|
||||||
yield exec_1.exec(`"${yield getTarPath()}"`, args);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
exports.createTar = createTar;
|
|
||||||
function getTarPath() {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
// Explicitly use BSD Tar on Windows
|
|
||||||
const IS_WINDOWS = process.platform === "win32";
|
|
||||||
return IS_WINDOWS
|
|
||||||
? `${process.env["windir"]}\\System32\\tar.exe`
|
|
||||||
: yield io.which("tar", true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 986:
|
/***/ 986:
|
||||||
|
100
dist/save/index.js
vendored
100
dist/save/index.js
vendored
@ -1533,12 +1533,11 @@ function getCacheEntry(keys) {
|
|||||||
throw new Error(`Cache service responded with ${response.statusCode}`);
|
throw new Error(`Cache service responded with ${response.statusCode}`);
|
||||||
}
|
}
|
||||||
const cacheResult = response.result;
|
const cacheResult = response.result;
|
||||||
|
core.debug(`Cache Result:`);
|
||||||
|
core.debug(JSON.stringify(cacheResult));
|
||||||
if (!cacheResult || !cacheResult.archiveLocation) {
|
if (!cacheResult || !cacheResult.archiveLocation) {
|
||||||
throw new Error("Cache not found.");
|
throw new Error("Cache not found.");
|
||||||
}
|
}
|
||||||
core.setSecret(cacheResult.archiveLocation);
|
|
||||||
core.debug(`Cache Result:`);
|
|
||||||
core.debug(JSON.stringify(cacheResult));
|
|
||||||
return cacheResult;
|
return cacheResult;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -2209,11 +2208,6 @@ function getCacheState() {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
exports.getCacheState = getCacheState;
|
exports.getCacheState = getCacheState;
|
||||||
function logWarning(message) {
|
|
||||||
const warningPrefix = "[warning]";
|
|
||||||
core.info(`${warningPrefix}${message}`);
|
|
||||||
}
|
|
||||||
exports.logWarning = logWarning;
|
|
||||||
function resolvePath(filePath) {
|
function resolvePath(filePath) {
|
||||||
if (filePath[0] === "~") {
|
if (filePath[0] === "~") {
|
||||||
const home = os.homedir();
|
const home = os.homedir();
|
||||||
@ -2879,25 +2873,20 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const core = __importStar(__webpack_require__(470));
|
const core = __importStar(__webpack_require__(470));
|
||||||
|
const exec_1 = __webpack_require__(986);
|
||||||
|
const io = __importStar(__webpack_require__(1));
|
||||||
const path = __importStar(__webpack_require__(622));
|
const path = __importStar(__webpack_require__(622));
|
||||||
const cacheHttpClient = __importStar(__webpack_require__(154));
|
const cacheHttpClient = __importStar(__webpack_require__(154));
|
||||||
const constants_1 = __webpack_require__(694);
|
const constants_1 = __webpack_require__(694);
|
||||||
const tar_1 = __webpack_require__(943);
|
|
||||||
const utils = __importStar(__webpack_require__(443));
|
const utils = __importStar(__webpack_require__(443));
|
||||||
function run() {
|
function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
if (!utils.isValidEvent()) {
|
|
||||||
utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported. Only ${utils
|
|
||||||
.getSupportedEvents()
|
|
||||||
.join(", ")} events are supported at this time.`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const state = utils.getCacheState();
|
const state = utils.getCacheState();
|
||||||
// Inputs are re-evaluted before the post action, so we want the original key used for restore
|
// Inputs are re-evaluted before the post action, so we want the original key used for restore
|
||||||
const primaryKey = core.getState(constants_1.State.CacheKey);
|
const primaryKey = core.getState(constants_1.State.CacheKey);
|
||||||
if (!primaryKey) {
|
if (!primaryKey) {
|
||||||
utils.logWarning(`Error retrieving key from state.`);
|
core.warning(`Error retrieving key from state.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (utils.isExactKeyMatch(primaryKey, state)) {
|
if (utils.isExactKeyMatch(primaryKey, state)) {
|
||||||
@ -2908,18 +2897,34 @@ function run() {
|
|||||||
core.debug(`Cache Path: ${cachePath}`);
|
core.debug(`Cache Path: ${cachePath}`);
|
||||||
const archivePath = path.join(yield utils.createTempDirectory(), "cache.tgz");
|
const archivePath = path.join(yield utils.createTempDirectory(), "cache.tgz");
|
||||||
core.debug(`Archive Path: ${archivePath}`);
|
core.debug(`Archive Path: ${archivePath}`);
|
||||||
yield tar_1.createTar(archivePath, cachePath);
|
// 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, "."];
|
||||||
|
const tarPath = yield io.which("tar", true);
|
||||||
|
core.debug(`Tar Path: ${tarPath}`);
|
||||||
|
yield exec_1.exec(`"${tarPath}"`, args);
|
||||||
const fileSizeLimit = 400 * 1024 * 1024; // 400MB
|
const fileSizeLimit = 400 * 1024 * 1024; // 400MB
|
||||||
const archiveFileSize = utils.getArchiveFileSize(archivePath);
|
const archiveFileSize = utils.getArchiveFileSize(archivePath);
|
||||||
core.debug(`File Size: ${archiveFileSize}`);
|
core.debug(`File Size: ${archiveFileSize}`);
|
||||||
if (archiveFileSize > fileSizeLimit) {
|
if (archiveFileSize > fileSizeLimit) {
|
||||||
utils.logWarning(`Cache size of ~${Math.round(archiveFileSize / (1024 * 1024))} MB (${archiveFileSize} B) is over the 400MB limit, not saving cache.`);
|
core.warning(`Cache size of ~${Math.round(archiveFileSize / (1024 * 1024))} MB (${archiveFileSize} B) is over the 400MB limit, not saving cache.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
yield cacheHttpClient.saveCache(primaryKey, archivePath);
|
yield cacheHttpClient.saveCache(primaryKey, archivePath);
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
utils.logWarning(error.message);
|
core.warning(error.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -5116,63 +5121,6 @@ var personalaccesstoken_1 = __webpack_require__(327);
|
|||||||
exports.PersonalAccessTokenCredentialHandler = personalaccesstoken_1.PersonalAccessTokenCredentialHandler;
|
exports.PersonalAccessTokenCredentialHandler = personalaccesstoken_1.PersonalAccessTokenCredentialHandler;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
|
||||||
|
|
||||||
/***/ 943:
|
|
||||||
/***/ (function(__unusedmodule, exports, __webpack_require__) {
|
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
||||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
|
||||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
||||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
||||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
||||||
});
|
|
||||||
};
|
|
||||||
var __importStar = (this && this.__importStar) || function (mod) {
|
|
||||||
if (mod && mod.__esModule) return mod;
|
|
||||||
var result = {};
|
|
||||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
||||||
result["default"] = mod;
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
const exec_1 = __webpack_require__(986);
|
|
||||||
const io = __importStar(__webpack_require__(1));
|
|
||||||
function extractTar(archivePath, targetDirectory) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
// Create directory to extract tar into
|
|
||||||
yield io.mkdirP(targetDirectory);
|
|
||||||
// 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 args = ["-xz", "-f", archivePath, "-C", targetDirectory];
|
|
||||||
yield exec_1.exec(`"${yield getTarPath()}"`, args);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
exports.extractTar = extractTar;
|
|
||||||
function createTar(archivePath, sourceDirectory) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
// 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 args = ["-cz", "-f", archivePath, "-C", sourceDirectory, "."];
|
|
||||||
yield exec_1.exec(`"${yield getTarPath()}"`, args);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
exports.createTar = createTar;
|
|
||||||
function getTarPath() {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
// Explicitly use BSD Tar on Windows
|
|
||||||
const IS_WINDOWS = process.platform === "win32";
|
|
||||||
return IS_WINDOWS
|
|
||||||
? `${process.env["windir"]}\\System32\\tar.exe`
|
|
||||||
: yield io.which("tar", true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 986:
|
/***/ 986:
|
||||||
|
41
examples.md
41
examples.md
@ -1,18 +1,25 @@
|
|||||||
# Examples
|
# Examples
|
||||||
|
|
||||||
- [C# - Nuget](#c---nuget)
|
- [Examples](#examples)
|
||||||
- [Elixir - Mix](#elixir---mix)
|
- [C# - Nuget](#c---nuget)
|
||||||
- [Go - Modules](#go---modules)
|
- [Elixir - Mix](#elixir---mix)
|
||||||
- [Java - Gradle](#java---gradle)
|
- [Go - Modules](#go---modules)
|
||||||
- [Java - Maven](#java---maven)
|
- [Java - Gradle](#java---gradle)
|
||||||
- [Node - npm](#node---npm)
|
- [Java - Maven](#java---maven)
|
||||||
- [Node - Yarn](#node---yarn)
|
- [Node - npm](#node---npm)
|
||||||
- [PHP - Composer](#php---composer)
|
- [macOS and Ubuntu](#macos-and-ubuntu)
|
||||||
- [Python - pip](#python---pip)
|
- [Windows](#windows)
|
||||||
- [Ruby - Gem](#ruby---gem)
|
- [Using multiple systems and `npm config`](#using-multiple-systems-and-npm-config)
|
||||||
- [Rust - Cargo](#rust---cargo)
|
- [Node - Yarn](#node---yarn)
|
||||||
- [Swift, Objective-C - Carthage](#swift-objective-c---carthage)
|
- [PHP - Composer](#php---composer)
|
||||||
- [Swift, Objective-C - CocoaPods](#swift-objective-c---cocoapods)
|
- [Python - pip](#python---pip)
|
||||||
|
- [Simple example](#simple-example)
|
||||||
|
- [Multiple OS's in a workflow](#multiple-oss-in-a-workflow)
|
||||||
|
- [Using a script to get cache location](#using-a-script-to-get-cache-location)
|
||||||
|
- [Ruby - Gem](#ruby---gem)
|
||||||
|
- [Rust - Cargo](#rust---cargo)
|
||||||
|
- [Swift, Objective-C - Carthage](#swift-objective-c---carthage)
|
||||||
|
- [Swift, Objective-C - CocoaPods](#swift-objective-c---cocoapods)
|
||||||
|
|
||||||
## C# - Nuget
|
## C# - Nuget
|
||||||
Using [NuGet lock files](https://docs.microsoft.com/nuget/consume-packages/package-references-in-project-files#locking-dependencies):
|
Using [NuGet lock files](https://docs.microsoft.com/nuget/consume-packages/package-references-in-project-files#locking-dependencies):
|
||||||
@ -219,14 +226,6 @@ Replace `~/.cache/pip` with the correct `path` if not using Ubuntu.
|
|||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-gem-
|
${{ runner.os }}-gem-
|
||||||
```
|
```
|
||||||
When dependencies are installed later in the workflow, we must specify the same path for the bundler.
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
- name: Bundle install
|
|
||||||
run: |
|
|
||||||
bundle config path vendor/bundle
|
|
||||||
bundle install --jobs 4 --retry 3
|
|
||||||
```
|
|
||||||
|
|
||||||
## Rust - Cargo
|
## Rust - Cargo
|
||||||
|
|
||||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cache",
|
"name": "cache",
|
||||||
"version": "1.0.3",
|
"version": "1.0.2",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cache",
|
"name": "cache",
|
||||||
"version": "1.0.3",
|
"version": "1.0.2",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Cache dependencies and build outputs",
|
"description": "Cache dependencies and build outputs",
|
||||||
"main": "dist/restore/index.js",
|
"main": "dist/restore/index.js",
|
||||||
|
@ -61,12 +61,11 @@ export async function getCacheEntry(
|
|||||||
throw new Error(`Cache service responded with ${response.statusCode}`);
|
throw new Error(`Cache service responded with ${response.statusCode}`);
|
||||||
}
|
}
|
||||||
const cacheResult = response.result;
|
const cacheResult = response.result;
|
||||||
|
core.debug(`Cache Result:`);
|
||||||
|
core.debug(JSON.stringify(cacheResult));
|
||||||
if (!cacheResult || !cacheResult.archiveLocation) {
|
if (!cacheResult || !cacheResult.archiveLocation) {
|
||||||
throw new Error("Cache not found.");
|
throw new Error("Cache not found.");
|
||||||
}
|
}
|
||||||
core.setSecret(cacheResult.archiveLocation);
|
|
||||||
core.debug(`Cache Result:`);
|
|
||||||
core.debug(JSON.stringify(cacheResult));
|
|
||||||
|
|
||||||
return cacheResult;
|
return cacheResult;
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,22 @@
|
|||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
|
import { exec } from "@actions/exec";
|
||||||
|
import * as io from "@actions/io";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import * as cacheHttpClient from "./cacheHttpClient";
|
import * as cacheHttpClient from "./cacheHttpClient";
|
||||||
import { Events, Inputs, State } from "./constants";
|
import { Events, Inputs, State } from "./constants";
|
||||||
import { extractTar } from "./tar";
|
|
||||||
import * as utils from "./utils/actionUtils";
|
import * as utils from "./utils/actionUtils";
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
// Validate inputs, this can cause task failure
|
// Validate inputs, this can cause task failure
|
||||||
if (!utils.isValidEvent()) {
|
if (!utils.isValidEvent()) {
|
||||||
utils.logWarning(
|
core.setFailed(
|
||||||
`Event Validation Error: The event type ${
|
`Event Validation Error: The event type ${
|
||||||
process.env[Events.Key]
|
process.env[Events.Key]
|
||||||
} is not supported. Only ${utils
|
} is not supported. Only ${utils
|
||||||
.getSupportedEvents()
|
.getSupportedEvents()
|
||||||
.join(", ")} events are supported at this time.`
|
.join(", ")} events are supported at this time.`
|
||||||
);
|
);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const cachePath = utils.resolvePath(
|
const cachePath = utils.resolvePath(
|
||||||
@ -86,7 +86,27 @@ async function run(): Promise<void> {
|
|||||||
)} MB (${archiveFileSize} B)`
|
)} MB (${archiveFileSize} B)`
|
||||||
);
|
);
|
||||||
|
|
||||||
await extractTar(archivePath, cachePath);
|
// Create directory to extract tar into
|
||||||
|
await io.mkdirP(cachePath);
|
||||||
|
|
||||||
|
// 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
|
||||||
|
? [
|
||||||
|
"-xz",
|
||||||
|
"--force-local",
|
||||||
|
"-f",
|
||||||
|
archivePath.replace(/\\/g, "/"),
|
||||||
|
"-C",
|
||||||
|
cachePath.replace(/\\/g, "/")
|
||||||
|
]
|
||||||
|
: ["-xz", "-f", archivePath, "-C", cachePath];
|
||||||
|
|
||||||
|
const tarPath = await io.which("tar", true);
|
||||||
|
core.debug(`Tar Path: ${tarPath}`);
|
||||||
|
|
||||||
|
await exec(`"${tarPath}"`, args);
|
||||||
|
|
||||||
const isExactKeyMatch = utils.isExactKeyMatch(
|
const isExactKeyMatch = utils.isExactKeyMatch(
|
||||||
primaryKey,
|
primaryKey,
|
||||||
@ -98,7 +118,7 @@ async function run(): Promise<void> {
|
|||||||
`Cache restored from key: ${cacheEntry && cacheEntry.cacheKey}`
|
`Cache restored from key: ${cacheEntry && cacheEntry.cacheKey}`
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
utils.logWarning(error.message);
|
core.warning(error.message);
|
||||||
utils.setCacheHitOutput(false);
|
utils.setCacheHitOutput(false);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
41
src/save.ts
41
src/save.ts
@ -1,29 +1,19 @@
|
|||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
|
import { exec } from "@actions/exec";
|
||||||
|
import * as io from "@actions/io";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import * as cacheHttpClient from "./cacheHttpClient";
|
import * as cacheHttpClient from "./cacheHttpClient";
|
||||||
import { Events, Inputs, State } from "./constants";
|
import { Inputs, State } from "./constants";
|
||||||
import { createTar } from "./tar";
|
|
||||||
import * as utils from "./utils/actionUtils";
|
import * as utils from "./utils/actionUtils";
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
if (!utils.isValidEvent()) {
|
|
||||||
utils.logWarning(
|
|
||||||
`Event Validation Error: The event type ${
|
|
||||||
process.env[Events.Key]
|
|
||||||
} is not supported. Only ${utils
|
|
||||||
.getSupportedEvents()
|
|
||||||
.join(", ")} events are supported at this time.`
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const state = utils.getCacheState();
|
const state = utils.getCacheState();
|
||||||
|
|
||||||
// Inputs are re-evaluted before the post action, so we want the original key used for restore
|
// Inputs are re-evaluted before the post action, so we want the original key used for restore
|
||||||
const primaryKey = core.getState(State.CacheKey);
|
const primaryKey = core.getState(State.CacheKey);
|
||||||
if (!primaryKey) {
|
if (!primaryKey) {
|
||||||
utils.logWarning(`Error retrieving key from state.`);
|
core.warning(`Error retrieving key from state.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,13 +35,30 @@ async function run(): Promise<void> {
|
|||||||
);
|
);
|
||||||
core.debug(`Archive Path: ${archivePath}`);
|
core.debug(`Archive Path: ${archivePath}`);
|
||||||
|
|
||||||
await createTar(archivePath, cachePath);
|
// 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, "."];
|
||||||
|
|
||||||
|
const tarPath = await io.which("tar", true);
|
||||||
|
core.debug(`Tar Path: ${tarPath}`);
|
||||||
|
await exec(`"${tarPath}"`, args);
|
||||||
|
|
||||||
const fileSizeLimit = 400 * 1024 * 1024; // 400MB
|
const fileSizeLimit = 400 * 1024 * 1024; // 400MB
|
||||||
const archiveFileSize = utils.getArchiveFileSize(archivePath);
|
const archiveFileSize = utils.getArchiveFileSize(archivePath);
|
||||||
core.debug(`File Size: ${archiveFileSize}`);
|
core.debug(`File Size: ${archiveFileSize}`);
|
||||||
if (archiveFileSize > fileSizeLimit) {
|
if (archiveFileSize > fileSizeLimit) {
|
||||||
utils.logWarning(
|
core.warning(
|
||||||
`Cache size of ~${Math.round(
|
`Cache size of ~${Math.round(
|
||||||
archiveFileSize / (1024 * 1024)
|
archiveFileSize / (1024 * 1024)
|
||||||
)} MB (${archiveFileSize} B) is over the 400MB limit, not saving cache.`
|
)} MB (${archiveFileSize} B) is over the 400MB limit, not saving cache.`
|
||||||
@ -61,7 +68,7 @@ async function run(): Promise<void> {
|
|||||||
|
|
||||||
await cacheHttpClient.saveCache(primaryKey, archivePath);
|
await cacheHttpClient.saveCache(primaryKey, archivePath);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
utils.logWarning(error.message);
|
core.warning(error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
33
src/tar.ts
33
src/tar.ts
@ -1,33 +0,0 @@
|
|||||||
import { exec } from "@actions/exec";
|
|
||||||
import * as io from "@actions/io";
|
|
||||||
|
|
||||||
async function getTarPath(): Promise<string> {
|
|
||||||
// Explicitly use BSD Tar on Windows
|
|
||||||
const IS_WINDOWS = process.platform === "win32";
|
|
||||||
return IS_WINDOWS
|
|
||||||
? `${process.env["windir"]}\\System32\\tar.exe`
|
|
||||||
: await io.which("tar", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function extractTar(
|
|
||||||
archivePath: string,
|
|
||||||
targetDirectory: string
|
|
||||||
): Promise<void> {
|
|
||||||
// Create directory to extract tar into
|
|
||||||
await io.mkdirP(targetDirectory);
|
|
||||||
|
|
||||||
// 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 args = ["-xz", "-f", archivePath, "-C", targetDirectory];
|
|
||||||
await exec(`"${await getTarPath()}"`, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function createTar(
|
|
||||||
archivePath: string,
|
|
||||||
sourceDirectory: string
|
|
||||||
): Promise<void> {
|
|
||||||
// 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 args = ["-cz", "-f", archivePath, "-C", sourceDirectory, "."];
|
|
||||||
await exec(`"${await getTarPath()}"`, args);
|
|
||||||
}
|
|
@ -77,11 +77,6 @@ export function getCacheState(): ArtifactCacheEntry | undefined {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function logWarning(message: string): void {
|
|
||||||
const warningPrefix = "[warning]";
|
|
||||||
core.info(`${warningPrefix}${message}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function resolvePath(filePath: string): string {
|
export function resolvePath(filePath: string): string {
|
||||||
if (filePath[0] === "~") {
|
if (filePath[0] === "~") {
|
||||||
const home = os.homedir();
|
const home = os.homedir();
|
||||||
|
Reference in New Issue
Block a user