Expose the ability to select different architectures

This commit is contained in:
Tyler Ang-Wanek 2019-08-22 13:21:46 -07:00
parent e565252a9d
commit 3d0361d465
No known key found for this signature in database
GPG key ID: DED1387F8E0A5146
7 changed files with 84 additions and 35 deletions

View file

@ -25,7 +25,6 @@ const os = __importStar(require("os"));
const path = __importStar(require("path"));
const semver = __importStar(require("semver"));
let osPlat = os.platform();
let osArch = os.arch();
if (!tempDirectory) {
let baseLocation;
if (process.platform === 'win32') {
@ -42,11 +41,11 @@ if (!tempDirectory) {
}
tempDirectory = path.join(baseLocation, 'actions', 'temp');
}
function getNode(versionSpec) {
function getNode(versionSpec, osArch = os.arch()) {
return __awaiter(this, void 0, void 0, function* () {
// check cache
let toolPath;
toolPath = tc.find('node', versionSpec);
toolPath = tc.find('node', versionSpec, osArch);
// If not found in cache, download
if (!toolPath) {
let version;
@ -58,16 +57,16 @@ function getNode(versionSpec) {
}
else {
// query nodejs.org for a matching version
version = yield queryLatestMatch(versionSpec);
version = yield queryLatestMatch(versionSpec, osArch);
if (!version) {
throw new Error(`Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`);
}
// check cache
toolPath = tc.find('node', version);
toolPath = tc.find('node', version, osArch);
}
if (!toolPath) {
// download, extract, cache
toolPath = yield acquireNode(version);
toolPath = yield acquireNode(version, osArch);
}
}
//
@ -84,7 +83,7 @@ function getNode(versionSpec) {
});
}
exports.getNode = getNode;
function queryLatestMatch(versionSpec) {
function queryLatestMatch(versionSpec, osArch) {
return __awaiter(this, void 0, void 0, function* () {
// node offers a json list of versions
let dataFileName;
@ -142,15 +141,15 @@ function evaluateVersions(versions, versionSpec) {
}
return version;
}
function acquireNode(version) {
function acquireNode(version, osArch) {
return __awaiter(this, void 0, void 0, function* () {
//
// Download - a tool installer intimately knows how to get the tool (and construct urls)
//
version = semver.clean(version) || '';
let fileName = osPlat == 'win32'
? 'node-v' + version + '-win-' + os.arch()
: 'node-v' + version + '-' + osPlat + '-' + os.arch();
? 'node-v' + version + '-win-' + osArch
: 'node-v' + version + '-' + osPlat + '-' + osArch;
let urlFileName = osPlat == 'win32' ? fileName + '.7z' : fileName + '.tar.gz';
let downloadUrl = 'https://nodejs.org/dist/v' + version + '/' + urlFileName;
let downloadPath;
@ -159,7 +158,7 @@ function acquireNode(version) {
}
catch (err) {
if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
return yield acquireNodeFromFallbackLocation(version);
return yield acquireNodeFromFallbackLocation(version, osArch);
}
throw err;
}
@ -178,7 +177,7 @@ function acquireNode(version) {
// Install into the local tool cache - node extracts with a root folder that matches the fileName downloaded
//
let toolRoot = path.join(extPath, fileName);
return yield tc.cacheDir(toolRoot, 'node', version);
return yield tc.cacheDir(toolRoot, 'node', version, osArch);
});
}
// For non LTS versions of Node, the files we need (for Windows) are sometimes located
@ -193,7 +192,7 @@ function acquireNode(version) {
// 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, osArch) {
return __awaiter(this, void 0, void 0, function* () {
// Create temporary folder to download in to
let tempDownloadFolder = 'temp_' + Math.floor(Math.random() * 2000000000);
@ -202,8 +201,8 @@ function acquireNodeFromFallbackLocation(version) {
let exeUrl;
let libUrl;
try {
exeUrl = `https://nodejs.org/dist/v${version}/win-${os.arch()}/node.exe`;
libUrl = `https://nodejs.org/dist/v${version}/win-${os.arch()}/node.lib`;
exeUrl = `https://nodejs.org/dist/v${version}/win-${osArch}/node.exe`;
libUrl = `https://nodejs.org/dist/v${version}/win-${osArch}/node.lib`;
const exePath = yield tc.downloadTool(exeUrl);
yield io.cp(exePath, path.join(tempDir, 'node.exe'));
const libPath = yield tc.downloadTool(libUrl);
@ -222,6 +221,6 @@ function acquireNodeFromFallbackLocation(version) {
throw err;
}
}
return yield tc.cacheDir(tempDir, 'node', version);
return yield tc.cacheDir(tempDir, 'node', version, osArch);
});
}