Skip to content

Commit 4438e2b

Browse files
Install macos CLI only from .pkg installer
1 parent 5b103ac commit 4438e2b

File tree

3 files changed

+96
-160
lines changed

3 files changed

+96
-160
lines changed

dist/index.js

Lines changed: 85 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -68270,10 +68270,10 @@ class CliInstaller {
6827068270
async install(downloadUrl) {
6827168271
console.info(`Downloading 1Password CLI from: ${downloadUrl}`);
6827268272
const downloadPath = await tool_cache.downloadTool(downloadUrl);
68273-
console.info(`Extracting 1Password CLI from: ${downloadPath}`);
68273+
console.info("Installing 1Password CLI");
6827468274
const extractedPath = await tool_cache.extractZip(downloadPath);
6827568275
core.addPath(extractedPath);
68276-
core.info(`1Password CLI installed at ${extractedPath}`);
68276+
core.info("1Password CLI installed");
6827768277
}
6827868278
}
6827968279

@@ -68320,6 +68320,89 @@ var external_child_process_ = __nccwpck_require__(5317);
6832068320
var external_fs_ = __nccwpck_require__(9896);
6832168321
// EXTERNAL MODULE: external "path"
6832268322
var external_path_ = __nccwpck_require__(6928);
68323+
;// CONCATENATED MODULE: ./src/cli-installer/macos.ts
68324+
68325+
68326+
68327+
68328+
68329+
68330+
68331+
68332+
const execAsync = (0,external_util_.promisify)(external_child_process_.exec);
68333+
class MacOSInstaller extends CliInstaller {
68334+
version;
68335+
constructor(version) {
68336+
super();
68337+
this.version = version;
68338+
}
68339+
async installCli() {
68340+
const downloadUrl = this.downloadUrl();
68341+
core.info(`Downloading 1Password CLI ${this.version} from ${downloadUrl}`);
68342+
await this.install(downloadUrl);
68343+
}
68344+
downloadUrl() {
68345+
return `https://cache.agilebits.com/dist/1P/op2/pkg/${this.version}/op_apple_universal_${this.version}.pkg`;
68346+
}
68347+
// @actions/tool-cache package does not support .pkg files, so we need to handle the installation manually
68348+
async install(downloadUrl) {
68349+
console.info(`Downloading 1Password CLI from: ${downloadUrl}`);
68350+
const pkgPath = await tool_cache.downloadTool(downloadUrl);
68351+
const pkgWithExtension = `${pkgPath}.pkg`;
68352+
external_fs_.renameSync(pkgPath, pkgWithExtension);
68353+
const expandDir = "temp-pkg";
68354+
await execAsync(`pkgutil --expand "${pkgWithExtension}" "${expandDir}"`);
68355+
const payloadPath = external_path_.join(expandDir, "op.pkg", "Payload");
68356+
console.info("Installing 1Password CLI");
68357+
const cliPath = await tool_cache.extractTar(payloadPath);
68358+
core.addPath(cliPath);
68359+
external_fs_.rmSync(expandDir, { recursive: true, force: true });
68360+
external_fs_.rmSync(pkgPath, { force: true });
68361+
core.info("1Password CLI installed");
68362+
}
68363+
}
68364+
68365+
;// CONCATENATED MODULE: ./src/cli-installer/windows.ts
68366+
68367+
class WindowsInstaller extends CliInstaller {
68368+
arch;
68369+
version;
68370+
constructor(version) {
68371+
super();
68372+
this.version = version;
68373+
this.arch = "amd64"; // GitHub-hosted Windows runners (like windows-latest, windows-2022, windows-2019) are all 64-bit Windows Server VMs.
68374+
}
68375+
async installCli() {
68376+
const downloadUrl = this.downloadUrl();
68377+
await super.install(downloadUrl);
68378+
}
68379+
downloadUrl() {
68380+
return `https://cache.agilebits.com/dist/1P/op2/pkg/${this.version}/op_windows_${this.arch}_${this.version}.zip`;
68381+
}
68382+
}
68383+
68384+
;// CONCATENATED MODULE: ./src/cli-installer/index.ts
68385+
68386+
68387+
68388+
// Defines the architecture of the runner executing the job.
68389+
// Look `RUNNER_ARCH` for possible values (https://docs.github.com/en/actions/reference/variables-reference).
68390+
var RunnerArch;
68391+
(function (RunnerArch) {
68392+
RunnerArch["X64"] = "X64";
68393+
RunnerArch["X86"] = "X86";
68394+
RunnerArch["ARM"] = "ARM";
68395+
RunnerArch["ARM64"] = "ARM64";
68396+
})(RunnerArch || (RunnerArch = {}));
68397+
// RunnerOS defines the operating system of the runner executing the job.
68398+
// Look `RUNNER_OS` for possible values (https://docs.github.com/en/actions/reference/variables-reference).
68399+
var RunnerOS;
68400+
(function (RunnerOS) {
68401+
RunnerOS["Linux"] = "Linux";
68402+
RunnerOS["MacOS"] = "macOS";
68403+
RunnerOS["Windows"] = "Windows";
68404+
})(RunnerOS || (RunnerOS = {}));
68405+
6832368406
// EXTERNAL MODULE: ./node_modules/semver/index.js
6832468407
var semver = __nccwpck_require__(2088);
6832568408
var semver_default = /*#__PURE__*/__nccwpck_require__.n(semver);
@@ -88219,114 +88302,6 @@ class VersionResolver {
8821988302

8822088303

8822188304

88222-
;// CONCATENATED MODULE: ./src/cli-installer/macos.ts
88223-
88224-
88225-
88226-
88227-
88228-
88229-
88230-
88231-
88232-
88233-
const execAsync = (0,external_util_.promisify)(external_child_process_.exec);
88234-
class MacOSInstaller extends CliInstaller {
88235-
arch;
88236-
version;
88237-
minVersionWithMacOSZipInstaller = "2.20.0";
88238-
constructor(version) {
88239-
super();
88240-
this.version = version;
88241-
this.arch = this.getArch();
88242-
}
88243-
async installCli() {
88244-
const downloadUrl = this.downloadUrl();
88245-
core.info(`Downloading 1Password CLI ${this.version} from ${downloadUrl}`);
88246-
await this.installOnMacOS(downloadUrl);
88247-
}
88248-
downloadUrl() {
88249-
// For versions before 2.20.0, use the .pkg installer
88250-
if (semver_default().lt(normalizeForSemver(this.version), this.minVersionWithMacOSZipInstaller)) {
88251-
return `https://cache.agilebits.com/dist/1P/op2/pkg/${this.version}/op_apple_universal_${this.version}.pkg`;
88252-
}
88253-
return `https://cache.agilebits.com/dist/1P/op2/pkg/${this.version}/op_darwin_${this.arch}_${this.version}.zip`;
88254-
}
88255-
getArch() {
88256-
switch (process.env.RUNNER_ARCH) {
88257-
case RunnerArch.X64:
88258-
return "amd64";
88259-
case RunnerArch.ARM64:
88260-
return "arm64";
88261-
default:
88262-
throw new Error(`Unsupported RUNNER_ARCH value for macOS: ${process.env.RUNNER_ARCH}`);
88263-
}
88264-
}
88265-
// CLI releases <2.20.0 doesn't support `.zip` files, and uses `.pkg` files instead,
88266-
// Need to overwrite this to not introduce breaking changes.
88267-
async installOnMacOS(downloadUrl) {
88268-
if (semver_default().gte(normalizeForSemver(this.version), this.minVersionWithMacOSZipInstaller)) {
88269-
await super.install(downloadUrl);
88270-
return;
88271-
}
88272-
core.info("Installing 1Password CLI using MacOS .pkg installer");
88273-
const pkgPath = await tool_cache.downloadTool(downloadUrl);
88274-
// Renaming to .pkg extension
88275-
const pkgWithExtension = `${pkgPath}.pkg`;
88276-
external_fs_.renameSync(pkgPath, pkgWithExtension);
88277-
const expandDir = "temp-pkg";
88278-
await execAsync(`pkgutil --expand "${pkgWithExtension}" "${expandDir}"`);
88279-
const payloadPath = external_path_.join(expandDir, "op.pkg", "Payload");
88280-
const cliPath = await tool_cache.extractTar(payloadPath);
88281-
core.info(`Extracted CLI to '${cliPath}'`);
88282-
core.addPath(cliPath);
88283-
external_fs_.rmSync(expandDir, { recursive: true, force: true });
88284-
external_fs_.rmSync(pkgPath, { force: true });
88285-
core.info("1Password CLI installed from MacOS .pkg");
88286-
}
88287-
}
88288-
88289-
;// CONCATENATED MODULE: ./src/cli-installer/windows.ts
88290-
88291-
class WindowsInstaller extends CliInstaller {
88292-
arch;
88293-
version;
88294-
constructor(version) {
88295-
super();
88296-
this.version = version;
88297-
this.arch = "amd64"; // GitHub-hosted Windows runners (like windows-latest, windows-2022, windows-2019) are all 64-bit Windows Server VMs.
88298-
}
88299-
async installCli() {
88300-
const downloadUrl = this.downloadUrl();
88301-
await super.install(downloadUrl);
88302-
}
88303-
downloadUrl() {
88304-
return `https://cache.agilebits.com/dist/1P/op2/pkg/${this.version}/op_windows_${this.arch}_${this.version}.zip`;
88305-
}
88306-
}
88307-
88308-
;// CONCATENATED MODULE: ./src/cli-installer/index.ts
88309-
88310-
88311-
88312-
// Defines the architecture of the runner executing the job.
88313-
// Look `RUNNER_ARCH` for possible values (https://docs.github.com/en/actions/reference/variables-reference).
88314-
var RunnerArch;
88315-
(function (RunnerArch) {
88316-
RunnerArch["X64"] = "X64";
88317-
RunnerArch["X86"] = "X86";
88318-
RunnerArch["ARM"] = "ARM";
88319-
RunnerArch["ARM64"] = "ARM64";
88320-
})(RunnerArch || (RunnerArch = {}));
88321-
// RunnerOS defines the operating system of the runner executing the job.
88322-
// Look `RUNNER_OS` for possible values (https://docs.github.com/en/actions/reference/variables-reference).
88323-
var RunnerOS;
88324-
(function (RunnerOS) {
88325-
RunnerOS["Linux"] = "Linux";
88326-
RunnerOS["MacOS"] = "macOS";
88327-
RunnerOS["Windows"] = "Windows";
88328-
})(RunnerOS || (RunnerOS = {}));
88329-
8833088305
;// CONCATENATED MODULE: ./src/index.ts
8833188306

8833288307

src/cli-installer/cli-installer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ export class CliInstaller {
55
async install(downloadUrl: string): Promise<void> {
66
console.info(`Downloading 1Password CLI from: ${downloadUrl}`);
77
const downloadPath = await tc.downloadTool(downloadUrl);
8-
console.info(`Extracting 1Password CLI from: ${downloadPath}`);
8+
console.info("Installing 1Password CLI");
99
const extractedPath = await tc.extractZip(downloadPath);
1010
core.addPath(extractedPath);
11-
core.info(`1Password CLI installed at ${extractedPath}`);
11+
core.info("1Password CLI installed");
1212
}
1313
}

src/cli-installer/macos.ts

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,87 +2,48 @@ import { promisify } from "util";
22
import { exec } from "child_process";
33
import * as fs from "fs";
44
import * as path from "path";
5-
import semver from "semver";
65
import * as core from "@actions/core";
76
import * as tc from "@actions/tool-cache";
87
import { CliInstaller } from "./cli-installer";
9-
import { type Installer, RunnerArch } from "./index";
10-
import * as version from "../version";
8+
import { type Installer } from "./index";
119

1210
const execAsync = promisify(exec);
1311

1412
export class MacOSInstaller extends CliInstaller implements Installer {
15-
private readonly arch: string;
1613
private readonly version: string;
17-
private readonly minVersionWithMacOSZipInstaller = "2.20.0";
1814

1915
constructor(version: string) {
2016
super();
2117
this.version = version;
22-
this.arch = this.getArch();
2318
}
2419

2520
async installCli(): Promise<void> {
2621
const downloadUrl = this.downloadUrl();
2722
core.info(`Downloading 1Password CLI ${this.version} from ${downloadUrl}`);
28-
await this.installOnMacOS(downloadUrl);
23+
await this.install(downloadUrl);
2924
}
3025

3126
private downloadUrl(): string {
32-
// For versions before 2.20.0, use the .pkg installer
33-
if (
34-
semver.lt(
35-
version.normalizeForSemver(this.version),
36-
this.minVersionWithMacOSZipInstaller,
37-
)
38-
) {
39-
return `https://cache.agilebits.com/dist/1P/op2/pkg/${this.version}/op_apple_universal_${this.version}.pkg`;
40-
}
41-
42-
return `https://cache.agilebits.com/dist/1P/op2/pkg/${this.version}/op_darwin_${this.arch}_${this.version}.zip`;
43-
}
44-
45-
private getArch(): string {
46-
switch (process.env.RUNNER_ARCH) {
47-
case RunnerArch.X64:
48-
return "amd64";
49-
case RunnerArch.ARM64:
50-
return "arm64";
51-
default:
52-
throw new Error(
53-
`Unsupported RUNNER_ARCH value for macOS: ${process.env.RUNNER_ARCH}`,
54-
);
55-
}
27+
return `https://cache.agilebits.com/dist/1P/op2/pkg/${this.version}/op_apple_universal_${this.version}.pkg`;
5628
}
5729

58-
// CLI releases <2.20.0 doesn't support `.zip` files, and uses `.pkg` files instead,
59-
// Need to overwrite this to not introduce breaking changes.
60-
private async installOnMacOS(downloadUrl: string): Promise<void> {
61-
if (
62-
semver.gte(
63-
version.normalizeForSemver(this.version),
64-
this.minVersionWithMacOSZipInstaller,
65-
)
66-
) {
67-
await super.install(downloadUrl);
68-
return;
69-
}
70-
71-
core.info("Installing 1Password CLI using MacOS .pkg installer");
30+
// @actions/tool-cache package does not support .pkg files, so we need to handle the installation manually
31+
override async install(downloadUrl: string): Promise<void> {
32+
console.info(`Downloading 1Password CLI from: ${downloadUrl}`);
7233
const pkgPath = await tc.downloadTool(downloadUrl);
73-
// Renaming to .pkg extension
7434
const pkgWithExtension = `${pkgPath}.pkg`;
7535
fs.renameSync(pkgPath, pkgWithExtension);
7636

7737
const expandDir = "temp-pkg"
7838
await execAsync(`pkgutil --expand "${pkgWithExtension}" "${expandDir}"`);
7939
const payloadPath = path.join(expandDir, "op.pkg", "Payload");
40+
console.info("Installing 1Password CLI");
8041
const cliPath = await tc.extractTar(payloadPath)
81-
core.info(`Extracted CLI to '${cliPath}'`);
8242
core.addPath(cliPath);
43+
8344
fs.rmSync(expandDir, { recursive: true, force: true });
8445
fs.rmSync(pkgPath, { force: true });
8546

86-
core.info("1Password CLI installed from MacOS .pkg");
47+
core.info("1Password CLI installed");
8748
}
8849
}

0 commit comments

Comments
 (0)