Skip to content

Commit 74b0791

Browse files
worked on resolving comments
1 parent b38fc9b commit 74b0791

File tree

9 files changed

+414
-409
lines changed

9 files changed

+414
-409
lines changed

action.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ inputs:
2020
description: Used to pull node distributions from node-versions. Since there's a default, this is typically not supplied by the user.
2121
default: ${{ github.token }}
2222
cache:
23-
description: 'Used to specify cache variant'
23+
description: 'Used to specify supported package manager to cache in its default directory'
2424
key:
2525
description: 'primary key to restore and save modules'
2626
# TODO: add input to control forcing to pull from cloud or dist.
@@ -32,4 +32,5 @@ inputs:
3232
runs:
3333
using: 'node12'
3434
main: 'dist/setup/index.js'
35-
post: 'dist/cleanup/index.js'
35+
post: 'dist/saveCache/index.js'
36+
post-if: inputs.cache != ''

dist/cleanup/index.js renamed to dist/saveCache/index.js

Lines changed: 139 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -39252,7 +39252,137 @@ exports.NOOP_METER_PROVIDER = new NoopMeterProvider();
3925239252

3925339253

3925439254
/***/ }),
39255-
/* 452 */,
39255+
/* 452 */
39256+
/***/ (function(__unusedmodule, exports, __webpack_require__) {
39257+
39258+
"use strict";
39259+
39260+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
39261+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
39262+
return new (P || (P = Promise))(function (resolve, reject) {
39263+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39264+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
39265+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
39266+
step((generator = generator.apply(thisArg, _arguments || [])).next());
39267+
});
39268+
};
39269+
var __asyncValues = (this && this.__asyncValues) || function (o) {
39270+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
39271+
var m = o[Symbol.asyncIterator], i;
39272+
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);
39273+
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); }); }; }
39274+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
39275+
};
39276+
var __importStar = (this && this.__importStar) || function (mod) {
39277+
if (mod && mod.__esModule) return mod;
39278+
var result = {};
39279+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
39280+
result["default"] = mod;
39281+
return result;
39282+
};
39283+
Object.defineProperty(exports, "__esModule", { value: true });
39284+
const exec = __importStar(__webpack_require__(986));
39285+
const constants_1 = __webpack_require__(196);
39286+
const glob = __importStar(__webpack_require__(281));
39287+
const crypto = __importStar(__webpack_require__(417));
39288+
const fs = __importStar(__webpack_require__(747));
39289+
const stream = __importStar(__webpack_require__(794));
39290+
const util = __importStar(__webpack_require__(669));
39291+
const path = __importStar(__webpack_require__(622));
39292+
const toolCacheCommands = {
39293+
npm: 'npm config get cache',
39294+
yarn1: 'yarn cache dir',
39295+
yarn2: 'yarn config get cacheFolder'
39296+
};
39297+
const execHandler = (toolCommand, errMessage) => __awaiter(void 0, void 0, void 0, function* () {
39298+
let stdOut;
39299+
let stdErr;
39300+
yield exec.exec(toolCommand, undefined, {
39301+
listeners: {
39302+
stderr: (err) => (stdErr = err.toString()),
39303+
stdout: (out) => (stdOut = out.toString())
39304+
}
39305+
});
39306+
if (stdErr) {
39307+
throw new Error(stdErr);
39308+
}
39309+
if (!stdOut) {
39310+
throw new Error(errMessage);
39311+
}
39312+
return stdOut;
39313+
});
39314+
const getToolVersion = (toolName, command, regex) => __awaiter(void 0, void 0, void 0, function* () {
39315+
const stdOut = yield execHandler(`${toolName} ${command}`, `Could not get version for ${toolName}`);
39316+
if (stdOut.startsWith('1.')) {
39317+
return '1';
39318+
}
39319+
return '2';
39320+
});
39321+
const getCmdCommand = (toolName) => __awaiter(void 0, void 0, void 0, function* () {
39322+
let cmdCommand = toolName;
39323+
if (toolName === 'yarn') {
39324+
const toolVersion = yield getToolVersion(toolName, '--version');
39325+
cmdCommand = `${toolName}${toolVersion}`;
39326+
}
39327+
return cmdCommand;
39328+
});
39329+
exports.isPackageManagerCacheSupported = toolName => {
39330+
const arr = Array.of(...Object.values(constants_1.LockType));
39331+
return arr.includes(toolName);
39332+
};
39333+
exports.getCacheDirectoryPath = (toolName) => __awaiter(void 0, void 0, void 0, function* () {
39334+
const fullToolName = yield getCmdCommand(toolName);
39335+
const toolCommand = toolCacheCommands[fullToolName];
39336+
const stdOut = yield execHandler(toolCommand, `Could not get version for ${toolName}`);
39337+
return stdOut;
39338+
});
39339+
// https://github.com/actions/runner/blob/master/src/Misc/expressionFunc/hashFiles/src/hashFiles.ts
39340+
// replace it, when the issue will be resolved: https://github.com/actions/toolkit/issues/472
39341+
function hashFile(matchPatterns) {
39342+
var e_1, _a;
39343+
return __awaiter(this, void 0, void 0, function* () {
39344+
let hasMatch = false;
39345+
let followSymbolicLinks = false;
39346+
if (process.env.followSymbolicLinks === 'true') {
39347+
followSymbolicLinks = true;
39348+
}
39349+
const githubWorkspace = process.env.GITHUB_WORKSPACE;
39350+
const result = crypto.createHash('sha256');
39351+
const globber = yield glob.create(matchPatterns, { followSymbolicLinks });
39352+
try {
39353+
for (var _b = __asyncValues(globber.globGenerator()), _c; _c = yield _b.next(), !_c.done;) {
39354+
const file = _c.value;
39355+
console.log(file);
39356+
if (!file.startsWith(`${githubWorkspace}${path.sep}`)) {
39357+
continue;
39358+
}
39359+
if (fs.statSync(file).isDirectory()) {
39360+
continue;
39361+
}
39362+
const hash = crypto.createHash('sha256');
39363+
const pipeline = util.promisify(stream.pipeline);
39364+
yield pipeline(fs.createReadStream(file), hash);
39365+
result.write(hash.digest());
39366+
if (!hasMatch) {
39367+
hasMatch = true;
39368+
}
39369+
}
39370+
}
39371+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
39372+
finally {
39373+
try {
39374+
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
39375+
}
39376+
finally { if (e_1) throw e_1.error; }
39377+
}
39378+
result.end();
39379+
return result.digest('hex');
39380+
});
39381+
}
39382+
exports.hashFile = hashFile;
39383+
39384+
39385+
/***/ }),
3925639386
/* 453 */,
3925739387
/* 454 */
3925839388
/***/ (function(module, exports, __webpack_require__) {
@@ -47699,101 +47829,7 @@ exports.ProxyTracerProvider = ProxyTracerProvider;
4769947829
/* 719 */,
4770047830
/* 720 */,
4770147831
/* 721 */,
47702-
/* 722 */
47703-
/***/ (function(__unusedmodule, exports, __webpack_require__) {
47704-
47705-
"use strict";
47706-
47707-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
47708-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
47709-
return new (P || (P = Promise))(function (resolve, reject) {
47710-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
47711-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
47712-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
47713-
step((generator = generator.apply(thisArg, _arguments || [])).next());
47714-
});
47715-
};
47716-
var __importStar = (this && this.__importStar) || function (mod) {
47717-
if (mod && mod.__esModule) return mod;
47718-
var result = {};
47719-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
47720-
result["default"] = mod;
47721-
return result;
47722-
};
47723-
Object.defineProperty(exports, "__esModule", { value: true });
47724-
const exec = __importStar(__webpack_require__(986));
47725-
const core = __importStar(__webpack_require__(470));
47726-
const constants_1 = __webpack_require__(196);
47727-
const semver_1 = __webpack_require__(280);
47728-
const toolCacheCommands = {
47729-
npm: 'npm config get cache',
47730-
yarn1: 'yarn cache dir',
47731-
yarn2: 'yarn config get cacheFolder'
47732-
};
47733-
const getToolVersion = (toolName, command, regex) => __awaiter(void 0, void 0, void 0, function* () {
47734-
let stdErr;
47735-
let stdOut;
47736-
let toolVersion;
47737-
yield exec.exec(`${toolName} ${command}`, undefined, {
47738-
listeners: {
47739-
stdout: (err) => (stdOut = err.toString()),
47740-
stderr: (out) => (stdErr = out.toString())
47741-
}
47742-
});
47743-
core.info(`stdout is ${stdOut}`);
47744-
core.info(`stdErr is ${stdErr}`);
47745-
if (stdErr) {
47746-
throw new Error(stdErr);
47747-
}
47748-
if (!stdOut) {
47749-
throw new Error(`Could not get version for ${toolName}`);
47750-
}
47751-
if (regex) {
47752-
core.info('add regex support');
47753-
toolVersion = stdOut;
47754-
}
47755-
else {
47756-
toolVersion = semver_1.major(stdOut).toString();
47757-
}
47758-
return toolVersion;
47759-
});
47760-
const getCmdCommand = (toolName, version) => {
47761-
let cmdCommand = toolName;
47762-
if (toolName === 'yarn') {
47763-
cmdCommand = `${toolName}${version}`;
47764-
}
47765-
return cmdCommand;
47766-
};
47767-
exports.isToolSupported = toolName => {
47768-
const arr = Array.of(...Object.values(constants_1.LockType));
47769-
return arr.includes(toolName);
47770-
};
47771-
exports.getDefaultCacheDirectory = (toolName) => __awaiter(void 0, void 0, void 0, function* () {
47772-
let stdOut;
47773-
let stdErr;
47774-
if (!exports.isToolSupported(toolName)) {
47775-
throw new Error(`${toolName} is not supported`);
47776-
}
47777-
const toolVersion = yield getToolVersion(toolName, '--version');
47778-
const fullToolName = getCmdCommand(toolName, toolVersion);
47779-
const toolCommand = toolCacheCommands[fullToolName];
47780-
yield exec.exec(toolCommand, undefined, {
47781-
listeners: {
47782-
stderr: (err) => (stdErr = err.toString()),
47783-
stdout: (out) => (stdOut = out.toString())
47784-
}
47785-
});
47786-
if (stdErr) {
47787-
throw new Error(stdErr);
47788-
}
47789-
if (!stdOut) {
47790-
throw new Error(`Could not get version for ${toolName}`);
47791-
}
47792-
return stdOut;
47793-
});
47794-
47795-
47796-
/***/ }),
47832+
/* 722 */,
4779747833
/* 723 */,
4779847834
/* 724 */
4779947835
/***/ (function(module) {
@@ -50296,24 +50332,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
5029650332
const core = __importStar(__webpack_require__(470));
5029750333
const cache = __importStar(__webpack_require__(692));
5029850334
const constants_1 = __webpack_require__(196);
50299-
const cache_1 = __webpack_require__(722);
50335+
const cache_utils_1 = __webpack_require__(452);
5030050336
function run() {
5030150337
return __awaiter(this, void 0, void 0, function* () {
5030250338
const cacheLock = core.getInput(constants_1.Inputs.Cache);
50303-
if (cacheLock && cache_1.isToolSupported(cacheLock)) {
50304-
try {
50305-
yield cachePackages(cacheLock);
50306-
}
50307-
catch (error) {
50308-
core.setFailed('Failed to remove private key');
50309-
}
50339+
try {
50340+
yield cachePackages(cacheLock);
50341+
}
50342+
catch (error) {
50343+
core.setFailed('Failed to remove private key');
5031050344
}
5031150345
});
5031250346
}
5031350347
const cachePackages = (toolName) => __awaiter(void 0, void 0, void 0, function* () {
5031450348
const state = getCacheState();
5031550349
const primaryKey = core.getState(constants_1.State.CachePrimaryKey);
50316-
const cachePath = yield cache_1.getDefaultCacheDirectory(toolName);
50350+
const cachePath = yield cache_utils_1.getCacheDirectoryPath(toolName);
5031750351
if (isExactKeyMatch(primaryKey, state)) {
5031850352
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
5031950353
return;

0 commit comments

Comments
 (0)