Skip to content

Commit f9f495b

Browse files
Support both self hosted and github hosted runner architectures
1 parent f884838 commit f9f495b

File tree

5 files changed

+46
-56
lines changed

5 files changed

+46
-56
lines changed

dist/index.js

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32657,11 +32657,23 @@ var __webpack_exports__ = {};
3265732657

3265832658
// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js
3265932659
var core = __nccwpck_require__(7484);
32660+
// EXTERNAL MODULE: external "os"
32661+
var external_os_ = __nccwpck_require__(857);
32662+
var external_os_default = /*#__PURE__*/__nccwpck_require__.n(external_os_);
3266032663
// EXTERNAL MODULE: ./node_modules/@actions/tool-cache/lib/tool-cache.js
3266132664
var tool_cache = __nccwpck_require__(3472);
3266232665
;// CONCATENATED MODULE: ./src/cli-installer/cli-installer.ts
3266332666

3266432667

32668+
32669+
const archMap = {
32670+
ia32: "386",
32671+
x32: "386",
32672+
x86: "386",
32673+
x64: "amd64",
32674+
arm: "arm",
32675+
arm64: "arm64",
32676+
};
3266532677
class CliInstaller {
3266632678
async install(downloadUrl) {
3266732679
console.info(`Downloading 1Password CLI from: ${downloadUrl}`);
@@ -32671,6 +32683,14 @@ class CliInstaller {
3267132683
core.addPath(extractedPath);
3267232684
core.info("1Password CLI installed");
3267332685
}
32686+
// possible values for GitHub hosted runners (process.env.RUNNER_ARCH) can be found here: https://docs.github.com/en/actions/reference/variables-reference#default-environment-variables
32687+
getArch() {
32688+
const arch = archMap[process.env.RUNNER_ARCH?.toLowerCase() || external_os_default().arch()];
32689+
if (!arch) {
32690+
throw new Error("Unsupported architecture");
32691+
}
32692+
return arch;
32693+
}
3267432694
}
3267532695

3267632696
;// CONCATENATED MODULE: ./src/cli-installer/linux.ts
@@ -32682,7 +32702,7 @@ class LinuxInstaller extends CliInstaller {
3268232702
constructor(version) {
3268332703
super();
3268432704
this.version = version;
32685-
this.arch = this.getArch();
32705+
this.arch = super.getArch();
3268632706
}
3268732707
async installCli() {
3268832708
const downloadUrl = this.downloadUrl();
@@ -32691,21 +32711,6 @@ class LinuxInstaller extends CliInstaller {
3269132711
downloadUrl() {
3269232712
return `https://cache.agilebits.com/dist/1P/op2/pkg/${this.version}/op_linux_${this.arch}_${this.version}.zip`;
3269332713
}
32694-
// return cpu architecture for the current
32695-
getArch() {
32696-
switch (process.env.RUNNER_ARCH) {
32697-
case RunnerArch.X86:
32698-
return "386";
32699-
case RunnerArch.X64:
32700-
return "amd64";
32701-
case RunnerArch.ARM:
32702-
return "arm";
32703-
case RunnerArch.ARM64:
32704-
return "arm64";
32705-
default:
32706-
throw new Error(`Unsupported RUNNER_ARCH value for linux: ${process.env.RUNNER_ARCH}`);
32707-
}
32708-
}
3270932714
}
3271032715

3271132716
// EXTERNAL MODULE: external "child_process"
@@ -32766,7 +32771,7 @@ class WindowsInstaller extends CliInstaller {
3276632771
constructor(version) {
3276732772
super();
3276832773
this.version = version;
32769-
this.arch = "amd64"; // GitHub-hosted Windows runners (like windows-latest, windows-2022, windows-2019) are all 64-bit Windows Server VMs.
32774+
this.arch = super.getArch();
3277032775
}
3277132776
async installCli() {
3277232777
const downloadUrl = this.downloadUrl();
@@ -32782,15 +32787,6 @@ class WindowsInstaller extends CliInstaller {
3278232787

3278332788

3278432789
/* eslint-disable @typescript-eslint/naming-convention */
32785-
// Defines the architecture of the runner executing the job.
32786-
// Look `RUNNER_ARCH` for possible values (https://docs.github.com/en/actions/reference/variables-reference).
32787-
var RunnerArch;
32788-
(function (RunnerArch) {
32789-
RunnerArch["X64"] = "X64";
32790-
RunnerArch["X86"] = "X86";
32791-
RunnerArch["ARM"] = "ARM";
32792-
RunnerArch["ARM64"] = "ARM64";
32793-
})(RunnerArch || (RunnerArch = {}));
3279432790
// RunnerOS defines the operating system of the runner executing the job.
3279532791
// Look `RUNNER_OS` for possible values (https://docs.github.com/en/actions/reference/variables-reference).
3279632792
var RunnerOS;

src/cli-installer/cli-installer.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1+
import os from "os";
2+
13
import * as core from "@actions/core";
24
import * as tc from "@actions/tool-cache";
35

6+
export const archMap: Record<string, string> = {
7+
ia32: "386",
8+
x32: "386",
9+
x86: "386",
10+
x64: "amd64",
11+
arm: "arm",
12+
arm64: "arm64",
13+
};
14+
415
export class CliInstaller {
516
public async install(downloadUrl: string): Promise<void> {
617
console.info(`Downloading 1Password CLI from: ${downloadUrl}`);
@@ -10,4 +21,14 @@ export class CliInstaller {
1021
core.addPath(extractedPath);
1122
core.info("1Password CLI installed");
1223
}
24+
25+
// possible values for GitHub hosted runners (process.env.RUNNER_ARCH) can be found here: https://docs.github.com/en/actions/reference/variables-reference#default-environment-variables
26+
public getArch(): string {
27+
const arch = archMap[process.env.RUNNER_ARCH?.toLowerCase() || os.arch()];
28+
if (!arch) {
29+
throw new Error("Unsupported architecture");
30+
}
31+
32+
return arch;
33+
}
1334
}

src/cli-installer/index.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@ export interface Installer {
77
}
88

99
/* eslint-disable @typescript-eslint/naming-convention */
10-
// Defines the architecture of the runner executing the job.
11-
// Look `RUNNER_ARCH` for possible values (https://docs.github.com/en/actions/reference/variables-reference).
12-
export enum RunnerArch {
13-
X64 = "X64",
14-
X86 = "X86",
15-
ARM = "ARM",
16-
ARM64 = "ARM64",
17-
}
18-
1910
// RunnerOS defines the operating system of the runner executing the job.
2011
// Look `RUNNER_OS` for possible values (https://docs.github.com/en/actions/reference/variables-reference).
2112
export enum RunnerOS {

src/cli-installer/linux.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CliInstaller } from "./cli-installer";
2-
import { type Installer, RunnerArch } from "./index";
2+
import { type Installer } from "./index";
33

44
export class LinuxInstaller extends CliInstaller implements Installer {
55
private readonly arch: string;
@@ -8,7 +8,7 @@ export class LinuxInstaller extends CliInstaller implements Installer {
88
public constructor(version: string) {
99
super();
1010
this.version = version;
11-
this.arch = this.getArch();
11+
this.arch = super.getArch();
1212
}
1313

1414
public async installCli(): Promise<void> {
@@ -19,22 +19,4 @@ export class LinuxInstaller extends CliInstaller implements Installer {
1919
private downloadUrl(): string {
2020
return `https://cache.agilebits.com/dist/1P/op2/pkg/${this.version}/op_linux_${this.arch}_${this.version}.zip`;
2121
}
22-
23-
// return cpu architecture for the current
24-
private getArch(): string {
25-
switch (process.env.RUNNER_ARCH) {
26-
case RunnerArch.X86:
27-
return "386";
28-
case RunnerArch.X64:
29-
return "amd64";
30-
case RunnerArch.ARM:
31-
return "arm";
32-
case RunnerArch.ARM64:
33-
return "arm64";
34-
default:
35-
throw new Error(
36-
`Unsupported RUNNER_ARCH value for linux: ${process.env.RUNNER_ARCH}`,
37-
);
38-
}
39-
}
4022
}

src/cli-installer/windows.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export class WindowsInstaller extends CliInstaller implements Installer {
88
public constructor(version: string) {
99
super();
1010
this.version = version;
11-
this.arch = "amd64"; // GitHub-hosted Windows runners (like windows-latest, windows-2022, windows-2019) are all 64-bit Windows Server VMs.
11+
this.arch = super.getArch();
1212
}
1313

1414
public async installCli(): Promise<void> {

0 commit comments

Comments
 (0)