mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-04-20 03:46:17 +02:00
Merge master into ethanis/cache-multiple-paths
This commit is contained in:
commit
f68f5d03cc
15 changed files with 3437 additions and 602 deletions
|
@ -12,5 +12,12 @@
|
||||||
"plugin:prettier/recommended",
|
"plugin:prettier/recommended",
|
||||||
"prettier/@typescript-eslint"
|
"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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ Using the `cache-hit` output, subsequent steps (such as install or build) can be
|
||||||
Example:
|
Example:
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- uses: actions/cache@v1
|
- uses: actions/cache@v1
|
||||||
id: cache
|
id: cache
|
||||||
|
|
|
@ -341,3 +341,15 @@ test("isValidEvent returns true for pull request event", () => {
|
||||||
|
|
||||||
expect(isValidEvent).toBe(true);
|
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);
|
||||||
|
});
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
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";
|
||||||
|
@ -236,6 +237,7 @@ test("restore with cache found", async () => {
|
||||||
.mockReturnValue(fileSize);
|
.mockReturnValue(fileSize);
|
||||||
|
|
||||||
const extractTarMock = jest.spyOn(tar, "extractTar");
|
const extractTarMock = jest.spyOn(tar, "extractTar");
|
||||||
|
const unlinkFileMock = jest.spyOn(actionUtils, "unlinkFile");
|
||||||
const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput");
|
const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput");
|
||||||
|
|
||||||
await run();
|
await run();
|
||||||
|
@ -253,6 +255,9 @@ test("restore with cache found", async () => {
|
||||||
expect(extractTarMock).toHaveBeenCalledTimes(1);
|
expect(extractTarMock).toHaveBeenCalledTimes(1);
|
||||||
expect(extractTarMock).toHaveBeenCalledWith(archivePath);
|
expect(extractTarMock).toHaveBeenCalledWith(archivePath);
|
||||||
|
|
||||||
|
expect(unlinkFileMock).toHaveBeenCalledTimes(1);
|
||||||
|
expect(unlinkFileMock).toHaveBeenCalledWith(archivePath);
|
||||||
|
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith(true);
|
expect(setCacheHitOutputMock).toHaveBeenCalledWith(true);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
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, CacheFilename } from "../src/constants";
|
import { Events, Inputs, CacheFilename } from "../src/constants";
|
||||||
import { ArtifactCacheEntry } from "../src/contracts";
|
import { ArtifactCacheEntry } from "../src/contracts";
|
||||||
|
|
|
@ -2,6 +2,7 @@ import * as exec from "@actions/exec";
|
||||||
import * as io from "@actions/io";
|
import * as io from "@actions/io";
|
||||||
import { promises as fs } from "fs";
|
import { promises as fs } from "fs";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
|
|
||||||
import * as tar from "../src/tar";
|
import * as tar from "../src/tar";
|
||||||
import { CacheFilename } from "../src/constants";
|
import { CacheFilename } from "../src/constants";
|
||||||
|
|
||||||
|
|
23
dist/restore/index.js
vendored
23
dist/restore/index.js
vendored
|
@ -2184,8 +2184,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const core = __importStar(__webpack_require__(470));
|
const core = __importStar(__webpack_require__(470));
|
||||||
const fs = __importStar(__webpack_require__(747));
|
const fs = __importStar(__webpack_require__(747));
|
||||||
const crypto = __importStar(__webpack_require__(417));
|
const crypto = __importStar(__webpack_require__(417));
|
||||||
const auth_1 = __webpack_require__(226);
|
|
||||||
const http_client_1 = __webpack_require__(539);
|
const http_client_1 = __webpack_require__(539);
|
||||||
|
const auth_1 = __webpack_require__(226);
|
||||||
const utils = __importStar(__webpack_require__(443));
|
const utils = __importStar(__webpack_require__(443));
|
||||||
const constants_1 = __webpack_require__(694);
|
const constants_1 = __webpack_require__(694);
|
||||||
const versionSalt = "1.0";
|
const versionSalt = "1.0";
|
||||||
|
@ -3189,6 +3189,7 @@ const io = __importStar(__webpack_require__(1));
|
||||||
const glob = __importStar(__webpack_require__(281));
|
const glob = __importStar(__webpack_require__(281));
|
||||||
const fs = __importStar(__webpack_require__(747));
|
const fs = __importStar(__webpack_require__(747));
|
||||||
const path = __importStar(__webpack_require__(622));
|
const path = __importStar(__webpack_require__(622));
|
||||||
|
const util = __importStar(__webpack_require__(669));
|
||||||
const uuidV4 = __importStar(__webpack_require__(826));
|
const uuidV4 = __importStar(__webpack_require__(826));
|
||||||
const constants_1 = __webpack_require__(694);
|
const constants_1 = __webpack_require__(694);
|
||||||
// From https://github.com/actions/toolkit/blob/master/packages/tool-cache/src/tool-cache.ts#L23
|
// 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);
|
return getSupportedEvents().includes(githubEvent);
|
||||||
}
|
}
|
||||||
exports.isValidEvent = isValidEvent;
|
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}`);
|
core.debug(`Archive Path: ${archivePath}`);
|
||||||
// Store the cache result
|
// Store the cache result
|
||||||
utils.setCacheState(cacheEntry);
|
utils.setCacheState(cacheEntry);
|
||||||
|
try {
|
||||||
// Download the cache from the cache entry
|
// Download the cache from the cache entry
|
||||||
yield cacheHttpClient.downloadCache(cacheEntry.archiveLocation, archivePath);
|
yield cacheHttpClient.downloadCache(cacheEntry.archiveLocation, 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);
|
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);
|
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}`);
|
||||||
|
@ -4943,11 +4959,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const exec_1 = __webpack_require__(986);
|
||||||
const io = __importStar(__webpack_require__(1));
|
const io = __importStar(__webpack_require__(1));
|
||||||
|
const fs_1 = __webpack_require__(747);
|
||||||
const path = __importStar(__webpack_require__(622));
|
const path = __importStar(__webpack_require__(622));
|
||||||
const constants_1 = __webpack_require__(694);
|
const constants_1 = __webpack_require__(694);
|
||||||
const exec_1 = __webpack_require__(986);
|
|
||||||
const fs_1 = __webpack_require__(747);
|
|
||||||
function getTarPath() {
|
function getTarPath() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
// Explicitly use BSD Tar on Windows
|
// Explicitly use BSD Tar on Windows
|
||||||
|
@ -4968,7 +4984,6 @@ function execTar(args, cwd) {
|
||||||
yield exec_1.exec(`"${yield getTarPath()}"`, args, { cwd: cwd });
|
yield exec_1.exec(`"${yield getTarPath()}"`, args, { cwd: cwd });
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.log("error", error);
|
|
||||||
const IS_WINDOWS = process.platform === "win32";
|
const IS_WINDOWS = process.platform === "win32";
|
||||||
if (IS_WINDOWS) {
|
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.`);
|
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
12
dist/save/index.js
vendored
|
@ -2184,8 +2184,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const core = __importStar(__webpack_require__(470));
|
const core = __importStar(__webpack_require__(470));
|
||||||
const fs = __importStar(__webpack_require__(747));
|
const fs = __importStar(__webpack_require__(747));
|
||||||
const crypto = __importStar(__webpack_require__(417));
|
const crypto = __importStar(__webpack_require__(417));
|
||||||
const auth_1 = __webpack_require__(226);
|
|
||||||
const http_client_1 = __webpack_require__(539);
|
const http_client_1 = __webpack_require__(539);
|
||||||
|
const auth_1 = __webpack_require__(226);
|
||||||
const utils = __importStar(__webpack_require__(443));
|
const utils = __importStar(__webpack_require__(443));
|
||||||
const constants_1 = __webpack_require__(694);
|
const constants_1 = __webpack_require__(694);
|
||||||
const versionSalt = "1.0";
|
const versionSalt = "1.0";
|
||||||
|
@ -3189,6 +3189,7 @@ const io = __importStar(__webpack_require__(1));
|
||||||
const glob = __importStar(__webpack_require__(281));
|
const glob = __importStar(__webpack_require__(281));
|
||||||
const fs = __importStar(__webpack_require__(747));
|
const fs = __importStar(__webpack_require__(747));
|
||||||
const path = __importStar(__webpack_require__(622));
|
const path = __importStar(__webpack_require__(622));
|
||||||
|
const util = __importStar(__webpack_require__(669));
|
||||||
const uuidV4 = __importStar(__webpack_require__(826));
|
const uuidV4 = __importStar(__webpack_require__(826));
|
||||||
const constants_1 = __webpack_require__(694);
|
const constants_1 = __webpack_require__(694);
|
||||||
// From https://github.com/actions/toolkit/blob/master/packages/tool-cache/src/tool-cache.ts#L23
|
// 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);
|
return getSupportedEvents().includes(githubEvent);
|
||||||
}
|
}
|
||||||
exports.isValidEvent = isValidEvent;
|
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;
|
return result;
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const exec_1 = __webpack_require__(986);
|
||||||
const io = __importStar(__webpack_require__(1));
|
const io = __importStar(__webpack_require__(1));
|
||||||
|
const fs_1 = __webpack_require__(747);
|
||||||
const path = __importStar(__webpack_require__(622));
|
const path = __importStar(__webpack_require__(622));
|
||||||
const constants_1 = __webpack_require__(694);
|
const constants_1 = __webpack_require__(694);
|
||||||
const exec_1 = __webpack_require__(986);
|
|
||||||
const fs_1 = __webpack_require__(747);
|
|
||||||
function getTarPath() {
|
function getTarPath() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
// Explicitly use BSD Tar on Windows
|
// Explicitly use BSD Tar on Windows
|
||||||
|
@ -4956,7 +4961,6 @@ function execTar(args, cwd) {
|
||||||
yield exec_1.exec(`"${yield getTarPath()}"`, args, { cwd: cwd });
|
yield exec_1.exec(`"${yield getTarPath()}"`, args, { cwd: cwd });
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.log("error", error);
|
|
||||||
const IS_WINDOWS = process.platform === "win32";
|
const IS_WINDOWS = process.platform === "win32";
|
||||||
if (IS_WINDOWS) {
|
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.`);
|
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.`);
|
||||||
|
|
|
@ -104,7 +104,7 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
|
||||||
- uses: actions/cache@v1
|
- uses: actions/cache@v1
|
||||||
with:
|
with:
|
||||||
path: ~/.gradle/caches
|
path: ~/.gradle/caches
|
||||||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
|
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-gradle-
|
${{ runner.os }}-gradle-
|
||||||
```
|
```
|
||||||
|
|
3918
package-lock.json
generated
3918
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -43,6 +43,7 @@
|
||||||
"eslint-plugin-import": "^2.18.2",
|
"eslint-plugin-import": "^2.18.2",
|
||||||
"eslint-plugin-jest": "^23.0.3",
|
"eslint-plugin-jest": "^23.0.3",
|
||||||
"eslint-plugin-prettier": "^3.1.1",
|
"eslint-plugin-prettier": "^3.1.1",
|
||||||
|
"eslint-plugin-simple-import-sort": "^5.0.2",
|
||||||
"jest": "^24.8.0",
|
"jest": "^24.8.0",
|
||||||
"jest-circus": "^24.7.1",
|
"jest-circus": "^24.7.1",
|
||||||
"nock": "^11.7.0",
|
"nock": "^11.7.0",
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import * as crypto from "crypto";
|
import * as crypto from "crypto";
|
||||||
import { BearerCredentialHandler } from "@actions/http-client/auth";
|
|
||||||
import { HttpClient, HttpCodes } from "@actions/http-client";
|
import { HttpClient, HttpCodes } from "@actions/http-client";
|
||||||
|
import { BearerCredentialHandler } from "@actions/http-client/auth";
|
||||||
import {
|
import {
|
||||||
IHttpClientResponse,
|
IHttpClientResponse,
|
||||||
IRequestOptions,
|
IRequestOptions,
|
||||||
ITypedResponse
|
ITypedResponse
|
||||||
} from "@actions/http-client/interfaces";
|
} from "@actions/http-client/interfaces";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ArtifactCacheEntry,
|
ArtifactCacheEntry,
|
||||||
CommitCacheRequest,
|
CommitCacheRequest,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
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 { extractTar } from "./tar";
|
||||||
|
@ -69,6 +70,7 @@ async function run(): Promise<void> {
|
||||||
// Store the cache result
|
// Store the cache result
|
||||||
utils.setCacheState(cacheEntry);
|
utils.setCacheState(cacheEntry);
|
||||||
|
|
||||||
|
try {
|
||||||
// Download the cache from the cache entry
|
// Download the cache from the cache entry
|
||||||
await cacheHttpClient.downloadCache(
|
await cacheHttpClient.downloadCache(
|
||||||
cacheEntry.archiveLocation,
|
cacheEntry.archiveLocation,
|
||||||
|
@ -83,6 +85,14 @@ async function run(): Promise<void> {
|
||||||
);
|
);
|
||||||
|
|
||||||
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(
|
const isExactKeyMatch = utils.isExactKeyMatch(
|
||||||
primaryKey,
|
primaryKey,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
|
|
||||||
import * as cacheHttpClient from "./cacheHttpClient";
|
import * as cacheHttpClient from "./cacheHttpClient";
|
||||||
import { Events, Inputs, State, CacheFilename } from "./constants";
|
import { Events, Inputs, State, CacheFilename } from "./constants";
|
||||||
import { createTar } from "./tar";
|
import { createTar } from "./tar";
|
||||||
|
|
|
@ -4,6 +4,7 @@ import * as glob from "@actions/glob";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import * as os from "os";
|
import * as os from "os";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
|
import * as util from "util";
|
||||||
import * as uuidV4 from "uuid/v4";
|
import * as uuidV4 from "uuid/v4";
|
||||||
|
|
||||||
import { Events, Outputs, State } from "../constants";
|
import { Events, Outputs, State } from "../constants";
|
||||||
|
@ -112,3 +113,7 @@ export function isValidEvent(): boolean {
|
||||||
const githubEvent = process.env[Events.Key] || "";
|
const githubEvent = process.env[Events.Key] || "";
|
||||||
return getSupportedEvents().includes(githubEvent);
|
return getSupportedEvents().includes(githubEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function unlinkFile(path: fs.PathLike): Promise<void> {
|
||||||
|
return util.promisify(fs.unlink)(path);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue