@@ -7522,7 +7522,6 @@ function run() {
75227522 }
75237523 let arch = core.getInput('architecture');
75247524 const cache = core.getInput('cache');
7525- core.info(`cache is ${cache}`);
75267525 // if architecture supplied but node-version is not
75277526 // if we don't throw a warning, the already installed x64 node will be used which is not probably what user meant.
75287527 if (arch && !version) {
@@ -7545,7 +7544,7 @@ function run() {
75457544 }
75467545 if (cache) {
75477546 if (!isGhes()) {
7548- yield cache_restore_1.restoreCache(cache, version );
7547+ yield cache_restore_1.restoreCache(cache);
75497548 }
75507549 else {
75517550 throw new Error('Caching is not supported on GHES');
@@ -43402,19 +43401,19 @@ const path_1 = __importDefault(__webpack_require__(622));
4340243401const fs_1 = __importDefault(__webpack_require__(747));
4340343402const constants_1 = __webpack_require__(196);
4340443403const cache_utils_1 = __webpack_require__(452);
43405- exports.restoreCache = (packageManager, version ) => __awaiter(void 0, void 0, void 0, function* () {
43404+ exports.restoreCache = (packageManager) => __awaiter(void 0, void 0, void 0, function* () {
4340643405 if (!cache_utils_1.isPackageManagerCacheSupported(packageManager)) {
4340743406 throw new Error(`Caching for '${packageManager}'is not supported`);
4340843407 }
43409- const lockKey = findLockFile(packageManager);
4341043408 const platform = process.env.RUNNER_OS;
43411- const fileHash = yield cache_utils_1.hashFile(lockKey);
43412- const primaryKey = `${platform}-${packageManager}-${version}-${fileHash}`;
43409+ const lockFilePath = findLockFile(packageManager);
43410+ const fileHash = yield cache_utils_1.hashFile(lockFilePath);
43411+ const primaryKey = `${platform}-${packageManager}-${fileHash}`;
4341343412 core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
4341443413 const cachePath = yield cache_utils_1.getCacheDirectoryPath(packageManager);
4341543414 const cacheKey = yield cache.restoreCache([cachePath], primaryKey);
4341643415 if (!cacheKey) {
43417- core.warning (`${packageManager} cache is not found`);
43416+ core.info (`${packageManager} cache is not found`);
4341843417 return;
4341943418 }
4342043419 core.saveState(constants_1.State.CacheMatchedKey, cacheKey);
@@ -43423,12 +43422,15 @@ exports.restoreCache = (packageManager, version) => __awaiter(void 0, void 0, vo
4342343422 core.info(`Cache restored from key: ${cacheKey}`);
4342443423});
4342543424const findLockFile = (packageManager) => {
43426- let lockFiles = ['package-lock.json', 'yarn.lock'];
43425+ let lockFiles;
43426+ if (packageManager === 'npm') {
43427+ lockFiles = cache_utils_1.supportedPackageManagers.npm.lockFilePatterns;
43428+ }
43429+ else {
43430+ lockFiles = cache_utils_1.supportedPackageManagers.yarn1.lockFilePatterns;
43431+ }
4342743432 const workspace = process.env.GITHUB_WORKSPACE;
4342843433 const rootContent = fs_1.default.readdirSync(workspace);
43429- if (packageManager === 'yarn') {
43430- lockFiles.splice(0);
43431- }
4343243434 const fullLockFile = rootContent.find(item => lockFiles.includes(item));
4343343435 if (!fullLockFile) {
4343443436 throw new Error(`No package-lock.json or yarn.lock were found in ${workspace}`);
@@ -44684,12 +44686,21 @@ const fs = __importStar(__webpack_require__(747));
4468444686const stream = __importStar(__webpack_require__(794));
4468544687const util = __importStar(__webpack_require__(669));
4468644688const path = __importStar(__webpack_require__(622));
44687- const toolCacheCommands = {
44688- npm: 'npm config get cache',
44689- yarn1: 'yarn cache dir',
44690- yarn2: 'yarn config get cacheFolder'
44689+ exports.supportedPackageManagers = {
44690+ npm: {
44691+ lockFilePatterns: ['package-lock.json', 'yarn.lock'],
44692+ getCacheFolderCommand: 'npm config get cache'
44693+ },
44694+ yarn1: {
44695+ lockFilePatterns: ['yarn.lock'],
44696+ getCacheFolderCommand: 'yarn cache dir'
44697+ },
44698+ yarn2: {
44699+ lockFilePatterns: ['yarn.lock'],
44700+ getCacheFolderCommand: 'yarn config get cacheFolder'
44701+ }
4469144702};
44692- const getCommandOutput = (toolCommand, errMessage ) => __awaiter(void 0, void 0, void 0, function* () {
44703+ const getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () {
4469344704 let stdOut;
4469444705 let stdErr;
4469544706 yield exec.exec(toolCommand, undefined, {
@@ -44701,13 +44712,13 @@ const getCommandOutput = (toolCommand, errMessage) => __awaiter(void 0, void 0,
4470144712 if (stdErr) {
4470244713 throw new Error(stdErr);
4470344714 }
44704- if (!stdOut) {
44705- throw new Error(errMessage);
44706- }
4470744715 return stdOut;
4470844716});
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}`);
44717+ const getpackageManagerVersion = (packageManager, command) => __awaiter(void 0, void 0, void 0, function* () {
44718+ const stdOut = yield getCommandOutput(`${packageManager} ${command}`);
44719+ if (!stdOut) {
44720+ throw new Error(`Could not get version for ${packageManager}`);
44721+ }
4471144722 if (stdOut.startsWith('1.')) {
4471244723 return '1';
4471344724 }
@@ -44726,9 +44737,23 @@ exports.isPackageManagerCacheSupported = packageManager => {
4472644737 return arr.includes(packageManager);
4472744738};
4472844739exports.getCacheDirectoryPath = (packageManager) => __awaiter(void 0, void 0, void 0, function* () {
44729- const fullToolName = yield getCmdCommand(packageManager);
44730- const toolCommand = toolCacheCommands[fullToolName];
44731- const stdOut = yield getCommandOutput(toolCommand, `Could not get version for ${packageManager}`);
44740+ let packageManagerInfo;
44741+ if (packageManager === 'npm') {
44742+ packageManagerInfo = exports.supportedPackageManagers.npm;
44743+ }
44744+ else if (packageManager === 'yarn') {
44745+ const yarnVersion = yield getpackageManagerVersion('yarn', '--version');
44746+ if (yarnVersion.startsWith('1.')) {
44747+ packageManagerInfo = exports.supportedPackageManagers.yarn1;
44748+ }
44749+ else {
44750+ packageManagerInfo = exports.supportedPackageManagers.yarn2;
44751+ }
44752+ }
44753+ const stdOut = yield getCommandOutput(packageManagerInfo.getCacheFolderCommand);
44754+ if (!stdOut) {
44755+ throw new Error(`Could not get version for ${packageManager}`);
44756+ }
4473244757 return stdOut;
4473344758});
4473444759// https://github.com/actions/runner/blob/master/src/Misc/expressionFunc/hashFiles/src/hashFiles.ts
0 commit comments