mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-04-20 03:46:17 +02:00
Cache multiple entries using --files-from tar input
remove known failing test Quote tar paths Add salt to test cache Try reading input files from manifest bump salt Run test on macos more testing Run caching tests on 3 platforms Run tests on self-hosted Apparently cant reference hosted runners by name Bump salt wait for some time after save more timing out smarter waiting Cache in tmp dir that won't be deleted Use child_process instead of actions/exec Revert tempDir hack bump salt more logging More console logging Use filepath to with cacheHttpClient Test cache restoration Revert temp dir hack debug logging clean up cache.yml testing Bump salt change debug output build actions
This commit is contained in:
parent
db235cfc56
commit
e0d1942524
11 changed files with 157 additions and 80 deletions
17
.github/workflows/cache.yml
vendored
17
.github/workflows/cache.yml
vendored
|
@ -6,7 +6,6 @@ on:
|
||||||
- master
|
- master
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# Build and unit test
|
|
||||||
build:
|
build:
|
||||||
runs-on: self-hosted
|
runs-on: self-hosted
|
||||||
steps:
|
steps:
|
||||||
|
@ -16,19 +15,15 @@ jobs:
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: '12.x'
|
node-version: '12.x'
|
||||||
- run: npm install
|
|
||||||
- run: npm run build
|
|
||||||
- name: Restore npm cache
|
- name: Restore npm cache
|
||||||
uses: ./
|
uses: ./
|
||||||
|
id: cache
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
node_modules
|
node_modules
|
||||||
dist
|
dist
|
||||||
~/Desktop/cache-me
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('salt.txt') }}
|
||||||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
- run: npm install
|
||||||
- name: Prettier Format Check
|
if: steps.cache.outputs.cache-hit != 'true'
|
||||||
run: npm run format-check
|
- run: npm run build
|
||||||
- name: ESLint Check
|
if: steps.cache.outputs.cache-hit != 'true'
|
||||||
run: npm run lint
|
|
||||||
- name: Build & Test
|
|
||||||
run: npm run test
|
|
10
.github/workflows/workflow.yml
vendored
10
.github/workflows/workflow.yml
vendored
|
@ -1,11 +1,11 @@
|
||||||
name: Tests
|
name: Tests
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
# pull_request:
|
||||||
branches:
|
# branches:
|
||||||
- master
|
# - master
|
||||||
paths-ignore:
|
# paths-ignore:
|
||||||
- '**.md'
|
# - '**.md'
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
|
import * as glob from "@actions/glob";
|
||||||
import * as os from "os";
|
import * as os from "os";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
|
|
||||||
|
@ -181,16 +182,17 @@ test("isValidEvent returns false for unknown event", () => {
|
||||||
expect(isValidEvent).toBe(false);
|
expect(isValidEvent).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("expandPaths with no ~ in path", () => {
|
test("resolvePaths with no ~ in path", async () => {
|
||||||
|
// TODO: these test paths will need to exist
|
||||||
const filePath = ".cache/yarn";
|
const filePath = ".cache/yarn";
|
||||||
|
|
||||||
const resolvedPath = actionUtils.expandPaths([filePath]);
|
const resolvedPath = await actionUtils.resolvePaths([filePath]);
|
||||||
|
|
||||||
const expectedPath = [path.resolve(filePath)];
|
const expectedPath = [path.resolve(filePath)];
|
||||||
expect(resolvedPath).toStrictEqual(expectedPath);
|
expect(resolvedPath).toStrictEqual(expectedPath);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("expandPaths with ~ in path", () => {
|
test("resolvePaths with ~ in path", async () => {
|
||||||
const filePath = "~/.cache/yarn";
|
const filePath = "~/.cache/yarn";
|
||||||
|
|
||||||
const homedir = jest.requireActual("os").homedir();
|
const homedir = jest.requireActual("os").homedir();
|
||||||
|
@ -199,20 +201,22 @@ test("expandPaths with ~ in path", () => {
|
||||||
return homedir;
|
return homedir;
|
||||||
});
|
});
|
||||||
|
|
||||||
const resolvedPath = actionUtils.expandPaths([filePath]);
|
const resolvedPath = await actionUtils.resolvePaths([filePath]);
|
||||||
|
|
||||||
const expectedPath = [path.join(homedir, ".cache/yarn")];
|
const expectedPath = [path.join(homedir, ".cache/yarn")];
|
||||||
expect(resolvedPath).toStrictEqual(expectedPath);
|
expect(resolvedPath).toStrictEqual(expectedPath);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("expandPaths with home not found", () => {
|
test("resolvePaths with home not found", () => {
|
||||||
const filePath = "~/.cache/yarn";
|
const filePath = "~/.cache/yarn";
|
||||||
const homedirMock = jest.spyOn(os, "homedir");
|
const homedirMock = jest.spyOn(os, "homedir");
|
||||||
homedirMock.mockImplementation(() => {
|
homedirMock.mockImplementation(() => {
|
||||||
return "";
|
return "";
|
||||||
});
|
});
|
||||||
|
// const globMock = jest.spyOn(glob, "homedir");
|
||||||
|
// globMock.mockImplementation(() => "");
|
||||||
|
|
||||||
expect(() => actionUtils.expandPaths([filePath])).toThrow(
|
expect(async () => await actionUtils.resolvePaths([filePath])).toThrow(
|
||||||
"Unable to resolve `~` to HOME"
|
"Unable to resolve `~` to HOME"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -40,7 +40,7 @@ beforeAll(() => {
|
||||||
return actualUtils.getSupportedEvents();
|
return actualUtils.getSupportedEvents();
|
||||||
});
|
});
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "expandPaths").mockImplementation(
|
jest.spyOn(actionUtils, "resolvePaths").mockImplementation(
|
||||||
async filePaths => {
|
async filePaths => {
|
||||||
return filePaths.map(x => path.resolve(x));
|
return filePaths.map(x => path.resolve(x));
|
||||||
}
|
}
|
||||||
|
|
62
dist/restore/index.js
vendored
62
dist/restore/index.js
vendored
|
@ -3151,6 +3151,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
||||||
|
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
||||||
|
var m = o[Symbol.asyncIterator], i;
|
||||||
|
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
||||||
|
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
||||||
|
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
||||||
|
};
|
||||||
var __importStar = (this && this.__importStar) || function (mod) {
|
var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
if (mod && mod.__esModule) return mod;
|
if (mod && mod.__esModule) return mod;
|
||||||
var result = {};
|
var result = {};
|
||||||
|
@ -3233,19 +3240,35 @@ function logWarning(message) {
|
||||||
core.info(`${warningPrefix}${message}`);
|
core.info(`${warningPrefix}${message}`);
|
||||||
}
|
}
|
||||||
exports.logWarning = logWarning;
|
exports.logWarning = logWarning;
|
||||||
function expandPaths(patterns) {
|
function resolvePaths(patterns) {
|
||||||
var _a;
|
var e_1, _a;
|
||||||
|
var _b;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const paths = [];
|
const paths = [];
|
||||||
const workspace = (_a = process.env["GITHUB_WORKSPACE"], (_a !== null && _a !== void 0 ? _a : process.cwd()));
|
const workspace = (_b = process.env["GITHUB_WORKSPACE"], (_b !== null && _b !== void 0 ? _b : process.cwd()));
|
||||||
const globber = yield glob.create(patterns.join("\n"));
|
const globber = yield glob.create(patterns.join("\n"), {
|
||||||
const files = yield globber.glob();
|
implicitDescendants: false
|
||||||
paths.push(...files);
|
});
|
||||||
// Convert paths to relative paths here?
|
try {
|
||||||
return paths.map(x => path.relative(workspace, x));
|
for (var _c = __asyncValues(globber.globGenerator()), _d; _d = yield _c.next(), !_d.done;) {
|
||||||
|
const file = _d.value;
|
||||||
|
const relativeFile = path.relative(workspace, file);
|
||||||
|
core.debug(`Matched: ${relativeFile}`);
|
||||||
|
// Paths are made relative so the tar entries are all relative to the root of the workspace.
|
||||||
|
paths.push(`${relativeFile}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
if (_d && !_d.done && (_a = _c.return)) yield _a.call(_c);
|
||||||
|
}
|
||||||
|
finally { if (e_1) throw e_1.error; }
|
||||||
|
}
|
||||||
|
return paths;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.expandPaths = expandPaths;
|
exports.resolvePaths = resolvePaths;
|
||||||
function getSupportedEvents() {
|
function getSupportedEvents() {
|
||||||
return [constants_1.Events.Push, constants_1.Events.PullRequest];
|
return [constants_1.Events.Push, constants_1.Events.PullRequest];
|
||||||
}
|
}
|
||||||
|
@ -4421,6 +4444,7 @@ var Events;
|
||||||
Events["Push"] = "push";
|
Events["Push"] = "push";
|
||||||
Events["PullRequest"] = "pull_request";
|
Events["PullRequest"] = "pull_request";
|
||||||
})(Events = exports.Events || (exports.Events = {}));
|
})(Events = exports.Events || (exports.Events = {}));
|
||||||
|
exports.CacheFilename = "cache.tgz";
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
@ -4901,8 +4925,10 @@ 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 path = __importStar(__webpack_require__(622));
|
||||||
|
const constants_1 = __webpack_require__(694);
|
||||||
|
const exec_1 = __webpack_require__(986);
|
||||||
const fs_1 = __webpack_require__(747);
|
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* () {
|
||||||
|
@ -4917,13 +4943,14 @@ function getTarPath() {
|
||||||
return yield io.which("tar", true);
|
return yield io.which("tar", true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function execTar(args) {
|
function execTar(args, cwd) {
|
||||||
var _a, _b;
|
var _a, _b;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
yield exec_1.exec(`"${yield getTarPath()}"`, args);
|
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.`);
|
||||||
|
@ -4946,19 +4973,22 @@ function extractTar(archivePath) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.extractTar = extractTar;
|
exports.extractTar = extractTar;
|
||||||
function createTar(archivePath, sourceDirectories) {
|
function createTar(archiveFolder, sourceDirectories) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
// TODO: will want to stream sourceDirectories into tar
|
// TODO: will want to stream sourceDirectories into tar
|
||||||
|
const manifestFilename = "manifest.txt";
|
||||||
|
fs_1.writeFileSync(path.join(archiveFolder, manifestFilename), sourceDirectories.join("\n"));
|
||||||
const workingDirectory = getWorkingDirectory();
|
const workingDirectory = getWorkingDirectory();
|
||||||
const args = [
|
const args = [
|
||||||
"-cz",
|
"-cz",
|
||||||
"-f",
|
"-f",
|
||||||
archivePath,
|
constants_1.CacheFilename,
|
||||||
"-C",
|
"-C",
|
||||||
workingDirectory,
|
workingDirectory,
|
||||||
sourceDirectories.join(" ")
|
"--files-from",
|
||||||
|
manifestFilename
|
||||||
];
|
];
|
||||||
yield execTar(args);
|
yield execTar(args, archiveFolder);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.createTar = createTar;
|
exports.createTar = createTar;
|
||||||
|
|
69
dist/save/index.js
vendored
69
dist/save/index.js
vendored
|
@ -3151,6 +3151,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
||||||
|
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
||||||
|
var m = o[Symbol.asyncIterator], i;
|
||||||
|
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
||||||
|
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
||||||
|
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
||||||
|
};
|
||||||
var __importStar = (this && this.__importStar) || function (mod) {
|
var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
if (mod && mod.__esModule) return mod;
|
if (mod && mod.__esModule) return mod;
|
||||||
var result = {};
|
var result = {};
|
||||||
|
@ -3233,19 +3240,35 @@ function logWarning(message) {
|
||||||
core.info(`${warningPrefix}${message}`);
|
core.info(`${warningPrefix}${message}`);
|
||||||
}
|
}
|
||||||
exports.logWarning = logWarning;
|
exports.logWarning = logWarning;
|
||||||
function expandPaths(patterns) {
|
function resolvePaths(patterns) {
|
||||||
var _a;
|
var e_1, _a;
|
||||||
|
var _b;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const paths = [];
|
const paths = [];
|
||||||
const workspace = (_a = process.env["GITHUB_WORKSPACE"], (_a !== null && _a !== void 0 ? _a : process.cwd()));
|
const workspace = (_b = process.env["GITHUB_WORKSPACE"], (_b !== null && _b !== void 0 ? _b : process.cwd()));
|
||||||
const globber = yield glob.create(patterns.join("\n"));
|
const globber = yield glob.create(patterns.join("\n"), {
|
||||||
const files = yield globber.glob();
|
implicitDescendants: false
|
||||||
paths.push(...files);
|
});
|
||||||
// Convert paths to relative paths here?
|
try {
|
||||||
return paths.map(x => path.relative(workspace, x));
|
for (var _c = __asyncValues(globber.globGenerator()), _d; _d = yield _c.next(), !_d.done;) {
|
||||||
|
const file = _d.value;
|
||||||
|
const relativeFile = path.relative(workspace, file);
|
||||||
|
core.debug(`Matched: ${relativeFile}`);
|
||||||
|
// Paths are made relative so the tar entries are all relative to the root of the workspace.
|
||||||
|
paths.push(`${relativeFile}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
if (_d && !_d.done && (_a = _c.return)) yield _a.call(_c);
|
||||||
|
}
|
||||||
|
finally { if (e_1) throw e_1.error; }
|
||||||
|
}
|
||||||
|
return paths;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.expandPaths = expandPaths;
|
exports.resolvePaths = resolvePaths;
|
||||||
function getSupportedEvents() {
|
function getSupportedEvents() {
|
||||||
return [constants_1.Events.Push, constants_1.Events.PullRequest];
|
return [constants_1.Events.Push, constants_1.Events.PullRequest];
|
||||||
}
|
}
|
||||||
|
@ -4449,15 +4472,16 @@ function run() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
core.debug(`Cache ID: ${cacheId}`);
|
core.debug(`Cache ID: ${cacheId}`);
|
||||||
const cachePaths = yield utils.expandPaths(core
|
const cachePaths = yield utils.resolvePaths(core
|
||||||
.getInput(constants_1.Inputs.Path)
|
.getInput(constants_1.Inputs.Path)
|
||||||
.split("\n")
|
.split("\n")
|
||||||
.filter(x => x !== ""));
|
.filter(x => x !== ""));
|
||||||
core.debug("Cache Paths:");
|
core.debug("Cache Paths:");
|
||||||
core.debug(`${JSON.stringify(cachePaths)}`);
|
core.debug(`${JSON.stringify(cachePaths)}`);
|
||||||
const archivePath = path.join(yield utils.createTempDirectory(), "cache.tgz");
|
const archiveFolder = yield utils.createTempDirectory();
|
||||||
|
const archivePath = path.join(archiveFolder, constants_1.CacheFilename);
|
||||||
core.debug(`Archive Path: ${archivePath}`);
|
core.debug(`Archive Path: ${archivePath}`);
|
||||||
yield tar_1.createTar(archivePath, cachePaths);
|
yield tar_1.createTar(archiveFolder, cachePaths);
|
||||||
const fileSizeLimit = 5 * 1024 * 1024 * 1024; // 5GB per repo limit
|
const fileSizeLimit = 5 * 1024 * 1024 * 1024; // 5GB per repo limit
|
||||||
const archiveFileSize = utils.getArchiveFileSize(archivePath);
|
const archiveFileSize = utils.getArchiveFileSize(archivePath);
|
||||||
core.debug(`File Size: ${archiveFileSize}`);
|
core.debug(`File Size: ${archiveFileSize}`);
|
||||||
|
@ -4506,6 +4530,7 @@ var Events;
|
||||||
Events["Push"] = "push";
|
Events["Push"] = "push";
|
||||||
Events["PullRequest"] = "pull_request";
|
Events["PullRequest"] = "pull_request";
|
||||||
})(Events = exports.Events || (exports.Events = {}));
|
})(Events = exports.Events || (exports.Events = {}));
|
||||||
|
exports.CacheFilename = "cache.tgz";
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
@ -4888,8 +4913,10 @@ 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 path = __importStar(__webpack_require__(622));
|
||||||
|
const constants_1 = __webpack_require__(694);
|
||||||
|
const exec_1 = __webpack_require__(986);
|
||||||
const fs_1 = __webpack_require__(747);
|
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* () {
|
||||||
|
@ -4904,13 +4931,14 @@ function getTarPath() {
|
||||||
return yield io.which("tar", true);
|
return yield io.which("tar", true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function execTar(args) {
|
function execTar(args, cwd) {
|
||||||
var _a, _b;
|
var _a, _b;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
yield exec_1.exec(`"${yield getTarPath()}"`, args);
|
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.`);
|
||||||
|
@ -4933,19 +4961,22 @@ function extractTar(archivePath) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.extractTar = extractTar;
|
exports.extractTar = extractTar;
|
||||||
function createTar(archivePath, sourceDirectories) {
|
function createTar(archiveFolder, sourceDirectories) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
// TODO: will want to stream sourceDirectories into tar
|
// TODO: will want to stream sourceDirectories into tar
|
||||||
|
const manifestFilename = "manifest.txt";
|
||||||
|
fs_1.writeFileSync(path.join(archiveFolder, manifestFilename), sourceDirectories.join("\n"));
|
||||||
const workingDirectory = getWorkingDirectory();
|
const workingDirectory = getWorkingDirectory();
|
||||||
const args = [
|
const args = [
|
||||||
"-cz",
|
"-cz",
|
||||||
"-f",
|
"-f",
|
||||||
archivePath,
|
constants_1.CacheFilename,
|
||||||
"-C",
|
"-C",
|
||||||
workingDirectory,
|
workingDirectory,
|
||||||
sourceDirectories.join(" ")
|
"--files-from",
|
||||||
|
manifestFilename
|
||||||
];
|
];
|
||||||
yield execTar(args);
|
yield execTar(args, archiveFolder);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.createTar = createTar;
|
exports.createTar = createTar;
|
||||||
|
|
1
salt.txt
Normal file
1
salt.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Fri Mar 6 11:28:08 PST 2020
|
|
@ -18,3 +18,5 @@ export enum Events {
|
||||||
Push = "push",
|
Push = "push",
|
||||||
PullRequest = "pull_request"
|
PullRequest = "pull_request"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const CacheFilename = "cache.tgz";
|
||||||
|
|
12
src/save.ts
12
src/save.ts
|
@ -1,7 +1,7 @@
|
||||||
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, CacheFilename } from "./constants";
|
||||||
import { createTar } from "./tar";
|
import { createTar } from "./tar";
|
||||||
import * as utils from "./utils/actionUtils";
|
import * as utils from "./utils/actionUtils";
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ async function run(): Promise<void> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
core.debug(`Cache ID: ${cacheId}`);
|
core.debug(`Cache ID: ${cacheId}`);
|
||||||
const cachePaths = await utils.expandPaths(
|
const cachePaths = await utils.resolvePaths(
|
||||||
core
|
core
|
||||||
.getInput(Inputs.Path)
|
.getInput(Inputs.Path)
|
||||||
.split("\n")
|
.split("\n")
|
||||||
|
@ -53,13 +53,11 @@ async function run(): Promise<void> {
|
||||||
core.debug("Cache Paths:");
|
core.debug("Cache Paths:");
|
||||||
core.debug(`${JSON.stringify(cachePaths)}`);
|
core.debug(`${JSON.stringify(cachePaths)}`);
|
||||||
|
|
||||||
const archivePath = path.join(
|
const archiveFolder = await utils.createTempDirectory();
|
||||||
await utils.createTempDirectory(),
|
const archivePath = path.join(archiveFolder, CacheFilename);
|
||||||
"cache.tgz"
|
|
||||||
);
|
|
||||||
core.debug(`Archive Path: ${archivePath}`);
|
core.debug(`Archive Path: ${archivePath}`);
|
||||||
|
|
||||||
await createTar(archivePath, cachePaths);
|
await createTar(archiveFolder, cachePaths);
|
||||||
|
|
||||||
const fileSizeLimit = 5 * 1024 * 1024 * 1024; // 5GB per repo limit
|
const fileSizeLimit = 5 * 1024 * 1024 * 1024; // 5GB per repo limit
|
||||||
const archiveFileSize = utils.getArchiveFileSize(archivePath);
|
const archiveFileSize = utils.getArchiveFileSize(archivePath);
|
||||||
|
|
27
src/tar.ts
27
src/tar.ts
|
@ -1,6 +1,8 @@
|
||||||
import { exec } from "@actions/exec";
|
|
||||||
import * as io from "@actions/io";
|
import * as io from "@actions/io";
|
||||||
import { existsSync } from "fs";
|
import * as path from "path";
|
||||||
|
import { CacheFilename } from "./constants";
|
||||||
|
import { exec } from "@actions/exec";
|
||||||
|
import { existsSync, writeFileSync } from "fs";
|
||||||
|
|
||||||
async function getTarPath(): Promise<string> {
|
async function getTarPath(): Promise<string> {
|
||||||
// Explicitly use BSD Tar on Windows
|
// Explicitly use BSD Tar on Windows
|
||||||
|
@ -14,10 +16,12 @@ async function getTarPath(): Promise<string> {
|
||||||
return await io.which("tar", true);
|
return await io.which("tar", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function execTar(args: string[]): Promise<void> {
|
async function execTar(args: string[], cwd?: string): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await exec(`"${await getTarPath()}"`, args);
|
await exec(`"${await 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(
|
throw new Error(
|
||||||
|
@ -41,18 +45,25 @@ export async function extractTar(archivePath: string): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createTar(
|
export async function createTar(
|
||||||
archivePath: string,
|
archiveFolder: string,
|
||||||
sourceDirectories: string[]
|
sourceDirectories: string[]
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
// TODO: will want to stream sourceDirectories into tar
|
// TODO: will want to stream sourceDirectories into tar
|
||||||
|
const manifestFilename = "manifest.txt";
|
||||||
|
writeFileSync(
|
||||||
|
path.join(archiveFolder, manifestFilename),
|
||||||
|
sourceDirectories.join("\n")
|
||||||
|
);
|
||||||
|
|
||||||
const workingDirectory = getWorkingDirectory();
|
const workingDirectory = getWorkingDirectory();
|
||||||
const args = [
|
const args = [
|
||||||
"-cz",
|
"-cz",
|
||||||
"-f",
|
"-f",
|
||||||
archivePath,
|
CacheFilename,
|
||||||
"-C",
|
"-C",
|
||||||
workingDirectory,
|
workingDirectory,
|
||||||
sourceDirectories.join(" ")
|
"--files-from",
|
||||||
|
manifestFilename
|
||||||
];
|
];
|
||||||
await execTar(args);
|
await execTar(args, archiveFolder);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ export async function createTempDirectory(): Promise<string> {
|
||||||
}
|
}
|
||||||
tempDirectory = path.join(baseLocation, "actions", "temp");
|
tempDirectory = path.join(baseLocation, "actions", "temp");
|
||||||
}
|
}
|
||||||
|
|
||||||
const dest = path.join(tempDirectory, uuidV4.default());
|
const dest = path.join(tempDirectory, uuidV4.default());
|
||||||
await io.mkdirP(dest);
|
await io.mkdirP(dest);
|
||||||
return dest;
|
return dest;
|
||||||
|
@ -82,17 +83,21 @@ export function logWarning(message: string): void {
|
||||||
core.info(`${warningPrefix}${message}`);
|
core.info(`${warningPrefix}${message}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function expandPaths(patterns: string[]): Promise<string[]> {
|
export async function resolvePaths(patterns: string[]): Promise<string[]> {
|
||||||
const paths: string[] = [];
|
const paths: string[] = [];
|
||||||
const workspace = process.env["GITHUB_WORKSPACE"] ?? process.cwd();
|
const workspace = process.env["GITHUB_WORKSPACE"] ?? process.cwd();
|
||||||
|
const globber = await glob.create(patterns.join("\n"), {
|
||||||
|
implicitDescendants: false
|
||||||
|
});
|
||||||
|
|
||||||
const globber = await glob.create(patterns.join("\n"));
|
for await (const file of globber.globGenerator()) {
|
||||||
const files = await globber.glob();
|
const relativeFile = path.relative(workspace, file);
|
||||||
|
core.debug(`Matched: ${relativeFile}`);
|
||||||
|
// Paths are made relative so the tar entries are all relative to the root of the workspace.
|
||||||
|
paths.push(`${relativeFile}`);
|
||||||
|
}
|
||||||
|
|
||||||
paths.push(...files);
|
return paths;
|
||||||
|
|
||||||
// Convert paths to relative paths here?
|
|
||||||
return paths.map(x => path.relative(workspace, x));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSupportedEvents(): string[] {
|
export function getSupportedEvents(): string[] {
|
||||||
|
|
Loading…
Add table
Reference in a new issue