Merge branch 'main' of github.com:actions/setup-node into main

This commit is contained in:
Andres Vargas
2020-12-15 11:52:46 -06:00
10 changed files with 226 additions and 49 deletions

58
dist/index.js vendored
View File

@ -4694,6 +4694,7 @@ const installer = __importStar(__webpack_require__(749));
const auth = __importStar(__webpack_require__(202));
const path = __importStar(__webpack_require__(622));
const url_1 = __webpack_require__(835);
const os = __webpack_require__(87);
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
@ -4705,12 +4706,21 @@ function run() {
if (!version) {
version = core.getInput('version');
}
let arch = core.getInput('architecture');
// if architecture supplied but node-version is not
// if we don't throw a warning, the already installed x64 node will be used which is not probably what user meant.
if (arch && !version) {
core.warning('`architecture` is provided but `node-version` is missing. In this configuration, the version/architecture of Node will not be changed. To fix this, provide `architecture` in combination with `node-version`');
}
if (!arch) {
arch = os.arch();
}
if (version) {
let token = core.getInput('token');
let auth = !token || isGhes() ? undefined : `token ${token}`;
let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
const checkLatest = (core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE';
yield installer.getNode(version, stable, checkLatest, auth);
yield installer.getNode(version, stable, checkLatest, auth, arch);
}
const registryUrl = core.getInput('registry-url');
const alwaysAuth = core.getInput('always-auth');
@ -13093,13 +13103,13 @@ const tc = __importStar(__webpack_require__(533));
const path = __importStar(__webpack_require__(622));
const semver = __importStar(__webpack_require__(280));
const fs = __webpack_require__(747);
function getNode(versionSpec, stable, checkLatest, auth) {
function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) {
return __awaiter(this, void 0, void 0, function* () {
let osPlat = os.platform();
let osArch = translateArchToDistUrl(os.arch());
let osArch = translateArchToDistUrl(arch);
if (checkLatest) {
core.info('Attempt to resolve the latest version from manifest...');
const resolvedVersion = yield resolveVersionFromManifest(versionSpec, stable, auth);
const resolvedVersion = yield resolveVersionFromManifest(versionSpec, stable, auth, osArch);
if (resolvedVersion) {
versionSpec = resolvedVersion;
core.info(`Resolved as '${versionSpec}'`);
@ -13110,7 +13120,7 @@ function getNode(versionSpec, stable, checkLatest, auth) {
}
// check cache
let toolPath;
toolPath = tc.find('node', versionSpec);
toolPath = tc.find('node', versionSpec, osArch);
// If not found in cache, download
if (toolPath) {
core.info(`Found in cache @ ${toolPath}`);
@ -13123,9 +13133,9 @@ function getNode(versionSpec, stable, checkLatest, auth) {
// Try download from internal distribution (popular versions only)
//
try {
info = yield getInfoFromManifest(versionSpec, stable, auth);
info = yield getInfoFromManifest(versionSpec, stable, auth, osArch);
if (info) {
core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
core.info(`Acquiring ${info.resolvedVersion} - ${info.arch} from ${info.downloadUrl}`);
downloadPath = yield tc.downloadTool(info.downloadUrl, undefined, auth);
}
else {
@ -13148,17 +13158,17 @@ function getNode(versionSpec, stable, checkLatest, auth) {
// Download from nodejs.org
//
if (!downloadPath) {
info = yield getInfoFromDist(versionSpec);
info = yield getInfoFromDist(versionSpec, arch);
if (!info) {
throw new Error(`Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`);
}
core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
core.info(`Acquiring ${info.resolvedVersion} - ${info.arch} from ${info.downloadUrl}`);
try {
downloadPath = yield tc.downloadTool(info.downloadUrl);
}
catch (err) {
if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
return yield acquireNodeFromFallbackLocation(info.resolvedVersion);
return yield acquireNodeFromFallbackLocation(info.resolvedVersion, info.arch);
}
throw err;
}
@ -13189,7 +13199,7 @@ function getNode(versionSpec, stable, checkLatest, auth) {
// Install into the local tool cache - node extracts with a root folder that matches the fileName downloaded
//
core.info('Adding to the cache ...');
toolPath = yield tc.cacheDir(extPath, 'node', info.resolvedVersion);
toolPath = yield tc.cacheDir(extPath, 'node', info.resolvedVersion, info.arch);
core.info('Done');
}
//
@ -13206,26 +13216,27 @@ function getNode(versionSpec, stable, checkLatest, auth) {
});
}
exports.getNode = getNode;
function getInfoFromManifest(versionSpec, stable, auth) {
function getInfoFromManifest(versionSpec, stable, auth, osArch = translateArchToDistUrl(os.arch())) {
return __awaiter(this, void 0, void 0, function* () {
let info = null;
const releases = yield tc.getManifestFromRepo('actions', 'node-versions', auth, 'main');
const rel = yield tc.findFromManifest(versionSpec, stable, releases);
const rel = yield tc.findFromManifest(versionSpec, stable, releases, osArch);
if (rel && rel.files.length > 0) {
info = {};
info.resolvedVersion = rel.version;
info.arch = rel.files[0].arch;
info.downloadUrl = rel.files[0].download_url;
info.fileName = rel.files[0].filename;
}
return info;
});
}
function getInfoFromDist(versionSpec) {
function getInfoFromDist(versionSpec, arch = os.arch()) {
return __awaiter(this, void 0, void 0, function* () {
let osPlat = os.platform();
let osArch = translateArchToDistUrl(os.arch());
let osArch = translateArchToDistUrl(arch);
let version;
version = yield queryDistForMatch(versionSpec);
version = yield queryDistForMatch(versionSpec, arch);
if (!version) {
return null;
}
@ -13241,14 +13252,15 @@ function getInfoFromDist(versionSpec) {
return {
downloadUrl: url,
resolvedVersion: version,
arch: arch,
fileName: fileName
};
});
}
function resolveVersionFromManifest(versionSpec, stable, auth) {
function resolveVersionFromManifest(versionSpec, stable, auth, osArch = translateArchToDistUrl(os.arch())) {
return __awaiter(this, void 0, void 0, function* () {
try {
const info = yield getInfoFromManifest(versionSpec, stable, auth);
const info = yield getInfoFromManifest(versionSpec, stable, auth, osArch);
return info === null || info === void 0 ? void 0 : info.resolvedVersion;
}
catch (err) {
@ -13283,10 +13295,10 @@ function evaluateVersions(versions, versionSpec) {
}
return version;
}
function queryDistForMatch(versionSpec) {
function queryDistForMatch(versionSpec, arch = os.arch()) {
return __awaiter(this, void 0, void 0, function* () {
let osPlat = os.platform();
let osArch = translateArchToDistUrl(os.arch());
let osArch = translateArchToDistUrl(arch);
// node offers a json list of versions
let dataFileName;
switch (osPlat) {
@ -13339,10 +13351,10 @@ exports.getVersionsFromDist = getVersionsFromDist;
// This method attempts to download and cache the resources from these alternative locations.
// Note also that the files are normally zipped but in this case they are just an exe
// and lib file in a folder, not zipped.
function acquireNodeFromFallbackLocation(version) {
function acquireNodeFromFallbackLocation(version, arch = os.arch()) {
return __awaiter(this, void 0, void 0, function* () {
let osPlat = os.platform();
let osArch = translateArchToDistUrl(os.arch());
let osArch = translateArchToDistUrl(arch);
// Create temporary folder to download in to
const tempDownloadFolder = 'temp_' + Math.floor(Math.random() * 2000000000);
const tempDirectory = process.env['RUNNER_TEMP'] || '';
@ -13373,7 +13385,7 @@ function acquireNodeFromFallbackLocation(version) {
throw err;
}
}
let toolPath = yield tc.cacheDir(tempDir, 'node', version);
let toolPath = yield tc.cacheDir(tempDir, 'node', version, arch);
core.addPath(toolPath);
return toolPath;
});