@@ -43387,6 +43387,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
43387
43387
step((generator = generator.apply(thisArg, _arguments || [])).next());
43388
43388
});
43389
43389
};
43390
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
43391
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
43392
+ var m = o[Symbol.asyncIterator], i;
43393
+ 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);
43394
+ 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); }); }; }
43395
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
43396
+ };
43390
43397
var __importStar = (this && this.__importStar) || function (mod) {
43391
43398
if (mod && mod.__esModule) return mod;
43392
43399
var result = {};
@@ -43397,16 +43404,25 @@ var __importStar = (this && this.__importStar) || function (mod) {
43397
43404
Object.defineProperty(exports, "__esModule", { value: true });
43398
43405
const cache = __importStar(__webpack_require__(638));
43399
43406
const core = __importStar(__webpack_require__(470));
43407
+ const glob = __importStar(__webpack_require__(281));
43408
+ const crypto = __importStar(__webpack_require__(417));
43409
+ const fs = __importStar(__webpack_require__(747));
43410
+ const stream = __importStar(__webpack_require__(794));
43411
+ const util = __importStar(__webpack_require__(669));
43412
+ const path = __importStar(__webpack_require__(622));
43400
43413
const constants_1 = __webpack_require__(694);
43401
43414
const cache_1 = __webpack_require__(913);
43402
43415
exports.restoreCache = (type) => __awaiter(void 0, void 0, void 0, function* () {
43403
43416
let tool = 'npm';
43404
- const primaryKey = core.getInput(constants_1.Inputs.Key, { required: true });
43405
- core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
43417
+ const lockKey = core.getInput(constants_1.Inputs.Key, { required: true });
43418
+ const currentOs = process.env.RUNNER_OS;
43419
+ const fileHash = yield hashFile(lockKey);
43406
43420
if (type === constants_1.LockType.Yarn) {
43407
43421
const yarnVersion = yield cache_1.getYarnVersion();
43408
43422
tool = `yarn${yarnVersion}`;
43409
43423
}
43424
+ const primaryKey = `${currentOs}-${tool}-${fileHash}`;
43425
+ core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
43410
43426
const cachePath = yield cache_1.getDefaultCacheDirectory(tool);
43411
43427
core.info(`cachePath is ${cachePath}`);
43412
43428
core.info(`primaryKey is ${primaryKey}`);
@@ -43421,6 +43437,51 @@ exports.restoreCache = (type) => __awaiter(void 0, void 0, void 0, function* ()
43421
43437
core.setOutput(constants_1.Outputs.CacheHit, isExactMatch);
43422
43438
core.info(`Cache restored from key: ${cacheKey}`);
43423
43439
});
43440
+ function hashFile(matchPatterns) {
43441
+ var e_1, _a;
43442
+ return __awaiter(this, void 0, void 0, function* () {
43443
+ let followSymbolicLinks = false;
43444
+ if (process.env.followSymbolicLinks === 'true') {
43445
+ followSymbolicLinks = true;
43446
+ }
43447
+ let hasMatch = false;
43448
+ const githubWorkspace = process.env.GITHUB_WORKSPACE;
43449
+ const result = crypto.createHash('sha256');
43450
+ let count = 0;
43451
+ const globber = yield glob.create(matchPatterns, { followSymbolicLinks });
43452
+ try {
43453
+ for (var _b = __asyncValues(globber.globGenerator()), _c; _c = yield _b.next(), !_c.done;) {
43454
+ const file = _c.value;
43455
+ console.log(file);
43456
+ if (!file.startsWith(`${githubWorkspace}${path.sep}`)) {
43457
+ console.log(`Ignore '${file}' since it is not under GITHUB_WORKSPACE.`);
43458
+ continue;
43459
+ }
43460
+ if (fs.statSync(file).isDirectory()) {
43461
+ console.log(`Skip directory '${file}'.`);
43462
+ continue;
43463
+ }
43464
+ const hash = crypto.createHash('sha256');
43465
+ const pipeline = util.promisify(stream.pipeline);
43466
+ yield pipeline(fs.createReadStream(file), hash);
43467
+ result.write(hash.digest());
43468
+ count++;
43469
+ if (!hasMatch) {
43470
+ hasMatch = true;
43471
+ }
43472
+ }
43473
+ }
43474
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
43475
+ finally {
43476
+ try {
43477
+ if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
43478
+ }
43479
+ finally { if (e_1) throw e_1.error; }
43480
+ }
43481
+ result.end();
43482
+ return result.digest('hex');
43483
+ });
43484
+ }
43424
43485
43425
43486
43426
43487
/***/ }),
0 commit comments