Skip to content

Commit 732ca6c

Browse files
Overrride install method for macos runner
As CLI versions <2.20.0 do not have `.zip` installer, need to overrride this method to not introduce breaking changes
1 parent beb6554 commit 732ca6c

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/cli-installer/macos.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
import { type Installer, RunnerArch } from "./index";
1+
import { promisify } from "util";
2+
import { exec } from "child_process";
3+
import semver from "semver";
24
import * as core from "@actions/core";
5+
import * as tc from "@actions/tool-cache";
36
import { CliInstaller } from "./cli-installer";
7+
import { type Installer, RunnerArch } from "./index";
8+
9+
const execAsync = promisify(exec);
410

511
export class MacOSInstaller extends CliInstaller implements Installer {
612
private readonly arch: string;
713
private readonly version: string;
14+
private readonly minVersionWithMacOSZipInstaller = "2.20.0";
815

916
constructor(version: string) {
1017
super();
@@ -18,7 +25,30 @@ export class MacOSInstaller extends CliInstaller implements Installer {
1825
await super.install(downloadUrl);
1926
}
2027

28+
// CLI releases <2.20.0 doesn't support `.zip` files, and uses `.pkg` files instead,
29+
// Need to overwrite this to not introduce breaking changes.
30+
override async install(downloadUrl: string): Promise<void> {
31+
if (semver.gte(this.version, this.minVersionWithMacOSZipInstaller)) {
32+
await super.install(downloadUrl);
33+
return;
34+
}
35+
36+
const pkgPath = await tc.downloadTool(downloadUrl);
37+
const { stderr } = await execAsync(`sudo installer -pkg ${pkgPath} -target /`);
38+
if (stderr) {
39+
core.error(stderr);
40+
throw new Error(`Failed to install 1Password CLI: ${stderr}`);
41+
}
42+
43+
core.info("1Password CLI installed from MacOS .pkg");
44+
}
45+
2146
private downloadUrl(): string {
47+
// For versions before 2.20.0, use the .pkg installer
48+
if (semver.lt(this.version, this.minVersionWithMacOSZipInstaller)) {
49+
return `https://cache.agilebits.com/dist/1P/op2/pkg/${this.version}/op_apple_universal_${this.version}.pkg`;
50+
}
51+
2252
return `https://cache.agilebits.com/dist/1P/op2/pkg/${this.version}/op_darwin_${this.arch}_${this.version}.zip`;
2353
}
2454

0 commit comments

Comments
 (0)