Skip to content

Commit 3eed3f1

Browse files
Make latest build, fix windows download url and fix tests
1 parent e06540d commit 3eed3f1

File tree

6 files changed

+85
-77
lines changed

6 files changed

+85
-77
lines changed

dist/index.js

Lines changed: 48 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -32666,26 +32666,36 @@ var tool_cache = __nccwpck_require__(3472);
3266632666

3266732667

3266832668

32669+
// maps OS architecture names to 1Password CLI installer architecture names
3266932670
const archMap = {
3267032671
ia32: "386",
32671-
x32: "386",
32672-
x86: "386",
3267332672
x64: "amd64",
3267432673
arm: "arm",
3267532674
arm64: "arm64",
3267632675
};
32676+
// Builds the download URL for the 1Password CLI based on the platform and version.
32677+
const cliUrlBuilder = {
32678+
linux: (version, arch) => `https://cache.agilebits.com/dist/1P/op2/pkg/${version}/op_linux_${arch}_${version}.zip`,
32679+
darwin: (version) => `https://cache.agilebits.com/dist/1P/op2/pkg/${version}/op_apple_universal_${version}.pkg`,
32680+
win32: (version, arch) => `https://cache.agilebits.com/dist/1P/op2/pkg/${version}/op_windows_${arch}_${version}.zip`,
32681+
};
3267732682
class CliInstaller {
32678-
async install(downloadUrl) {
32679-
console.info(`Downloading 1Password CLI from: ${downloadUrl}`);
32680-
const downloadPath = await tool_cache.downloadTool(downloadUrl);
32683+
version;
32684+
arch;
32685+
constructor(version) {
32686+
this.version = version;
32687+
this.arch = this.getArch();
32688+
}
32689+
async install(url) {
32690+
console.info(`Downloading 1Password CLI from: ${url}`);
32691+
const downloadPath = await tool_cache.downloadTool(url);
3268132692
console.info("Installing 1Password CLI");
3268232693
const extractedPath = await tool_cache.extractZip(downloadPath);
3268332694
core.addPath(extractedPath);
3268432695
core.info("1Password CLI installed");
3268532696
}
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
3268732697
getArch() {
32688-
const arch = archMap[process.env.RUNNER_ARCH?.toLowerCase() || external_os_default().arch()];
32698+
const arch = archMap[external_os_default().arch()];
3268932699
if (!arch) {
3269032700
throw new Error("Unsupported architecture");
3269132701
}
@@ -32695,21 +32705,14 @@ class CliInstaller {
3269532705

3269632706
;// CONCATENATED MODULE: ./src/cli-installer/linux.ts
3269732707

32698-
3269932708
class LinuxInstaller extends CliInstaller {
32700-
arch;
32701-
version;
32709+
platform = "linux"; // Node.js platform identifier for Linux
3270232710
constructor(version) {
32703-
super();
32704-
this.version = version;
32705-
this.arch = super.getArch();
32711+
super(version);
3270632712
}
3270732713
async installCli() {
32708-
const downloadUrl = this.downloadUrl();
32709-
await super.install(downloadUrl);
32710-
}
32711-
downloadUrl() {
32712-
return `https://cache.agilebits.com/dist/1P/op2/pkg/${this.version}/op_linux_${this.arch}_${this.version}.zip`;
32714+
const urlBuilder = cliUrlBuilder[this.platform];
32715+
await super.install(urlBuilder(this.version, this.arch));
3271332716
}
3271432717
}
3271532718

@@ -32732,18 +32735,13 @@ var external_util_ = __nccwpck_require__(9023);
3273232735

3273332736
const execAsync = (0,external_util_.promisify)(external_child_process_.exec);
3273432737
class MacOsInstaller extends CliInstaller {
32735-
version;
32738+
platform = "darwin"; // Node.js platform identifier for macOS
3273632739
constructor(version) {
32737-
super();
32738-
this.version = version;
32740+
super(version);
3273932741
}
3274032742
async installCli() {
32741-
const downloadUrl = this.downloadUrl();
32742-
core.info(`Downloading 1Password CLI ${this.version} from ${downloadUrl}`);
32743-
await this.install(downloadUrl);
32744-
}
32745-
downloadUrl() {
32746-
return `https://cache.agilebits.com/dist/1P/op2/pkg/${this.version}/op_apple_universal_${this.version}.pkg`;
32743+
const urlBuilder = cliUrlBuilder[this.platform];
32744+
await this.install(urlBuilder(this.version));
3274732745
}
3274832746
// @actions/tool-cache package does not support .pkg files, so we need to handle the installation manually
3274932747
async install(downloadUrl) {
@@ -32766,36 +32764,37 @@ class MacOsInstaller extends CliInstaller {
3276632764
;// CONCATENATED MODULE: ./src/cli-installer/windows.ts
3276732765

3276832766
class WindowsInstaller extends CliInstaller {
32769-
arch;
32770-
version;
32767+
platform = "win32"; // Node.js platform identifier for Windows
3277132768
constructor(version) {
32772-
super();
32773-
this.version = version;
32774-
this.arch = super.getArch();
32769+
super(version);
3277532770
}
3277632771
async installCli() {
32777-
const downloadUrl = this.downloadUrl();
32778-
await super.install(downloadUrl);
32779-
}
32780-
downloadUrl() {
32781-
return `https://cache.agilebits.com/dist/1P/op2/pkg/${this.version}/op_windows_${this.arch}_${this.version}.zip`;
32772+
const urlBuilder = cliUrlBuilder[this.platform];
32773+
await super.install(urlBuilder(this.version, this.arch));
3278232774
}
3278332775
}
3278432776

32785-
;// CONCATENATED MODULE: ./src/cli-installer/index.ts
32777+
;// CONCATENATED MODULE: ./src/cli-installer/installer.ts
3278632778

3278732779

3278832780

32789-
/* eslint-disable @typescript-eslint/naming-convention */
32790-
// RunnerOS defines the operating system of the runner executing the job.
32791-
// Look `RUNNER_OS` for possible values (https://docs.github.com/en/actions/reference/variables-reference).
32792-
var RunnerOS;
32793-
(function (RunnerOS) {
32794-
RunnerOS["Linux"] = "Linux";
32795-
RunnerOS["MacOS"] = "macOS";
32796-
RunnerOS["Windows"] = "Windows";
32797-
})(RunnerOS || (RunnerOS = {}));
32798-
/* eslint-enable @typescript-eslint/naming-convention */
32781+
32782+
const newCliInstaller = (version) => {
32783+
const platform = external_os_default().platform();
32784+
switch (platform) {
32785+
case "linux":
32786+
return new LinuxInstaller(version);
32787+
case "darwin":
32788+
return new MacOsInstaller(version);
32789+
case "win32":
32790+
return new WindowsInstaller(version);
32791+
default:
32792+
throw new Error(`Unsupported platform: ${platform}`);
32793+
}
32794+
};
32795+
32796+
;// CONCATENATED MODULE: ./src/cli-installer/index.ts
32797+
3279932798

3280032799
;// CONCATENATED MODULE: ./src/version/constants.ts
3280132800
/* eslint-disable @typescript-eslint/naming-convention */
@@ -32900,21 +32899,7 @@ const run = async () => {
3290032899
try {
3290132900
const versionResolver = new VersionResolver(core.getInput("version"));
3290232901
await versionResolver.resolve();
32903-
let installer;
32904-
switch (process.env.RUNNER_OS) {
32905-
case RunnerOS.Linux:
32906-
installer = new LinuxInstaller(versionResolver.get());
32907-
break;
32908-
case RunnerOS.MacOS:
32909-
installer = new MacOsInstaller(versionResolver.get());
32910-
break;
32911-
case RunnerOS.Windows:
32912-
installer = new WindowsInstaller(versionResolver.get());
32913-
break;
32914-
default:
32915-
core.setFailed(`Unsupported platform: ${process.env.RUNNER_OS}`);
32916-
return;
32917-
}
32902+
const installer = newCliInstaller(versionResolver.get());
3291832903
await installer.installCli();
3291932904
}
3292032905
catch (error) {

src/cli-installer/cli-installer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export type SupportedPlatform = Extract<
99
>;
1010

1111
// maps OS architecture names to 1Password CLI installer architecture names
12-
const archMap: Record<string, string> = {
12+
export const archMap: Record<string, string> = {
1313
ia32: "386",
1414
x64: "amd64",
1515
arm: "arm",
@@ -26,7 +26,7 @@ export const cliUrlBuilder: Record<
2626
darwin: (version) =>
2727
`https://cache.agilebits.com/dist/1P/op2/pkg/${version}/op_apple_universal_${version}.pkg`,
2828
win32: (version, arch) =>
29-
`https://cache.agilebits.com/dist/1P/op2/pkg/${version}/op_windows_${arch}_${version}_.zip`,
29+
`https://cache.agilebits.com/dist/1P/op2/pkg/${version}/op_windows_${arch}_${version}.zip`,
3030
};
3131

3232
export class CliInstaller {

src/cli-installer/installer.test.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ import { LinuxInstaller } from "./linux";
55
import { MacOsInstaller } from "./macos";
66
import { WindowsInstaller } from "./windows";
77

8-
jest.mock("os");
9-
jest.mock("./linux");
10-
jest.mock("./macos");
11-
jest.mock("./windows");
8+
afterEach(() => {
9+
jest.restoreAllMocks();
10+
});
1211

1312
describe("newCliInstaller", () => {
1413
const version = "1.0.0";
@@ -18,25 +17,25 @@ describe("newCliInstaller", () => {
1817
});
1918

2019
it("should return LinuxInstaller for linux platform", () => {
21-
(os.platform as jest.Mock).mockReturnValue("linux");
20+
jest.spyOn(os, "platform").mockReturnValue("linux");
2221
const installer = newCliInstaller(version);
2322
expect(installer).toBeInstanceOf(LinuxInstaller);
2423
});
2524

2625
it("should return MacOsInstaller for darwin platform", () => {
27-
(os.platform as jest.Mock).mockReturnValue("darwin");
26+
jest.spyOn(os, "platform").mockReturnValue("darwin");
2827
const installer = newCliInstaller(version);
2928
expect(installer).toBeInstanceOf(MacOsInstaller);
3029
});
3130

3231
it("should return WindowsInstaller for win32 platform", () => {
33-
(os.platform as jest.Mock).mockReturnValue("win32");
32+
jest.spyOn(os, "platform").mockReturnValue("win32");
3433
const installer = newCliInstaller(version);
3534
expect(installer).toBeInstanceOf(WindowsInstaller);
3635
});
3736

3837
it("should throw error for unsupported platform", () => {
39-
(os.platform as jest.Mock).mockReturnValue("sunos");
38+
jest.spyOn(os, "platform").mockReturnValue("sunos");
4039
expect(() => newCliInstaller(version)).toThrow(
4140
"Unsupported platform: sunos",
4241
);

src/cli-installer/linux.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
import os from "os";
22

33
import {
4+
archMap,
45
CliInstaller,
56
cliUrlBuilder,
67
type SupportedPlatform,
78
} from "./cli-installer";
89
import { LinuxInstaller } from "./linux";
910

11+
afterEach(() => {
12+
jest.restoreAllMocks();
13+
});
14+
1015
describe("LinuxInstaller", () => {
1116
const version = "1.2.3";
17+
const arch: NodeJS.Architecture = "arm64";
1218

1319
it("should construct with given version and architecture", () => {
20+
jest.spyOn(os, "arch").mockReturnValue(arch);
1421
const installer = new LinuxInstaller(version);
1522
expect(installer.version).toEqual(version);
16-
expect(installer.arch).toEqual(os.arch());
23+
expect(installer.arch).toEqual(archMap[arch]);
1724
});
1825

1926
it("should call install with correct URL", async () => {

src/cli-installer/macos.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
import os from "os";
22

3-
import { cliUrlBuilder, type SupportedPlatform } from "./cli-installer";
3+
import {
4+
archMap,
5+
cliUrlBuilder,
6+
type SupportedPlatform,
7+
} from "./cli-installer";
48
import { MacOsInstaller } from "./macos";
59

10+
afterEach(() => {
11+
jest.restoreAllMocks();
12+
});
13+
614
describe("MacOsInstaller", () => {
715
const version = "1.2.3";
16+
const arch: NodeJS.Architecture = "x64";
817

918
it("should construct with given version and architecture", () => {
19+
jest.spyOn(os, "arch").mockReturnValue(arch);
1020
const installer = new MacOsInstaller(version);
1121
expect(installer.version).toEqual(version);
12-
expect(installer.arch).toEqual(os.arch());
22+
expect(installer.arch).toEqual(archMap[arch]);
1323
});
1424

1525
it("should call install with correct URL", async () => {

src/cli-installer/windows.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
import os from "os";
22

33
import {
4+
archMap,
45
CliInstaller,
56
cliUrlBuilder,
67
type SupportedPlatform,
78
} from "./cli-installer";
89
import { WindowsInstaller } from "./windows";
910

11+
afterEach(() => {
12+
jest.restoreAllMocks();
13+
});
14+
1015
describe("WindowsInstaller", () => {
1116
const version = "1.2.3";
17+
const arch: NodeJS.Architecture = "x64";
1218

1319
it("should construct with given version and architecture", () => {
20+
jest.spyOn(os, "arch").mockReturnValue(arch);
1421
const installer = new WindowsInstaller(version);
1522
expect(installer.version).toEqual(version);
16-
expect(installer.arch).toEqual(os.arch());
23+
expect(installer.arch).toEqual(archMap[arch]);
1724
});
1825

1926
it("should call install with correct URL", async () => {

0 commit comments

Comments
 (0)