1- import { type Installer , RunnerArch } from "./index" ;
1+ import { promisify } from "util" ;
2+ import { exec } from "child_process" ;
3+ import semver from "semver" ;
24import * as core from "@actions/core" ;
5+ import * as tc from "@actions/tool-cache" ;
36import { CliInstaller } from "./cli-installer" ;
7+ import { type Installer , RunnerArch } from "./index" ;
8+
9+ const execAsync = promisify ( exec ) ;
410
511export 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