Compare commits

..

1 Commits

Author SHA1 Message Date
K.B.Dharun Krishna
1ee4b17648
Merge b57a050d8f into 2a017f350d 2023-10-09 11:40:47 +05:30
9 changed files with 5148 additions and 5039 deletions

Binary file not shown.

View File

@ -357,41 +357,6 @@ describe('setup-node', () => {
expect(cnSpy).toHaveBeenCalledWith(`::error::${errMsg}${osm.EOL}`); expect(cnSpy).toHaveBeenCalledWith(`::error::${errMsg}${osm.EOL}`);
}); });
it('reports when download failed but version exists', async () => {
os.platform = 'linux';
os.arch = 'x64';
// a version which is not in the manifest but is in node dist
const versionSpec = '11.15.0';
inputs['node-version'] = versionSpec;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken';
// ... but not in the local cache
findSpy.mockImplementation(() => '');
dlSpy.mockImplementationOnce(async () => {
throw new tc.HTTPError(404);
});
await main.run();
expect(getManifestSpy).toHaveBeenCalled();
expect(logSpy).toHaveBeenCalledWith(
`Attempting to download ${versionSpec}...`
);
expect(logSpy).toHaveBeenCalledWith(
'Not found in manifest. Falling back to download directly from Node'
);
expect(dlSpy).toHaveBeenCalled();
expect(warningSpy).toHaveBeenCalledWith(
`Node version ${versionSpec} for platform ${os.platform} and architecture ${os.arch} was found but failed to download. ` +
'This usually happens when downloadable binaries are not fully updated at https://nodejs.org/. ' +
'To resolve this issue you may either fall back to the older version or try again later.'
);
});
it('acquires specified architecture of node', async () => { it('acquires specified architecture of node', async () => {
for (const {arch, version, osSpec} of [ for (const {arch, version, osSpec} of [
{arch: 'x86', version: '12.16.2', osSpec: 'win32'}, {arch: 'x86', version: '12.16.2', osSpec: 'win32'},

View File

@ -60332,90 +60332,86 @@ exports.debug = debug; // for test
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict"; "use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k; if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k); Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { }) : (function(o, m, k, k2) {
desc = { enumerable: true, get: function() { return m[k]; } }; if (k2 === undefined) k2 = k;
} o[k2] = m[k];
Object.defineProperty(o, k2, desc); }));
}) : (function(o, m, k, k2) { var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
if (k2 === undefined) k2 = k; Object.defineProperty(o, "default", { enumerable: true, value: v });
o[k2] = m[k]; }) : function(o, v) {
})); o["default"] = v;
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { });
Object.defineProperty(o, "default", { enumerable: true, value: v }); var __importStar = (this && this.__importStar) || function (mod) {
}) : function(o, v) { if (mod && mod.__esModule) return mod;
o["default"] = v; var result = {};
}); if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
var __importStar = (this && this.__importStar) || function (mod) { __setModuleDefault(result, mod);
if (mod && mod.__esModule) return mod; return result;
var result = {}; };
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
__setModuleDefault(result, mod); function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return result; return new (P || (P = Promise))(function (resolve, reject) {
}; function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
return new (P || (P = Promise))(function (resolve, reject) { step((generator = generator.apply(thisArg, _arguments || [])).next());
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } });
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } };
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } Object.defineProperty(exports, "__esModule", ({ value: true }));
step((generator = generator.apply(thisArg, _arguments || [])).next()); exports.run = void 0;
}); const core = __importStar(__nccwpck_require__(2186));
}; const cache = __importStar(__nccwpck_require__(7799));
Object.defineProperty(exports, "__esModule", ({ value: true })); const constants_1 = __nccwpck_require__(9042);
exports.run = void 0; const cache_utils_1 = __nccwpck_require__(1678);
const core = __importStar(__nccwpck_require__(2186)); // Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
const cache = __importStar(__nccwpck_require__(7799)); // @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to
const constants_1 = __nccwpck_require__(9042); // throw an uncaught exception. Instead of failing this action, just warn.
const cache_utils_1 = __nccwpck_require__(1678); process.on('uncaughtException', e => {
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in const warningPrefix = '[warning]';
// @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to core.info(`${warningPrefix}${e.message}`);
// throw an uncaught exception. Instead of failing this action, just warn. });
process.on('uncaughtException', e => { function run() {
const warningPrefix = '[warning]'; return __awaiter(this, void 0, void 0, function* () {
core.info(`${warningPrefix}${e.message}`); try {
}); const cacheLock = core.getState(constants_1.State.CachePackageManager);
function run() { yield cachePackages(cacheLock);
return __awaiter(this, void 0, void 0, function* () { }
try { catch (error) {
const cacheLock = core.getState(constants_1.State.CachePackageManager); core.setFailed(error.message);
yield cachePackages(cacheLock); }
} });
catch (error) { }
core.setFailed(error.message); exports.run = run;
} const cachePackages = (packageManager) => __awaiter(void 0, void 0, void 0, function* () {
}); const state = core.getState(constants_1.State.CacheMatchedKey);
} const primaryKey = core.getState(constants_1.State.CachePrimaryKey);
exports.run = run; const cachePaths = JSON.parse(core.getState(constants_1.State.CachePaths) || '[]');
const cachePackages = (packageManager) => __awaiter(void 0, void 0, void 0, function* () { const packageManagerInfo = yield cache_utils_1.getPackageManagerInfo(packageManager);
const state = core.getState(constants_1.State.CacheMatchedKey); if (!packageManagerInfo) {
const primaryKey = core.getState(constants_1.State.CachePrimaryKey); core.debug(`Caching for '${packageManager}' is not supported`);
const cachePaths = JSON.parse(core.getState(constants_1.State.CachePaths) || '[]'); return;
const packageManagerInfo = yield (0, cache_utils_1.getPackageManagerInfo)(packageManager); }
if (!packageManagerInfo) { if (!cachePaths.length) {
core.debug(`Caching for '${packageManager}' is not supported`); // TODO: core.getInput has a bug - it can return undefined despite its definition (tests only?)
return; // export declare function getInput(name: string, options?: InputOptions): string;
} const cacheDependencyPath = core.getInput('cache-dependency-path') || '';
if (!cachePaths.length) { throw new Error(`Cache folder paths are not retrieved for ${packageManager} with cache-dependency-path = ${cacheDependencyPath}`);
// TODO: core.getInput has a bug - it can return undefined despite its definition (tests only?) }
// export declare function getInput(name: string, options?: InputOptions): string; if (primaryKey === state) {
const cacheDependencyPath = core.getInput('cache-dependency-path') || ''; core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
throw new Error(`Cache folder paths are not retrieved for ${packageManager} with cache-dependency-path = ${cacheDependencyPath}`); return;
} }
if (primaryKey === state) { const cacheId = yield cache.saveCache(cachePaths, primaryKey);
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`); if (cacheId == -1) {
return; return;
} }
const cacheId = yield cache.saveCache(cachePaths, primaryKey); core.info(`Cache saved with the key: ${primaryKey}`);
if (cacheId == -1) { });
return; run();
}
core.info(`Cache saved with the key: ${primaryKey}`);
});
run();
/***/ }), /***/ }),
@ -60424,258 +60420,254 @@ run();
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict"; "use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k; if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k); Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { }) : (function(o, m, k, k2) {
desc = { enumerable: true, get: function() { return m[k]; } }; if (k2 === undefined) k2 = k;
} o[k2] = m[k];
Object.defineProperty(o, k2, desc); }));
}) : (function(o, m, k, k2) { var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
if (k2 === undefined) k2 = k; Object.defineProperty(o, "default", { enumerable: true, value: v });
o[k2] = m[k]; }) : function(o, v) {
})); o["default"] = v;
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { });
Object.defineProperty(o, "default", { enumerable: true, value: v }); var __importStar = (this && this.__importStar) || function (mod) {
}) : function(o, v) { if (mod && mod.__esModule) return mod;
o["default"] = v; var result = {};
}); if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
var __importStar = (this && this.__importStar) || function (mod) { __setModuleDefault(result, mod);
if (mod && mod.__esModule) return mod; return result;
var result = {}; };
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
__setModuleDefault(result, mod); function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return result; return new (P || (P = Promise))(function (resolve, reject) {
}; function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
return new (P || (P = Promise))(function (resolve, reject) { step((generator = generator.apply(thisArg, _arguments || [])).next());
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } });
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } };
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } var __importDefault = (this && this.__importDefault) || function (mod) {
step((generator = generator.apply(thisArg, _arguments || [])).next()); return (mod && mod.__esModule) ? mod : { "default": mod };
}); };
}; Object.defineProperty(exports, "__esModule", ({ value: true }));
var __importDefault = (this && this.__importDefault) || function (mod) { exports.isCacheFeatureAvailable = exports.isGhes = exports.repoHasYarnBerryManagedDependencies = exports.getCacheDirectories = exports.resetProjectDirectoriesMemoized = exports.getPackageManagerInfo = exports.getCommandOutputNotEmpty = exports.getCommandOutput = exports.supportedPackageManagers = void 0;
return (mod && mod.__esModule) ? mod : { "default": mod }; const core = __importStar(__nccwpck_require__(2186));
}; const exec = __importStar(__nccwpck_require__(1514));
Object.defineProperty(exports, "__esModule", ({ value: true })); const cache = __importStar(__nccwpck_require__(7799));
exports.isCacheFeatureAvailable = exports.isGhes = exports.repoHasYarnBerryManagedDependencies = exports.getCacheDirectories = exports.resetProjectDirectoriesMemoized = exports.getPackageManagerInfo = exports.getCommandOutputNotEmpty = exports.getCommandOutput = exports.supportedPackageManagers = void 0; const glob = __importStar(__nccwpck_require__(8090));
const core = __importStar(__nccwpck_require__(2186)); const path_1 = __importDefault(__nccwpck_require__(1017));
const exec = __importStar(__nccwpck_require__(1514)); const fs_1 = __importDefault(__nccwpck_require__(7147));
const cache = __importStar(__nccwpck_require__(7799)); const util_1 = __nccwpck_require__(2629);
const glob = __importStar(__nccwpck_require__(8090)); exports.supportedPackageManagers = {
const path_1 = __importDefault(__nccwpck_require__(1017)); npm: {
const fs_1 = __importDefault(__nccwpck_require__(7147)); name: 'npm',
const util_1 = __nccwpck_require__(2629); lockFilePatterns: ['package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock'],
exports.supportedPackageManagers = { getCacheFolderPath: () => exports.getCommandOutputNotEmpty('npm config get cache', 'Could not get npm cache folder path')
npm: { },
name: 'npm', pnpm: {
lockFilePatterns: ['package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock'], name: 'pnpm',
getCacheFolderPath: () => (0, exports.getCommandOutputNotEmpty)('npm config get cache', 'Could not get npm cache folder path') lockFilePatterns: ['pnpm-lock.yaml'],
}, getCacheFolderPath: () => exports.getCommandOutputNotEmpty('pnpm store path --silent', 'Could not get pnpm cache folder path')
pnpm: { },
name: 'pnpm', yarn: {
lockFilePatterns: ['pnpm-lock.yaml'], name: 'yarn',
getCacheFolderPath: () => (0, exports.getCommandOutputNotEmpty)('pnpm store path --silent', 'Could not get pnpm cache folder path') lockFilePatterns: ['yarn.lock'],
}, getCacheFolderPath: (projectDir) => __awaiter(void 0, void 0, void 0, function* () {
yarn: { const yarnVersion = yield exports.getCommandOutputNotEmpty(`yarn --version`, 'Could not retrieve version of yarn', projectDir);
name: 'yarn', core.debug(`Consumed yarn version is ${yarnVersion} (working dir: "${projectDir || ''}")`);
lockFilePatterns: ['yarn.lock'], const stdOut = yarnVersion.startsWith('1.')
getCacheFolderPath: (projectDir) => __awaiter(void 0, void 0, void 0, function* () { ? yield exports.getCommandOutput('yarn cache dir', projectDir)
const yarnVersion = yield (0, exports.getCommandOutputNotEmpty)(`yarn --version`, 'Could not retrieve version of yarn', projectDir); : yield exports.getCommandOutput('yarn config get cacheFolder', projectDir);
core.debug(`Consumed yarn version is ${yarnVersion} (working dir: "${projectDir || ''}")`); if (!stdOut) {
const stdOut = yarnVersion.startsWith('1.') throw new Error(`Could not get yarn cache folder path for ${projectDir}`);
? yield (0, exports.getCommandOutput)('yarn cache dir', projectDir) }
: yield (0, exports.getCommandOutput)('yarn config get cacheFolder', projectDir); return stdOut;
if (!stdOut) { })
throw new Error(`Could not get yarn cache folder path for ${projectDir}`); }
} };
return stdOut; const getCommandOutput = (toolCommand, cwd) => __awaiter(void 0, void 0, void 0, function* () {
}) let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, Object.assign({ ignoreReturnCode: true }, (cwd && { cwd })));
} if (exitCode) {
}; stderr = !stderr.trim()
const getCommandOutput = (toolCommand, cwd) => __awaiter(void 0, void 0, void 0, function* () { ? `The '${toolCommand}' command failed with exit code: ${exitCode}`
let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, Object.assign({ ignoreReturnCode: true }, (cwd && { cwd }))); : stderr;
if (exitCode) { throw new Error(stderr);
stderr = !stderr.trim() }
? `The '${toolCommand}' command failed with exit code: ${exitCode}` return stdout.trim();
: stderr; });
throw new Error(stderr); exports.getCommandOutput = getCommandOutput;
} const getCommandOutputNotEmpty = (toolCommand, error, cwd) => __awaiter(void 0, void 0, void 0, function* () {
return stdout.trim(); const stdOut = exports.getCommandOutput(toolCommand, cwd);
}); if (!stdOut) {
exports.getCommandOutput = getCommandOutput; throw new Error(error);
const getCommandOutputNotEmpty = (toolCommand, error, cwd) => __awaiter(void 0, void 0, void 0, function* () { }
const stdOut = (0, exports.getCommandOutput)(toolCommand, cwd); return stdOut;
if (!stdOut) { });
throw new Error(error); exports.getCommandOutputNotEmpty = getCommandOutputNotEmpty;
} const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void 0, function* () {
return stdOut; if (packageManager === 'npm') {
}); return exports.supportedPackageManagers.npm;
exports.getCommandOutputNotEmpty = getCommandOutputNotEmpty; }
const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void 0, function* () { else if (packageManager === 'pnpm') {
if (packageManager === 'npm') { return exports.supportedPackageManagers.pnpm;
return exports.supportedPackageManagers.npm; }
} else if (packageManager === 'yarn') {
else if (packageManager === 'pnpm') { return exports.supportedPackageManagers.yarn;
return exports.supportedPackageManagers.pnpm; }
} else {
else if (packageManager === 'yarn') { return null;
return exports.supportedPackageManagers.yarn; }
} });
else { exports.getPackageManagerInfo = getPackageManagerInfo;
return null; /**
} * getProjectDirectoriesFromCacheDependencyPath is called twice during `restoreCache`
}); * - first through `getCacheDirectories`
exports.getPackageManagerInfo = getPackageManagerInfo; * - second from `repoHasYarn3ManagedCache`
/** *
* getProjectDirectoriesFromCacheDependencyPath is called twice during `restoreCache` * it contains expensive IO operation and thus should be memoized
* - first through `getCacheDirectories` */
* - second from `repoHasYarn3ManagedCache` let projectDirectoriesMemoized = null;
* /**
* it contains expensive IO operation and thus should be memoized * unit test must reset memoized variables
*/ */
let projectDirectoriesMemoized = null; const resetProjectDirectoriesMemoized = () => (projectDirectoriesMemoized = null);
/** exports.resetProjectDirectoriesMemoized = resetProjectDirectoriesMemoized;
* unit test must reset memoized variables /**
*/ * Expands (converts) the string input `cache-dependency-path` to list of directories that
const resetProjectDirectoriesMemoized = () => (projectDirectoriesMemoized = null); * may be project roots
exports.resetProjectDirectoriesMemoized = resetProjectDirectoriesMemoized; * @param cacheDependencyPath - either a single string or multiline string with possible glob patterns
/** * expected to be the result of `core.getInput('cache-dependency-path')`
* Expands (converts) the string input `cache-dependency-path` to list of directories that * @return list of directories and possible
* may be project roots */
* @param cacheDependencyPath - either a single string or multiline string with possible glob patterns const getProjectDirectoriesFromCacheDependencyPath = (cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
* expected to be the result of `core.getInput('cache-dependency-path')` if (projectDirectoriesMemoized !== null) {
* @return list of directories and possible return projectDirectoriesMemoized;
*/ }
const getProjectDirectoriesFromCacheDependencyPath = (cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () { const globber = yield glob.create(cacheDependencyPath);
if (projectDirectoriesMemoized !== null) { const cacheDependenciesPaths = yield globber.glob();
return projectDirectoriesMemoized; const existingDirectories = cacheDependenciesPaths
} .map(path_1.default.dirname)
const globber = yield glob.create(cacheDependencyPath); .filter(util_1.unique())
const cacheDependenciesPaths = yield globber.glob(); .map(dirName => fs_1.default.realpathSync(dirName))
const existingDirectories = cacheDependenciesPaths .filter(directory => fs_1.default.lstatSync(directory).isDirectory());
.map(path_1.default.dirname) if (!existingDirectories.length)
.filter((0, util_1.unique)()) core.warning(`No existing directories found containing cache-dependency-path="${cacheDependencyPath}"`);
.map(dirName => fs_1.default.realpathSync(dirName)) projectDirectoriesMemoized = existingDirectories;
.filter(directory => fs_1.default.lstatSync(directory).isDirectory()); return existingDirectories;
if (!existingDirectories.length) });
core.warning(`No existing directories found containing cache-dependency-path="${cacheDependencyPath}"`); /**
projectDirectoriesMemoized = existingDirectories; * Finds the cache directories configured for the repo if cache-dependency-path is not empty
return existingDirectories; * @param packageManagerInfo - an object having getCacheFolderPath method specific to given PM
}); * @param cacheDependencyPath - either a single string or multiline string with possible glob patterns
/** * expected to be the result of `core.getInput('cache-dependency-path')`
* Finds the cache directories configured for the repo if cache-dependency-path is not empty * @return list of files on which the cache depends
* @param packageManagerInfo - an object having getCacheFolderPath method specific to given PM */
* @param cacheDependencyPath - either a single string or multiline string with possible glob patterns const getCacheDirectoriesFromCacheDependencyPath = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
* expected to be the result of `core.getInput('cache-dependency-path')` const projectDirectories = yield getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath);
* @return list of files on which the cache depends const cacheFoldersPaths = yield Promise.all(projectDirectories.map((projectDirectory) => __awaiter(void 0, void 0, void 0, function* () {
*/ const cacheFolderPath = yield packageManagerInfo.getCacheFolderPath(projectDirectory);
const getCacheDirectoriesFromCacheDependencyPath = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () { core.debug(`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the directory "${projectDirectory}"`);
const projectDirectories = yield getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath); return cacheFolderPath;
const cacheFoldersPaths = yield Promise.all(projectDirectories.map((projectDirectory) => __awaiter(void 0, void 0, void 0, function* () { })));
const cacheFolderPath = yield packageManagerInfo.getCacheFolderPath(projectDirectory); // uniq in order to do not cache the same directories twice
core.debug(`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the directory "${projectDirectory}"`); return cacheFoldersPaths.filter(util_1.unique());
return cacheFolderPath; });
}))); /**
// uniq in order to do not cache the same directories twice * Finds the cache directories configured for the repo ignoring cache-dependency-path
return cacheFoldersPaths.filter((0, util_1.unique)()); * @param packageManagerInfo - an object having getCacheFolderPath method specific to given PM
}); * @return list of files on which the cache depends
/** */
* Finds the cache directories configured for the repo ignoring cache-dependency-path const getCacheDirectoriesForRootProject = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
* @param packageManagerInfo - an object having getCacheFolderPath method specific to given PM const cacheFolderPath = yield packageManagerInfo.getCacheFolderPath();
* @return list of files on which the cache depends core.debug(`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the root directory`);
*/ return [cacheFolderPath];
const getCacheDirectoriesForRootProject = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () { });
const cacheFolderPath = yield packageManagerInfo.getCacheFolderPath(); /**
core.debug(`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the root directory`); * A function to find the cache directories configured for the repo
return [cacheFolderPath]; * currently it handles only the case of PM=yarn && cacheDependencyPath is not empty
}); * @param packageManagerInfo - an object having getCacheFolderPath method specific to given PM
/** * @param cacheDependencyPath - either a single string or multiline string with possible glob patterns
* A function to find the cache directories configured for the repo * expected to be the result of `core.getInput('cache-dependency-path')`
* currently it handles only the case of PM=yarn && cacheDependencyPath is not empty * @return list of files on which the cache depends
* @param packageManagerInfo - an object having getCacheFolderPath method specific to given PM */
* @param cacheDependencyPath - either a single string or multiline string with possible glob patterns const getCacheDirectories = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
* expected to be the result of `core.getInput('cache-dependency-path')` // For yarn, if cacheDependencyPath is set, ask information about cache folders in each project
* @return list of files on which the cache depends // folder satisfied by cacheDependencyPath https://github.com/actions/setup-node/issues/488
*/ if (packageManagerInfo.name === 'yarn' && cacheDependencyPath) {
const getCacheDirectories = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () { return getCacheDirectoriesFromCacheDependencyPath(packageManagerInfo, cacheDependencyPath);
// For yarn, if cacheDependencyPath is set, ask information about cache folders in each project }
// folder satisfied by cacheDependencyPath https://github.com/actions/setup-node/issues/488 return getCacheDirectoriesForRootProject(packageManagerInfo);
if (packageManagerInfo.name === 'yarn' && cacheDependencyPath) { });
return getCacheDirectoriesFromCacheDependencyPath(packageManagerInfo, cacheDependencyPath); exports.getCacheDirectories = getCacheDirectories;
} /**
return getCacheDirectoriesForRootProject(packageManagerInfo); * A function to check if the directory is a yarn project configured to manage
}); * obsolete dependencies in the local cache
exports.getCacheDirectories = getCacheDirectories; * @param directory - a path to the folder
/** * @return - true if the directory's project is yarn managed
* A function to check if the directory is a yarn project configured to manage * - if there's .yarn/cache folder do not mess with the dependencies kept in the repo, return false
* obsolete dependencies in the local cache * - global cache is not managed by yarn @see https://yarnpkg.com/features/offline-cache, return false
* @param directory - a path to the folder * - if local cache is not explicitly enabled (not yarn3), return false
* @return - true if the directory's project is yarn managed * - return true otherwise
* - if there's .yarn/cache folder do not mess with the dependencies kept in the repo, return false */
* - global cache is not managed by yarn @see https://yarnpkg.com/features/offline-cache, return false const projectHasYarnBerryManagedDependencies = (directory) => __awaiter(void 0, void 0, void 0, function* () {
* - if local cache is not explicitly enabled (not yarn3), return false const workDir = directory || process.env.GITHUB_WORKSPACE || '.';
* - return true otherwise core.debug(`check if "${workDir}" has locally managed yarn3 dependencies`);
*/ // if .yarn/cache directory exists the cache is managed by version control system
const projectHasYarnBerryManagedDependencies = (directory) => __awaiter(void 0, void 0, void 0, function* () { const yarnCacheFile = path_1.default.join(workDir, '.yarn', 'cache');
const workDir = directory || process.env.GITHUB_WORKSPACE || '.'; if (fs_1.default.existsSync(yarnCacheFile) &&
core.debug(`check if "${workDir}" has locally managed yarn3 dependencies`); fs_1.default.lstatSync(yarnCacheFile).isDirectory()) {
// if .yarn/cache directory exists the cache is managed by version control system core.debug(`"${workDir}" has .yarn/cache - dependencies are kept in the repository`);
const yarnCacheFile = path_1.default.join(workDir, '.yarn', 'cache'); return Promise.resolve(false);
if (fs_1.default.existsSync(yarnCacheFile) && }
fs_1.default.lstatSync(yarnCacheFile).isDirectory()) { // NOTE: yarn1 returns 'undefined' with return code = 0
core.debug(`"${workDir}" has .yarn/cache - dependencies are kept in the repository`); const enableGlobalCache = yield exports.getCommandOutput('yarn config get enableGlobalCache', workDir);
return Promise.resolve(false); // only local cache is not managed by yarn
} const managed = enableGlobalCache.includes('false');
// NOTE: yarn1 returns 'undefined' with return code = 0 if (managed) {
const enableGlobalCache = yield (0, exports.getCommandOutput)('yarn config get enableGlobalCache', workDir); core.debug(`"${workDir}" dependencies are managed by yarn 3 locally`);
// only local cache is not managed by yarn return true;
const managed = enableGlobalCache.includes('false'); }
if (managed) { else {
core.debug(`"${workDir}" dependencies are managed by yarn 3 locally`); core.debug(`"${workDir}" dependencies are not managed by yarn 3 locally`);
return true; return false;
} }
else { });
core.debug(`"${workDir}" dependencies are not managed by yarn 3 locally`); /**
return false; * A function to report the repo contains Yarn managed projects
} * @param packageManagerInfo - used to make sure current package manager is yarn
}); * @param cacheDependencyPath - either a single string or multiline string with possible glob patterns
/** * expected to be the result of `core.getInput('cache-dependency-path')`
* A function to report the repo contains Yarn managed projects * @return - true if all project directories configured to be Yarn managed
* @param packageManagerInfo - used to make sure current package manager is yarn */
* @param cacheDependencyPath - either a single string or multiline string with possible glob patterns const repoHasYarnBerryManagedDependencies = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
* expected to be the result of `core.getInput('cache-dependency-path')` if (packageManagerInfo.name !== 'yarn')
* @return - true if all project directories configured to be Yarn managed return false;
*/ const yarnDirs = cacheDependencyPath
const repoHasYarnBerryManagedDependencies = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () { ? yield getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath)
if (packageManagerInfo.name !== 'yarn') : [''];
return false; const isManagedList = yield Promise.all(yarnDirs.map(projectHasYarnBerryManagedDependencies));
const yarnDirs = cacheDependencyPath return isManagedList.every(Boolean);
? yield getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath) });
: ['']; exports.repoHasYarnBerryManagedDependencies = repoHasYarnBerryManagedDependencies;
const isManagedList = yield Promise.all(yarnDirs.map(projectHasYarnBerryManagedDependencies)); function isGhes() {
return isManagedList.every(Boolean); const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
}); return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
exports.repoHasYarnBerryManagedDependencies = repoHasYarnBerryManagedDependencies; }
function isGhes() { exports.isGhes = isGhes;
const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com'); function isCacheFeatureAvailable() {
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; if (cache.isFeatureAvailable())
} return true;
exports.isGhes = isGhes; if (isGhes()) {
function isCacheFeatureAvailable() { core.warning('Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.');
if (cache.isFeatureAvailable()) return false;
return true; }
if (isGhes()) { core.warning('The runner was not able to contact the cache service. Caching will be skipped');
core.warning('Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.'); return false;
return false; }
} exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
core.warning('The runner was not able to contact the cache service. Caching will be skipped');
return false;
}
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
/***/ }), /***/ }),
@ -60684,26 +60676,26 @@ exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
/***/ ((__unused_webpack_module, exports) => { /***/ ((__unused_webpack_module, exports) => {
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.Outputs = exports.State = exports.LockType = void 0; exports.Outputs = exports.State = exports.LockType = void 0;
var LockType; var LockType;
(function (LockType) { (function (LockType) {
LockType["Npm"] = "npm"; LockType["Npm"] = "npm";
LockType["Pnpm"] = "pnpm"; LockType["Pnpm"] = "pnpm";
LockType["Yarn"] = "yarn"; LockType["Yarn"] = "yarn";
})(LockType = exports.LockType || (exports.LockType = {})); })(LockType = exports.LockType || (exports.LockType = {}));
var State; var State;
(function (State) { (function (State) {
State["CachePackageManager"] = "SETUP_NODE_CACHE_PACKAGE_MANAGER"; State["CachePackageManager"] = "SETUP_NODE_CACHE_PACKAGE_MANAGER";
State["CachePrimaryKey"] = "CACHE_KEY"; State["CachePrimaryKey"] = "CACHE_KEY";
State["CacheMatchedKey"] = "CACHE_RESULT"; State["CacheMatchedKey"] = "CACHE_RESULT";
State["CachePaths"] = "CACHE_PATHS"; State["CachePaths"] = "CACHE_PATHS";
})(State = exports.State || (exports.State = {})); })(State = exports.State || (exports.State = {}));
var Outputs; var Outputs;
(function (Outputs) { (function (Outputs) {
Outputs["CacheHit"] = "cache-hit"; Outputs["CacheHit"] = "cache-hit";
})(Outputs = exports.Outputs || (exports.Outputs = {})); })(Outputs = exports.Outputs || (exports.Outputs = {}));
/***/ }), /***/ }),
@ -60712,112 +60704,108 @@ var Outputs;
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict"; "use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k; if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k); Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { }) : (function(o, m, k, k2) {
desc = { enumerable: true, get: function() { return m[k]; } }; if (k2 === undefined) k2 = k;
} o[k2] = m[k];
Object.defineProperty(o, k2, desc); }));
}) : (function(o, m, k, k2) { var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
if (k2 === undefined) k2 = k; Object.defineProperty(o, "default", { enumerable: true, value: v });
o[k2] = m[k]; }) : function(o, v) {
})); o["default"] = v;
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { });
Object.defineProperty(o, "default", { enumerable: true, value: v }); var __importStar = (this && this.__importStar) || function (mod) {
}) : function(o, v) { if (mod && mod.__esModule) return mod;
o["default"] = v; var result = {};
}); if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
var __importStar = (this && this.__importStar) || function (mod) { __setModuleDefault(result, mod);
if (mod && mod.__esModule) return mod; return result;
var result = {}; };
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
__setModuleDefault(result, mod); function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return result; return new (P || (P = Promise))(function (resolve, reject) {
}; function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
return new (P || (P = Promise))(function (resolve, reject) { step((generator = generator.apply(thisArg, _arguments || [])).next());
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } });
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } };
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } Object.defineProperty(exports, "__esModule", ({ value: true }));
step((generator = generator.apply(thisArg, _arguments || [])).next()); exports.unique = exports.printEnvDetailsAndSetOutput = exports.parseNodeVersionFile = void 0;
}); const core = __importStar(__nccwpck_require__(2186));
}; const exec = __importStar(__nccwpck_require__(1514));
Object.defineProperty(exports, "__esModule", ({ value: true })); function parseNodeVersionFile(contents) {
exports.unique = exports.printEnvDetailsAndSetOutput = exports.parseNodeVersionFile = void 0; var _a, _b, _c;
const core = __importStar(__nccwpck_require__(2186)); let nodeVersion;
const exec = __importStar(__nccwpck_require__(1514)); // Try parsing the file as an NPM `package.json` file.
function parseNodeVersionFile(contents) { try {
var _a, _b, _c; nodeVersion = (_a = JSON.parse(contents).volta) === null || _a === void 0 ? void 0 : _a.node;
let nodeVersion; if (!nodeVersion)
// Try parsing the file as an NPM `package.json` file. nodeVersion = (_b = JSON.parse(contents).engines) === null || _b === void 0 ? void 0 : _b.node;
try { }
nodeVersion = (_a = JSON.parse(contents).volta) === null || _a === void 0 ? void 0 : _a.node; catch (_d) {
if (!nodeVersion) core.info('Node version file is not JSON file');
nodeVersion = (_b = JSON.parse(contents).engines) === null || _b === void 0 ? void 0 : _b.node; }
} if (!nodeVersion) {
catch (_d) { const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
core.info('Node version file is not JSON file'); nodeVersion = (_c = found === null || found === void 0 ? void 0 : found.groups) === null || _c === void 0 ? void 0 : _c.version;
} }
if (!nodeVersion) { // In the case of an unknown format,
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m); // return as is and evaluate the version separately.
nodeVersion = (_c = found === null || found === void 0 ? void 0 : found.groups) === null || _c === void 0 ? void 0 : _c.version; if (!nodeVersion)
} nodeVersion = contents.trim();
// In the case of an unknown format, return nodeVersion;
// return as is and evaluate the version separately. }
if (!nodeVersion) exports.parseNodeVersionFile = parseNodeVersionFile;
nodeVersion = contents.trim(); function printEnvDetailsAndSetOutput() {
return nodeVersion; return __awaiter(this, void 0, void 0, function* () {
} core.startGroup('Environment details');
exports.parseNodeVersionFile = parseNodeVersionFile; const promises = ['node', 'npm', 'yarn'].map((tool) => __awaiter(this, void 0, void 0, function* () {
function printEnvDetailsAndSetOutput() { const output = yield getToolVersion(tool, ['--version']);
return __awaiter(this, void 0, void 0, function* () { return { tool, output };
core.startGroup('Environment details'); }));
const promises = ['node', 'npm', 'yarn'].map((tool) => __awaiter(this, void 0, void 0, function* () { const tools = yield Promise.all(promises);
const output = yield getToolVersion(tool, ['--version']); tools.forEach(({ tool, output }) => {
return { tool, output }; if (tool === 'node') {
})); core.setOutput(`${tool}-version`, output);
const tools = yield Promise.all(promises); }
tools.forEach(({ tool, output }) => { core.info(`${tool}: ${output}`);
if (tool === 'node') { });
core.setOutput(`${tool}-version`, output); core.endGroup();
} });
core.info(`${tool}: ${output}`); }
}); exports.printEnvDetailsAndSetOutput = printEnvDetailsAndSetOutput;
core.endGroup(); function getToolVersion(tool, options) {
}); return __awaiter(this, void 0, void 0, function* () {
} try {
exports.printEnvDetailsAndSetOutput = printEnvDetailsAndSetOutput; const { stdout, stderr, exitCode } = yield exec.getExecOutput(tool, options, {
function getToolVersion(tool, options) { ignoreReturnCode: true,
return __awaiter(this, void 0, void 0, function* () { silent: true
try { });
const { stdout, stderr, exitCode } = yield exec.getExecOutput(tool, options, { if (exitCode > 0) {
ignoreReturnCode: true, core.info(`[warning]${stderr}`);
silent: true return '';
}); }
if (exitCode > 0) { return stdout.trim();
core.info(`[warning]${stderr}`); }
return ''; catch (err) {
} return '';
return stdout.trim(); }
} });
catch (err) { }
return ''; const unique = () => {
} const encountered = new Set();
}); return (value) => {
} if (encountered.has(value))
const unique = () => { return false;
const encountered = new Set(); encountered.add(value);
return (value) => { return true;
if (encountered.has(value)) };
return false; };
encountered.add(value); exports.unique = unique;
return true;
};
};
exports.unique = unique;
/***/ }), /***/ }),

3660
dist/setup/index.js vendored

File diff suppressed because it is too large Load Diff

5428
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -37,22 +37,22 @@
"uuid": "^9.0.0" "uuid": "^9.0.0"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^29.5.6", "@types/jest": "^27.0.2",
"@types/node": "^16.11.25", "@types/node": "^16.11.25",
"@types/semver": "^6.0.0", "@types/semver": "^6.0.0",
"@types/uuid": "^9.0.3", "@types/uuid": "^9.0.3",
"@typescript-eslint/eslint-plugin": "^5.54.0", "@typescript-eslint/eslint-plugin": "^5.54.0",
"@typescript-eslint/parser": "^5.54.0", "@typescript-eslint/parser": "^5.54.0",
"@vercel/ncc": "^0.38.0", "@vercel/ncc": "^0.33.4",
"eslint": "^8.35.0", "eslint": "^8.35.0",
"eslint-config-prettier": "^8.6.0", "eslint-config-prettier": "^8.6.0",
"eslint-plugin-jest": "^27.2.1", "eslint-plugin-jest": "^27.2.1",
"eslint-plugin-node": "^11.1.0", "eslint-plugin-node": "^11.1.0",
"jest": "^29.7.0", "jest": "^27.2.5",
"jest-circus": "^29.7.0", "jest-circus": "^27.2.5",
"jest-each": "^29.7.0", "jest-each": "^27.2.5",
"prettier": "^2.8.4", "prettier": "^2.8.4",
"ts-jest": "^29.1.1", "ts-jest": "^27.0.5",
"typescript": "^4.2.3" "typescript": "^4.2.3"
} }
} }

View File

@ -17,7 +17,7 @@ export async function run() {
const cacheLock = core.getState(State.CachePackageManager); const cacheLock = core.getState(State.CachePackageManager);
await cachePackages(cacheLock); await cachePackages(cacheLock);
} catch (error) { } catch (error) {
core.setFailed((error as Error).message); core.setFailed(error.message);
} }
} }

View File

@ -18,7 +18,6 @@ export default class OfficialBuilds extends BaseDistribution {
let manifest: tc.IToolRelease[] | undefined; let manifest: tc.IToolRelease[] | undefined;
let nodeJsVersions: INodeVersion[] | undefined; let nodeJsVersions: INodeVersion[] | undefined;
const osArch = this.translateArchToDistUrl(this.nodeInfo.arch); const osArch = this.translateArchToDistUrl(this.nodeInfo.arch);
if (this.isLtsAlias(this.nodeInfo.versionSpec)) { if (this.isLtsAlias(this.nodeInfo.versionSpec)) {
core.info('Attempt to resolve LTS alias from manifest...'); core.info('Attempt to resolve LTS alias from manifest...');
@ -62,57 +61,63 @@ export default class OfficialBuilds extends BaseDistribution {
if (toolPath) { if (toolPath) {
core.info(`Found in cache @ ${toolPath}`); core.info(`Found in cache @ ${toolPath}`);
this.addToolPath(toolPath); } else {
return; let downloadPath = '';
} try {
core.info(`Attempting to download ${this.nodeInfo.versionSpec}...`);
let downloadPath = ''; const versionInfo = await this.getInfoFromManifest(
try { this.nodeInfo.versionSpec,
core.info(`Attempting to download ${this.nodeInfo.versionSpec}...`); this.nodeInfo.stable,
osArch,
const versionInfo = await this.getInfoFromManifest( manifest
this.nodeInfo.versionSpec,
this.nodeInfo.stable,
osArch,
manifest
);
if (versionInfo) {
core.info(
`Acquiring ${versionInfo.resolvedVersion} - ${versionInfo.arch} from ${versionInfo.downloadUrl}`
);
downloadPath = await tc.downloadTool(
versionInfo.downloadUrl,
undefined,
this.nodeInfo.auth
); );
if (versionInfo) {
core.info(
`Acquiring ${versionInfo.resolvedVersion} - ${versionInfo.arch} from ${versionInfo.downloadUrl}`
);
downloadPath = await tc.downloadTool(
versionInfo.downloadUrl,
undefined,
this.nodeInfo.auth
);
if (downloadPath) { if (downloadPath) {
toolPath = await this.extractArchive(downloadPath, versionInfo); toolPath = await this.extractArchive(downloadPath, versionInfo);
}
} else {
core.info(
'Not found in manifest. Falling back to download directly from Node'
);
} }
} else { } catch (err) {
core.info( // Rate limit?
'Not found in manifest. Falling back to download directly from Node' if (
); err instanceof tc.HTTPError &&
(err.httpStatusCode === 403 || err.httpStatusCode === 429)
) {
core.info(
`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`
);
} else {
core.info(err.message);
}
core.debug(err.stack);
core.info('Falling back to download directly from Node');
} }
} catch (err) {
// Rate limit?
if (
err instanceof tc.HTTPError &&
(err.httpStatusCode === 403 || err.httpStatusCode === 429)
) {
core.info(
`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`
);
} else {
core.info((err as Error).message);
}
core.debug((err as Error).stack ?? 'empty stack');
core.info('Falling back to download directly from Node');
}
if (!toolPath) { if (!toolPath) {
toolPath = await this.downloadDirectlyFromNode(); const nodeJsVersions = await this.getNodeJsVersions();
const versions = this.filterVersions(nodeJsVersions);
const evaluatedVersion = this.evaluateVersions(versions);
if (!evaluatedVersion) {
throw new Error(
`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`
);
}
const toolName = this.getNodejsDistInfo(evaluatedVersion);
toolPath = await this.downloadNodejs(toolName);
}
} }
if (this.osPlat != 'win32') { if (this.osPlat != 'win32') {
@ -122,43 +127,6 @@ export default class OfficialBuilds extends BaseDistribution {
core.addPath(toolPath); core.addPath(toolPath);
} }
protected addToolPath(toolPath: string) {
if (this.osPlat != 'win32') {
toolPath = path.join(toolPath, 'bin');
}
core.addPath(toolPath);
}
protected async downloadDirectlyFromNode() {
const nodeJsVersions = await this.getNodeJsVersions();
const versions = this.filterVersions(nodeJsVersions);
const evaluatedVersion = this.evaluateVersions(versions);
if (!evaluatedVersion) {
throw new Error(
`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`
);
}
const toolName = this.getNodejsDistInfo(evaluatedVersion);
try {
const toolPath = await this.downloadNodejs(toolName);
return toolPath;
} catch (error) {
if (error instanceof tc.HTTPError && error.httpStatusCode === 404) {
core.warning(
`Node version ${this.nodeInfo.versionSpec} for platform ${this.osPlat} and architecture ${this.nodeInfo.arch} was found but failed to download. ` +
'This usually happens when downloadable binaries are not fully updated at https://nodejs.org/. ' +
'To resolve this issue you may either fall back to the older version or try again later.'
);
}
throw error;
}
}
protected evaluateVersions(versions: string[]): string { protected evaluateVersions(versions: string[]): string {
let version = ''; let version = '';
@ -246,7 +214,7 @@ export default class OfficialBuilds extends BaseDistribution {
return info?.resolvedVersion; return info?.resolvedVersion;
} catch (err) { } catch (err) {
core.info('Unable to resolve version from manifest...'); core.info('Unable to resolve version from manifest...');
core.debug((err as Error).message); core.debug(err.message);
} }
} }

View File

@ -75,7 +75,7 @@ export async function run() {
`##[add-matcher]${path.join(matchersPath, 'eslint-compact.json')}` `##[add-matcher]${path.join(matchersPath, 'eslint-compact.json')}`
); );
} catch (err) { } catch (err) {
core.setFailed((err as Error).message); core.setFailed(err.message);
} }
} }