Skip to content

Commit 1426ce6

Browse files
authored
Select tmate binaries based on CPU architecture (#91)
* Select tmate binaries based on CPU architecture Now arm64 and amd64 are both supported. * Replace switch statement with an Object map Based on feedback in the PR
1 parent 3c4ea0b commit 1426ce6

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

lib/index.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10291,6 +10291,16 @@ const execShellCommand = (cmd) => {
1029110291

1029210292
const TMATE_LINUX_VERSION = "2.4.0"
1029310293

10294+
// Map os.arch() values to the architectures in tmate release binary filenames.
10295+
// Possible os.arch() values documented here:
10296+
// https://nodejs.org/api/os.html#os_os_arch
10297+
// Available tmate binaries listed here:
10298+
// https://github.com/tmate-io/tmate/releases/
10299+
const TMATE_ARCH_MAP = {
10300+
arm64: 'arm64v8',
10301+
x64: 'amd64',
10302+
};
10303+
1029410304
/** @param {number} ms */
1029510305
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
1029610306

@@ -10308,7 +10318,11 @@ async function run() {
1030810318
await execShellCommand(optionalSudoPrefix + 'apt-get update');
1030910319
await execShellCommand(optionalSudoPrefix + 'apt-get install -y openssh-client xz-utils');
1031010320

10311-
const tmateReleaseTar = await tool_cache.downloadTool(`https://github.com/tmate-io/tmate/releases/download/${TMATE_LINUX_VERSION}/tmate-${TMATE_LINUX_VERSION}-static-linux-amd64.tar.xz`);
10321+
const tmateArch = TMATE_ARCH_MAP[external_os_default().arch()];
10322+
if (!tmateArch) {
10323+
throw new Error(`Unsupported architecture: ${external_os_default().arch()}`)
10324+
}
10325+
const tmateReleaseTar = await tool_cache.downloadTool(`https://github.com/tmate-io/tmate/releases/download/${TMATE_LINUX_VERSION}/tmate-${TMATE_LINUX_VERSION}-static-linux-${tmateArch}.tar.xz`);
1031210326
const tmateDir = external_path_default().join(external_os_default().tmpdir(), "tmate")
1031310327
tmateExecutable = external_path_default().join(tmateDir, "tmate")
1031410328

src/index.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ import { execShellCommand } from "./helpers"
1111

1212
const TMATE_LINUX_VERSION = "2.4.0"
1313

14+
// Map os.arch() values to the architectures in tmate release binary filenames.
15+
// Possible os.arch() values documented here:
16+
// https://nodejs.org/api/os.html#os_os_arch
17+
// Available tmate binaries listed here:
18+
// https://github.com/tmate-io/tmate/releases/
19+
const TMATE_ARCH_MAP = {
20+
arm64: 'arm64v8',
21+
x64: 'amd64',
22+
};
23+
1424
/** @param {number} ms */
1525
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
1626

@@ -28,7 +38,11 @@ export async function run() {
2838
await execShellCommand(optionalSudoPrefix + 'apt-get update');
2939
await execShellCommand(optionalSudoPrefix + 'apt-get install -y openssh-client xz-utils');
3040

31-
const tmateReleaseTar = await tc.downloadTool(`https://github.com/tmate-io/tmate/releases/download/${TMATE_LINUX_VERSION}/tmate-${TMATE_LINUX_VERSION}-static-linux-amd64.tar.xz`);
41+
const tmateArch = TMATE_ARCH_MAP[os.arch()];
42+
if (!tmateArch) {
43+
throw new Error(`Unsupported architecture: ${os.arch()}`)
44+
}
45+
const tmateReleaseTar = await tc.downloadTool(`https://github.com/tmate-io/tmate/releases/download/${TMATE_LINUX_VERSION}/tmate-${TMATE_LINUX_VERSION}-static-linux-${tmateArch}.tar.xz`);
3246
const tmateDir = path.join(os.tmpdir(), "tmate")
3347
tmateExecutable = path.join(tmateDir, "tmate")
3448

0 commit comments

Comments
 (0)