Skip to content

Commit 9a99bb3

Browse files
author
David Kale
authored
Merge pull request #88 from actions/arm-installer
Get correct url for arm dist
2 parents 6ecfd2d + 93313ca commit 9a99bb3

File tree

2 files changed

+44
-21
lines changed

2 files changed

+44
-21
lines changed

lib/installer.js

+20-10
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const os = __importStar(require("os"));
2525
const path = __importStar(require("path"));
2626
const semver = __importStar(require("semver"));
2727
let osPlat = os.platform();
28-
let osArch = os.arch();
28+
let osArch = translateArchToDistUrl(os.arch());
2929
if (!tempDirectory) {
3030
let baseLocation;
3131
if (process.platform === 'win32') {
@@ -90,13 +90,13 @@ function queryLatestMatch(versionSpec) {
9090
let dataFileName;
9191
switch (osPlat) {
9292
case 'linux':
93-
dataFileName = 'linux-' + osArch;
93+
dataFileName = `linux-${osArch}`;
9494
break;
9595
case 'darwin':
96-
dataFileName = 'osx-' + osArch + '-tar';
96+
dataFileName = `osx-${osArch}-tar`;
9797
break;
9898
case 'win32':
99-
dataFileName = 'win-' + osArch + '-exe';
99+
dataFileName = `win-${osArch}-exe`;
100100
break;
101101
default:
102102
throw new Error(`Unexpected OS '${osPlat}'`);
@@ -149,10 +149,10 @@ function acquireNode(version) {
149149
//
150150
version = semver.clean(version) || '';
151151
let fileName = osPlat == 'win32'
152-
? 'node-v' + version + '-win-' + os.arch()
153-
: 'node-v' + version + '-' + osPlat + '-' + os.arch();
154-
let urlFileName = osPlat == 'win32' ? fileName + '.7z' : fileName + '.tar.gz';
155-
let downloadUrl = 'https://nodejs.org/dist/v' + version + '/' + urlFileName;
152+
? `node-v${version}-win-${osArch}`
153+
: `node-v${version}-${osPlat}-${osArch}`;
154+
let urlFileName = osPlat == 'win32' ? `${fileName}.7z` : `${fileName}.tar.gz`;
155+
let downloadUrl = `https://nodejs.org/dist/v${version}/${urlFileName}`;
156156
let downloadPath;
157157
try {
158158
downloadPath = yield tc.downloadTool(downloadUrl);
@@ -202,8 +202,8 @@ function acquireNodeFromFallbackLocation(version) {
202202
let exeUrl;
203203
let libUrl;
204204
try {
205-
exeUrl = `https://nodejs.org/dist/v${version}/win-${os.arch()}/node.exe`;
206-
libUrl = `https://nodejs.org/dist/v${version}/win-${os.arch()}/node.lib`;
205+
exeUrl = `https://nodejs.org/dist/v${version}/win-${osArch}/node.exe`;
206+
libUrl = `https://nodejs.org/dist/v${version}/win-${osArch}/node.lib`;
207207
const exePath = yield tc.downloadTool(exeUrl);
208208
yield io.cp(exePath, path.join(tempDir, 'node.exe'));
209209
const libPath = yield tc.downloadTool(libUrl);
@@ -225,3 +225,13 @@ function acquireNodeFromFallbackLocation(version) {
225225
return yield tc.cacheDir(tempDir, 'node', version);
226226
});
227227
}
228+
// os.arch does not always match the relative download url, e.g.
229+
// os.arch == 'arm' != node-v12.13.1-linux-armv7l.tar.gz
230+
function translateArchToDistUrl(arch) {
231+
switch (arch) {
232+
case 'arm':
233+
return 'armv7l';
234+
default:
235+
return arch;
236+
}
237+
}

src/installer.ts

+24-11
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as path from 'path';
99
import * as semver from 'semver';
1010

1111
let osPlat: string = os.platform();
12-
let osArch: string = os.arch();
12+
let osArch: string = translateArchToDistUrl(os.arch());
1313

1414
if (!tempDirectory) {
1515
let baseLocation;
@@ -86,13 +86,13 @@ async function queryLatestMatch(versionSpec: string): Promise<string> {
8686
let dataFileName: string;
8787
switch (osPlat) {
8888
case 'linux':
89-
dataFileName = 'linux-' + osArch;
89+
dataFileName = `linux-${osArch}`;
9090
break;
9191
case 'darwin':
92-
dataFileName = 'osx-' + osArch + '-tar';
92+
dataFileName = `osx-${osArch}-tar`;
9393
break;
9494
case 'win32':
95-
dataFileName = 'win-' + osArch + '-exe';
95+
dataFileName = `win-${osArch}-exe`;
9696
break;
9797
default:
9898
throw new Error(`Unexpected OS '${osPlat}'`);
@@ -150,12 +150,11 @@ async function acquireNode(version: string): Promise<string> {
150150
version = semver.clean(version) || '';
151151
let fileName: string =
152152
osPlat == 'win32'
153-
? 'node-v' + version + '-win-' + os.arch()
154-
: 'node-v' + version + '-' + osPlat + '-' + os.arch();
153+
? `node-v${version}-win-${osArch}`
154+
: `node-v${version}-${osPlat}-${osArch}`;
155155
let urlFileName: string =
156-
osPlat == 'win32' ? fileName + '.7z' : fileName + '.tar.gz';
157-
158-
let downloadUrl = 'https://nodejs.org/dist/v' + version + '/' + urlFileName;
156+
osPlat == 'win32' ? `${fileName}.7z` : `${fileName}.tar.gz`;
157+
let downloadUrl = `https://nodejs.org/dist/v${version}/${urlFileName}`;
159158

160159
let downloadPath: string;
161160

@@ -210,8 +209,8 @@ async function acquireNodeFromFallbackLocation(
210209
let exeUrl: string;
211210
let libUrl: string;
212211
try {
213-
exeUrl = `https://nodejs.org/dist/v${version}/win-${os.arch()}/node.exe`;
214-
libUrl = `https://nodejs.org/dist/v${version}/win-${os.arch()}/node.lib`;
212+
exeUrl = `https://nodejs.org/dist/v${version}/win-${osArch}/node.exe`;
213+
libUrl = `https://nodejs.org/dist/v${version}/win-${osArch}/node.lib`;
215214

216215
const exePath = await tc.downloadTool(exeUrl);
217216
await io.cp(exePath, path.join(tempDir, 'node.exe'));
@@ -232,3 +231,17 @@ async function acquireNodeFromFallbackLocation(
232231
}
233232
return await tc.cacheDir(tempDir, 'node', version);
234233
}
234+
235+
// os.arch does not always match the relative download url, e.g.
236+
// os.arch == 'arm' != node-v12.13.1-linux-armv7l.tar.gz
237+
// All other currently supported architectures match, e.g.:
238+
// os.arch = arm64 => https://nodejs.org/dist/v{VERSION}/node-v{VERSION}-{OS}-arm64.tar.gz
239+
// os.arch = x64 => https://nodejs.org/dist/v{VERSION}/node-v{VERSION}-{OS}-x64.tar.gz
240+
function translateArchToDistUrl(arch: string): string {
241+
switch (arch) {
242+
case 'arm':
243+
return 'armv7l';
244+
default:
245+
return arch;
246+
}
247+
}

0 commit comments

Comments
 (0)