@@ -43402,36 +43402,36 @@ const path_1 = __importDefault(__webpack_require__(622));
43402
43402
const fs_1 = __importDefault(__webpack_require__(747));
43403
43403
const constants_1 = __webpack_require__(196);
43404
43404
const cache_utils_1 = __webpack_require__(452);
43405
- exports.restoreCache = (toolName , version) => __awaiter(void 0, void 0, void 0, function* () {
43406
- if (!cache_utils_1.isPackageManagerCacheSupported(toolName )) {
43407
- throw new Error(`${toolName} is not supported`);
43405
+ exports.restoreCache = (packageManager , version) => __awaiter(void 0, void 0, void 0, function* () {
43406
+ if (!cache_utils_1.isPackageManagerCacheSupported(packageManager )) {
43407
+ throw new Error(`Caching for '${packageManager}' is not supported`);
43408
43408
}
43409
- const lockKey = getLockFile(toolName );
43409
+ const lockKey = findLockFile(packageManager );
43410
43410
const platform = process.env.RUNNER_OS;
43411
43411
const fileHash = yield cache_utils_1.hashFile(lockKey);
43412
- const primaryKey = `${platform}-${toolName }-${version}-${fileHash}`;
43412
+ const primaryKey = `${platform}-${packageManager }-${version}-${fileHash}`;
43413
43413
core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
43414
- const cachePath = yield cache_utils_1.getCacheDirectoryPath(toolName );
43414
+ const cachePath = yield cache_utils_1.getCacheDirectoryPath(packageManager );
43415
43415
const cacheKey = yield cache.restoreCache([cachePath], primaryKey);
43416
43416
if (!cacheKey) {
43417
- core.warning(`Cache not found for input keys: ${primaryKey} `);
43417
+ core.warning(`${packageManager} cache is not found `);
43418
43418
return;
43419
43419
}
43420
43420
core.saveState(constants_1.State.CacheMatchedKey, cacheKey);
43421
43421
const isExactMatch = (primaryKey === cacheKey).toString();
43422
43422
core.setOutput(constants_1.Outputs.CacheHit, isExactMatch);
43423
43423
core.info(`Cache restored from key: ${cacheKey}`);
43424
43424
});
43425
- const getLockFile = (cacheType ) => {
43426
- let lockFile = 'package-lock.json';
43425
+ const findLockFile = (packageManager ) => {
43426
+ let lockFiles = [ 'package-lock.json', 'yarn.lock'] ;
43427
43427
const workspace = process.env.GITHUB_WORKSPACE;
43428
43428
const rootContent = fs_1.default.readdirSync(workspace);
43429
- if (cacheType === 'yarn') {
43430
- lockFile = 'yarn.lock' ;
43429
+ if (packageManager === 'yarn') {
43430
+ lockFiles.splice(0) ;
43431
43431
}
43432
- const fullLockFile = rootContent.find(item => lockFile === item);
43432
+ const fullLockFile = rootContent.find(item => lockFiles.includes( item) );
43433
43433
if (!fullLockFile) {
43434
- throw new Error(' No package-lock.json or yarn.lock were found' );
43434
+ throw new Error(` No package-lock.json or yarn.lock were found in ${workspace}` );
43435
43435
}
43436
43436
return path_1.default.resolve(fullLockFile);
43437
43437
};
@@ -44689,7 +44689,7 @@ const toolCacheCommands = {
44689
44689
yarn1: 'yarn cache dir',
44690
44690
yarn2: 'yarn config get cacheFolder'
44691
44691
};
44692
- const execHandler = (toolCommand, errMessage) => __awaiter(void 0, void 0, void 0, function* () {
44692
+ const getCommandOutput = (toolCommand, errMessage) => __awaiter(void 0, void 0, void 0, function* () {
44693
44693
let stdOut;
44694
44694
let stdErr;
44695
44695
yield exec.exec(toolCommand, undefined, {
@@ -44706,29 +44706,29 @@ const execHandler = (toolCommand, errMessage) => __awaiter(void 0, void 0, void
44706
44706
}
44707
44707
return stdOut;
44708
44708
});
44709
- const getToolVersion = (toolName , command, regex) => __awaiter(void 0, void 0, void 0, function* () {
44710
- const stdOut = yield execHandler (`${toolName } ${command}`, `Could not get version for ${toolName }`);
44709
+ const getpackageManagerVersion = (packageManager , command, regex) => __awaiter(void 0, void 0, void 0, function* () {
44710
+ const stdOut = yield getCommandOutput (`${packageManager } ${command}`, `Could not get version for ${packageManager }`);
44711
44711
if (stdOut.startsWith('1.')) {
44712
44712
return '1';
44713
44713
}
44714
44714
return '2';
44715
44715
});
44716
- const getCmdCommand = (toolName ) => __awaiter(void 0, void 0, void 0, function* () {
44717
- let cmdCommand = toolName ;
44718
- if (toolName === 'yarn') {
44719
- const toolVersion = yield getToolVersion(toolName , '--version');
44720
- cmdCommand = `${toolName }${toolVersion}`;
44716
+ const getCmdCommand = (packageManager ) => __awaiter(void 0, void 0, void 0, function* () {
44717
+ let cmdCommand = packageManager ;
44718
+ if (packageManager === 'yarn') {
44719
+ const toolVersion = yield getpackageManagerVersion(packageManager , '--version');
44720
+ cmdCommand = `${packageManager }${toolVersion}`;
44721
44721
}
44722
44722
return cmdCommand;
44723
44723
});
44724
- exports.isPackageManagerCacheSupported = toolName => {
44724
+ exports.isPackageManagerCacheSupported = packageManager => {
44725
44725
const arr = Array.of(...Object.values(constants_1.LockType));
44726
- return arr.includes(toolName );
44726
+ return arr.includes(packageManager );
44727
44727
};
44728
- exports.getCacheDirectoryPath = (toolName ) => __awaiter(void 0, void 0, void 0, function* () {
44729
- const fullToolName = yield getCmdCommand(toolName );
44728
+ exports.getCacheDirectoryPath = (packageManager ) => __awaiter(void 0, void 0, void 0, function* () {
44729
+ const fullToolName = yield getCmdCommand(packageManager );
44730
44730
const toolCommand = toolCacheCommands[fullToolName];
44731
- const stdOut = yield execHandler (toolCommand, `Could not get version for ${toolName }`);
44731
+ const stdOut = yield getCommandOutput (toolCommand, `Could not get version for ${packageManager }`);
44732
44732
return stdOut;
44733
44733
});
44734
44734
// https://github.com/actions/runner/blob/master/src/Misc/expressionFunc/hashFiles/src/hashFiles.ts
@@ -44747,7 +44747,8 @@ function hashFile(matchPatterns) {
44747
44747
try {
44748
44748
for (var _b = __asyncValues(globber.globGenerator()), _c; _c = yield _b.next(), !_c.done;) {
44749
44749
const file = _c.value;
44750
- console.log(file);
44750
+ console.log(globber);
44751
+ console.log(`fileis ${file}`);
44751
44752
if (!file.startsWith(`${githubWorkspace}${path.sep}`)) {
44752
44753
continue;
44753
44754
}
@@ -44771,6 +44772,7 @@ function hashFile(matchPatterns) {
44771
44772
finally { if (e_1) throw e_1.error; }
44772
44773
}
44773
44774
result.end();
44775
+ // node -e "const prmosify = require('util').promisify; const crypto = require('crypto'); const stream = require('stream'); const file = '/Users/dmitryshibanov/Documents/myProjects/setup-node/__tests__/data/package-lock.json'; const resul = crypto.createHash('sha256'); const hash = crypto.createHash('sha256'); const pipeline = prmosify(stream.pipeline); pipeline(fs.createReadStream(file), hash).then((result1) =>{ result.write(hash.digest()); result.end(); console.log(result.digest('hex'))}) "
44774
44776
return result.digest('hex');
44775
44777
});
44776
44778
}
0 commit comments