1
0
Fork 0
mirror of https://code.forgejo.org/actions/cache.git synced 2025-04-19 19:46:17 +02:00

Merge master into ethanis/cache-multiple-paths

This commit is contained in:
Ethan Dennis 2020-03-18 17:35:59 -07:00
commit f68f5d03cc
No known key found for this signature in database
GPG key ID: 32E74B75DB4065DD
15 changed files with 3437 additions and 602 deletions

View file

@ -12,5 +12,12 @@
"plugin:prettier/recommended",
"prettier/@typescript-eslint"
],
"plugins": ["@typescript-eslint", "jest"]
"plugins": ["@typescript-eslint", "simple-import-sort", "jest"],
"rules": {
"import/first": "error",
"import/newline-after-import": "error",
"import/no-duplicates": "error",
"simple-import-sort/sort": "error",
"sort-imports": "off"
}
}

View file

@ -90,7 +90,7 @@ Using the `cache-hit` output, subsequent steps (such as install or build) can be
Example:
```yaml
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- uses: actions/cache@v1
id: cache

View file

@ -341,3 +341,15 @@ test("isValidEvent returns true for pull request event", () => {
expect(isValidEvent).toBe(true);
});
test("unlinkFile unlinks file", async () => {
const testDirectory = fs.mkdtempSync("unlinkFileTest");
const testFile = path.join(testDirectory, "test.txt");
fs.writeFileSync(testFile, "hello world");
await actionUtils.unlinkFile(testFile);
expect(fs.existsSync(testFile)).toBe(false);
fs.rmdirSync(testDirectory);
});

View file

@ -1,5 +1,6 @@
import * as core from "@actions/core";
import * as path from "path";
import * as cacheHttpClient from "../src/cacheHttpClient";
import { Events, Inputs } from "../src/constants";
import { ArtifactCacheEntry } from "../src/contracts";
@ -236,6 +237,7 @@ test("restore with cache found", async () => {
.mockReturnValue(fileSize);
const extractTarMock = jest.spyOn(tar, "extractTar");
const unlinkFileMock = jest.spyOn(actionUtils, "unlinkFile");
const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput");
await run();
@ -253,6 +255,9 @@ test("restore with cache found", async () => {
expect(extractTarMock).toHaveBeenCalledTimes(1);
expect(extractTarMock).toHaveBeenCalledWith(archivePath);
expect(unlinkFileMock).toHaveBeenCalledTimes(1);
expect(unlinkFileMock).toHaveBeenCalledWith(archivePath);
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
expect(setCacheHitOutputMock).toHaveBeenCalledWith(true);

View file

@ -1,5 +1,6 @@
import * as core from "@actions/core";
import * as path from "path";
import * as cacheHttpClient from "../src/cacheHttpClient";
import { Events, Inputs, CacheFilename } from "../src/constants";
import { ArtifactCacheEntry } from "../src/contracts";

View file

@ -2,6 +2,7 @@ import * as exec from "@actions/exec";
import * as io from "@actions/io";
import { promises as fs } from "fs";
import * as path from "path";
import * as tar from "../src/tar";
import { CacheFilename } from "../src/constants";

33
dist/restore/index.js vendored
View file

@ -2184,8 +2184,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(__webpack_require__(470));
const fs = __importStar(__webpack_require__(747));
const crypto = __importStar(__webpack_require__(417));
const auth_1 = __webpack_require__(226);
const http_client_1 = __webpack_require__(539);
const auth_1 = __webpack_require__(226);
const utils = __importStar(__webpack_require__(443));
const constants_1 = __webpack_require__(694);
const versionSalt = "1.0";
@ -3189,6 +3189,7 @@ const io = __importStar(__webpack_require__(1));
const glob = __importStar(__webpack_require__(281));
const fs = __importStar(__webpack_require__(747));
const path = __importStar(__webpack_require__(622));
const util = __importStar(__webpack_require__(669));
const uuidV4 = __importStar(__webpack_require__(826));
const constants_1 = __webpack_require__(694);
// From https://github.com/actions/toolkit/blob/master/packages/tool-cache/src/tool-cache.ts#L23
@ -3299,6 +3300,10 @@ function isValidEvent() {
return getSupportedEvents().includes(githubEvent);
}
exports.isValidEvent = isValidEvent;
function unlinkFile(path) {
return util.promisify(fs.unlink)(path);
}
exports.unlinkFile = unlinkFile;
/***/ }),
@ -4595,11 +4600,22 @@ function run() {
core.debug(`Archive Path: ${archivePath}`);
// Store the cache result
utils.setCacheState(cacheEntry);
// Download the cache from the cache entry
yield cacheHttpClient.downloadCache(cacheEntry.archiveLocation, archivePath);
const archiveFileSize = utils.getArchiveFileSize(archivePath);
core.info(`Cache Size: ~${Math.round(archiveFileSize / (1024 * 1024))} MB (${archiveFileSize} B)`);
yield tar_1.extractTar(archivePath);
try {
// Download the cache from the cache entry
yield cacheHttpClient.downloadCache(cacheEntry.archiveLocation, archivePath);
const archiveFileSize = utils.getArchiveFileSize(archivePath);
core.info(`Cache Size: ~${Math.round(archiveFileSize / (1024 * 1024))} MB (${archiveFileSize} B)`);
yield tar_1.extractTar(archivePath);
}
finally {
// Try to delete the archive to save space
try {
yield utils.unlinkFile(archivePath);
}
catch (error) {
core.debug(`Failed to delete archive: ${error}`);
}
}
const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheEntry);
utils.setCacheHitOutput(isExactKeyMatch);
core.info(`Cache restored from key: ${cacheEntry && cacheEntry.cacheKey}`);
@ -4943,11 +4959,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const exec_1 = __webpack_require__(986);
const io = __importStar(__webpack_require__(1));
const fs_1 = __webpack_require__(747);
const path = __importStar(__webpack_require__(622));
const constants_1 = __webpack_require__(694);
const exec_1 = __webpack_require__(986);
const fs_1 = __webpack_require__(747);
function getTarPath() {
return __awaiter(this, void 0, void 0, function* () {
// Explicitly use BSD Tar on Windows
@ -4968,7 +4984,6 @@ function execTar(args, cwd) {
yield exec_1.exec(`"${yield getTarPath()}"`, args, { cwd: cwd });
}
catch (error) {
console.log("error", error);
const IS_WINDOWS = process.platform === "win32";
if (IS_WINDOWS) {
throw new Error(`Tar failed with error: ${(_a = error) === null || _a === void 0 ? void 0 : _a.message}. Ensure BSD tar is installed and on the PATH.`);

12
dist/save/index.js vendored
View file

@ -2184,8 +2184,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(__webpack_require__(470));
const fs = __importStar(__webpack_require__(747));
const crypto = __importStar(__webpack_require__(417));
const auth_1 = __webpack_require__(226);
const http_client_1 = __webpack_require__(539);
const auth_1 = __webpack_require__(226);
const utils = __importStar(__webpack_require__(443));
const constants_1 = __webpack_require__(694);
const versionSalt = "1.0";
@ -3189,6 +3189,7 @@ const io = __importStar(__webpack_require__(1));
const glob = __importStar(__webpack_require__(281));
const fs = __importStar(__webpack_require__(747));
const path = __importStar(__webpack_require__(622));
const util = __importStar(__webpack_require__(669));
const uuidV4 = __importStar(__webpack_require__(826));
const constants_1 = __webpack_require__(694);
// From https://github.com/actions/toolkit/blob/master/packages/tool-cache/src/tool-cache.ts#L23
@ -3299,6 +3300,10 @@ function isValidEvent() {
return getSupportedEvents().includes(githubEvent);
}
exports.isValidEvent = isValidEvent;
function unlinkFile(path) {
return util.promisify(fs.unlink)(path);
}
exports.unlinkFile = unlinkFile;
/***/ }),
@ -4931,11 +4936,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const exec_1 = __webpack_require__(986);
const io = __importStar(__webpack_require__(1));
const fs_1 = __webpack_require__(747);
const path = __importStar(__webpack_require__(622));
const constants_1 = __webpack_require__(694);
const exec_1 = __webpack_require__(986);
const fs_1 = __webpack_require__(747);
function getTarPath() {
return __awaiter(this, void 0, void 0, function* () {
// Explicitly use BSD Tar on Windows
@ -4956,7 +4961,6 @@ function execTar(args, cwd) {
yield exec_1.exec(`"${yield getTarPath()}"`, args, { cwd: cwd });
}
catch (error) {
console.log("error", error);
const IS_WINDOWS = process.platform === "win32";
if (IS_WINDOWS) {
throw new Error(`Tar failed with error: ${(_a = error) === null || _a === void 0 ? void 0 : _a.message}. Ensure BSD tar is installed and on the PATH.`);

View file

@ -104,7 +104,7 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
- uses: actions/cache@v1
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-
```

3918
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -43,6 +43,7 @@
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jest": "^23.0.3",
"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-simple-import-sort": "^5.0.2",
"jest": "^24.8.0",
"jest-circus": "^24.7.1",
"nock": "^11.7.0",

View file

@ -1,13 +1,14 @@
import * as core from "@actions/core";
import * as fs from "fs";
import * as crypto from "crypto";
import { BearerCredentialHandler } from "@actions/http-client/auth";
import { HttpClient, HttpCodes } from "@actions/http-client";
import { BearerCredentialHandler } from "@actions/http-client/auth";
import {
IHttpClientResponse,
IRequestOptions,
ITypedResponse
} from "@actions/http-client/interfaces";
import {
ArtifactCacheEntry,
CommitCacheRequest,

View file

@ -1,5 +1,6 @@
import * as core from "@actions/core";
import * as path from "path";
import * as cacheHttpClient from "./cacheHttpClient";
import { Events, Inputs, State } from "./constants";
import { extractTar } from "./tar";
@ -69,20 +70,29 @@ async function run(): Promise<void> {
// Store the cache result
utils.setCacheState(cacheEntry);
// Download the cache from the cache entry
await cacheHttpClient.downloadCache(
cacheEntry.archiveLocation,
archivePath
);
try {
// Download the cache from the cache entry
await cacheHttpClient.downloadCache(
cacheEntry.archiveLocation,
archivePath
);
const archiveFileSize = utils.getArchiveFileSize(archivePath);
core.info(
`Cache Size: ~${Math.round(
archiveFileSize / (1024 * 1024)
)} MB (${archiveFileSize} B)`
);
const archiveFileSize = utils.getArchiveFileSize(archivePath);
core.info(
`Cache Size: ~${Math.round(
archiveFileSize / (1024 * 1024)
)} MB (${archiveFileSize} B)`
);
await extractTar(archivePath);
await extractTar(archivePath);
} finally {
// Try to delete the archive to save space
try {
await utils.unlinkFile(archivePath);
} catch (error) {
core.debug(`Failed to delete archive: ${error}`);
}
}
const isExactKeyMatch = utils.isExactKeyMatch(
primaryKey,

View file

@ -1,5 +1,6 @@
import * as core from "@actions/core";
import * as path from "path";
import * as cacheHttpClient from "./cacheHttpClient";
import { Events, Inputs, State, CacheFilename } from "./constants";
import { createTar } from "./tar";

View file

@ -4,6 +4,7 @@ import * as glob from "@actions/glob";
import * as fs from "fs";
import * as os from "os";
import * as path from "path";
import * as util from "util";
import * as uuidV4 from "uuid/v4";
import { Events, Outputs, State } from "../constants";
@ -112,3 +113,7 @@ export function isValidEvent(): boolean {
const githubEvent = process.env[Events.Key] || "";
return getSupportedEvents().includes(githubEvent);
}
export function unlinkFile(path: fs.PathLike): Promise<void> {
return util.promisify(fs.unlink)(path);
}