Skip to content

Commit 317a563

Browse files
Fix installation on macOS
1 parent 6b757c1 commit 317a563

File tree

7 files changed

+129
-129
lines changed

7 files changed

+129
-129
lines changed

dist/index.js

Lines changed: 105 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -68280,7 +68280,6 @@ class CliInstaller {
6828068280
;// CONCATENATED MODULE: ./src/cli-installer/linux.ts
6828168281

6828268282

68283-
6828468283
class LinuxInstaller extends CliInstaller {
6828568284
arch;
6828668285
version;
@@ -68291,7 +68290,6 @@ class LinuxInstaller extends CliInstaller {
6829168290
}
6829268291
async installCli() {
6829368292
const downloadUrl = this.downloadUrl();
68294-
core.info(`Downloading 1Password CLI ${this.version} from ${downloadUrl}`);
6829568293
await super.install(downloadUrl);
6829668294
}
6829768295
downloadUrl() {
@@ -68321,107 +68319,6 @@ var external_child_process_ = __nccwpck_require__(5317);
6832168319
// EXTERNAL MODULE: ./node_modules/semver/index.js
6832268320
var semver = __nccwpck_require__(2088);
6832368321
var semver_default = /*#__PURE__*/__nccwpck_require__.n(semver);
68324-
;// CONCATENATED MODULE: ./src/cli-installer/macos.ts
68325-
68326-
68327-
68328-
68329-
68330-
68331-
68332-
const execAsync = (0,external_util_.promisify)(external_child_process_.exec);
68333-
class MacOSInstaller extends CliInstaller {
68334-
arch;
68335-
version;
68336-
minVersionWithMacOSZipInstaller = "2.20.0";
68337-
constructor(version) {
68338-
super();
68339-
this.version = version;
68340-
this.arch = this.getArch();
68341-
}
68342-
async installCli() {
68343-
const downloadUrl = this.downloadUrl();
68344-
core.info(`Downloading 1Password CLI ${this.version} from ${downloadUrl}`);
68345-
await this.installOnMacOS(downloadUrl);
68346-
}
68347-
downloadUrl() {
68348-
// For versions before 2.20.0, use the .pkg installer
68349-
if (semver_default().lt(this.version, this.minVersionWithMacOSZipInstaller)) {
68350-
return `https://cache.agilebits.com/dist/1P/op2/pkg/${this.version}/op_apple_universal_${this.version}.pkg`;
68351-
}
68352-
return `https://cache.agilebits.com/dist/1P/op2/pkg/${this.version}/op_darwin_${this.arch}_${this.version}.zip`;
68353-
}
68354-
getArch() {
68355-
switch (process.env.RUNNER_ARCH) {
68356-
case RunnerArch.X64:
68357-
return "amd64";
68358-
case RunnerArch.ARM64:
68359-
return "arm64";
68360-
default:
68361-
throw new Error(`Unsupported RUNNER_ARCH value for macOS: ${process.env.RUNNER_ARCH}`);
68362-
}
68363-
}
68364-
// CLI releases <2.20.0 doesn't support `.zip` files, and uses `.pkg` files instead,
68365-
// Need to overwrite this to not introduce breaking changes.
68366-
async installOnMacOS(downloadUrl) {
68367-
if (semver_default().gte(this.version, this.minVersionWithMacOSZipInstaller)) {
68368-
await super.install(downloadUrl);
68369-
return;
68370-
}
68371-
core.info("Installing 1Password CLI using MacOS .pkg installer");
68372-
const pkgPath = await tool_cache.downloadTool(downloadUrl);
68373-
const { stderr } = await execAsync(`sudo installer -pkg ${pkgPath} -target /`);
68374-
if (stderr) {
68375-
core.error(stderr);
68376-
throw new Error(`Failed to install 1Password CLI: ${stderr}`);
68377-
}
68378-
core.info("1Password CLI installed from MacOS .pkg");
68379-
}
68380-
}
68381-
68382-
;// CONCATENATED MODULE: ./src/cli-installer/windows.ts
68383-
68384-
68385-
class WindowsInstaller extends CliInstaller {
68386-
arch;
68387-
version;
68388-
constructor(version) {
68389-
super();
68390-
this.version = version;
68391-
this.arch = "amd64"; // GitHub-hosted Windows runners (like windows-latest, windows-2022, windows-2019) are all 64-bit Windows Server VMs.
68392-
}
68393-
async installCli() {
68394-
const downloadUrl = this.downloadUrl();
68395-
core.info(`Downloading 1Password CLI ${this.version} from ${downloadUrl}`);
68396-
await super.install(downloadUrl);
68397-
}
68398-
downloadUrl() {
68399-
return `https://cache.agilebits.com/dist/1P/op2/pkg/${this.version}/op_windows_${this.arch}_${this.version}.zip`;
68400-
}
68401-
}
68402-
68403-
;// CONCATENATED MODULE: ./src/cli-installer/index.ts
68404-
68405-
68406-
68407-
// Defines the architecture of the runner executing the job.
68408-
// Look `RUNNER_ARCH` for possible values (https://docs.github.com/en/actions/reference/variables-reference).
68409-
var RunnerArch;
68410-
(function (RunnerArch) {
68411-
RunnerArch["X64"] = "X64";
68412-
RunnerArch["X86"] = "X86";
68413-
RunnerArch["ARM"] = "ARM";
68414-
RunnerArch["ARM64"] = "ARM64";
68415-
})(RunnerArch || (RunnerArch = {}));
68416-
// RunnerOS defines the operating system of the runner executing the job.
68417-
// Look `RUNNER_OS` for possible values (https://docs.github.com/en/actions/reference/variables-reference).
68418-
var RunnerOS;
68419-
(function (RunnerOS) {
68420-
RunnerOS["Linux"] = "Linux";
68421-
RunnerOS["MacOS"] = "macOS";
68422-
RunnerOS["Windows"] = "Windows";
68423-
})(RunnerOS || (RunnerOS = {}));
68424-
6842568322
;// CONCATENATED MODULE: ./src/version/constants.ts
6842668323
var ReleaseChannel;
6842768324
(function (ReleaseChannel) {
@@ -88231,7 +88128,7 @@ const findVersions = ($, query) => {
8823188128
});
8823288129
return versions;
8823388130
};
88234-
const normalizeBetaForSemver = (version) => version.replace(/-beta\.0*(\d+)/, "-beta.$1");
88131+
const normalizeForSemver = (version) => version.replace(/-beta\.0*(\d+)/, "-beta.$1");
8823588132
// Returns the latest version of the 1Password CLI based on the specified channel.
8823688133
const getLatestVersion = async (versionType) => {
8823788134
core.info(`Getting ${versionType} version number`);
@@ -88246,12 +88143,8 @@ const getLatestVersion = async (versionType) => {
8824688143
}
8824788144
// Sort versions in descending order
8824888145
versions.sort((a, b) => {
88249-
const na = normalizeBetaForSemver(a);
88250-
core.info(`Normalized version A: ${na}`);
88251-
const nb = normalizeBetaForSemver(b);
88252-
core.info(`Normalized version B: ${nb}`);
88253-
const aNorm = new (semver_default()).SemVer(na);
88254-
const bNorm = new (semver_default()).SemVer(nb);
88146+
const aNorm = new (semver_default()).SemVer(normalizeForSemver(a));
88147+
const bNorm = new (semver_default()).SemVer(normalizeForSemver(b));
8825588148
return semver_default().rcompare(aNorm, bNorm);
8825688149
});
8825788150
return versions[0];
@@ -88271,7 +88164,7 @@ const validateVersion = (input) => {
8827188164
// That's why we need to normalize them before validating.
8827288165
// Accepts valid semver versions like "2.18.0" or beta-releases like "2.19.0-beta.01"
8827388166
// or versions with 'v' prefix like "v2.19.0"
88274-
const normalized = normalizeBetaForSemver(input);
88167+
const normalized = normalizeForSemver(input);
8827588168
const normInput = new (semver_default()).SemVer(normalized);
8827688169
if (semver_default().valid(normInput)) {
8827788170
return;
@@ -88318,6 +88211,107 @@ class VersionResolver {
8831888211
;// CONCATENATED MODULE: ./src/version/index.ts
8831988212

8832088213

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

8832388317

src/cli-installer/linux.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { type Installer, RunnerArch } from "./index";
22
import { CliInstaller } from "./cli-installer";
3-
import * as core from "@actions/core";
43

54
export class LinuxInstaller extends CliInstaller implements Installer {
65
private readonly arch: string;
@@ -14,7 +13,6 @@ export class LinuxInstaller extends CliInstaller implements Installer {
1413

1514
async installCli(): Promise<void> {
1615
const downloadUrl = this.downloadUrl();
17-
core.info(`Downloading 1Password CLI ${this.version} from ${downloadUrl}`);
1816
await super.install(downloadUrl);
1917
}
2018

src/cli-installer/macos.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as core from "@actions/core";
55
import * as tc from "@actions/tool-cache";
66
import { CliInstaller } from "./cli-installer";
77
import { type Installer, RunnerArch } from "./index";
8+
import * as version from "../version";
89

910
const execAsync = promisify(exec);
1011

@@ -26,8 +27,13 @@ export class MacOSInstaller extends CliInstaller implements Installer {
2627
}
2728

2829
private downloadUrl(): string {
29-
// For versions before 2.20.0, use the .pkg installer
30-
if (semver.lt(this.version, this.minVersionWithMacOSZipInstaller)) {
30+
// For versions before 2.20.0, use the .pkg installer
31+
if (
32+
semver.lt(
33+
version.normalizeForSemver(this.version),
34+
this.minVersionWithMacOSZipInstaller,
35+
)
36+
) {
3137
return `https://cache.agilebits.com/dist/1P/op2/pkg/${this.version}/op_apple_universal_${this.version}.pkg`;
3238
}
3339

@@ -50,14 +56,21 @@ export class MacOSInstaller extends CliInstaller implements Installer {
5056
// CLI releases <2.20.0 doesn't support `.zip` files, and uses `.pkg` files instead,
5157
// Need to overwrite this to not introduce breaking changes.
5258
private async installOnMacOS(downloadUrl: string): Promise<void> {
53-
if (semver.gte(this.version, this.minVersionWithMacOSZipInstaller)) {
59+
if (
60+
semver.gte(
61+
version.normalizeForSemver(this.version),
62+
this.minVersionWithMacOSZipInstaller,
63+
)
64+
) {
5465
await super.install(downloadUrl);
5566
return;
5667
}
5768

5869
core.info("Installing 1Password CLI using MacOS .pkg installer");
5970
const pkgPath = await tc.downloadTool(downloadUrl);
60-
const { stderr } = await execAsync(`sudo installer -pkg ${pkgPath} -target /`);
71+
const { stderr } = await execAsync(
72+
`sudo installer -pkg ${pkgPath} -target /`,
73+
);
6174
if (stderr) {
6275
core.error(stderr);
6376
throw new Error(`Failed to install 1Password CLI: ${stderr}`);

src/cli-installer/windows.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { Installer } from "./index";
22
import { CliInstaller } from "./cli-installer";
3-
import * as core from "@actions/core";
43

54
export class WindowsInstaller extends CliInstaller implements Installer {
65
private readonly arch: string;
@@ -14,7 +13,6 @@ export class WindowsInstaller extends CliInstaller implements Installer {
1413

1514
async installCli(): Promise<void> {
1615
const downloadUrl = this.downloadUrl();
17-
core.info(`Downloading 1Password CLI ${this.version} from ${downloadUrl}`);
1816
await super.install(downloadUrl);
1917
}
2018

src/version/helper.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const findVersions = ($: cheerio.CheerioAPI, query: string): string[] => {
4141
return versions;
4242
};
4343

44-
export const normalizeBetaForSemver = (version: string): string =>
44+
export const normalizeForSemver = (version: string): string =>
4545
version.replace(/-beta\.0*(\d+)/, "-beta.$1");
4646

4747
// Returns the latest version of the 1Password CLI based on the specified channel.
@@ -63,12 +63,8 @@ export const getLatestVersion = async (
6363

6464
// Sort versions in descending order
6565
versions.sort((a: string, b: string): number => {
66-
const na = normalizeBetaForSemver(a);
67-
core.info(`Normalized version A: ${na}`);
68-
const nb = normalizeBetaForSemver(b);
69-
core.info(`Normalized version B: ${nb}`);
70-
const aNorm = new semver.SemVer(na);
71-
const bNorm = new semver.SemVer(nb);
66+
const aNorm = new semver.SemVer(normalizeForSemver(a));
67+
const bNorm = new semver.SemVer(normalizeForSemver(b));
7268
return semver.rcompare(aNorm, bNorm);
7369
});
7470

src/version/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { VersionResolver } from "./version-resolver";
2+
export { normalizeForSemver } from "./helper";

src/version/validate.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import semver from "semver";
22
import { ReleaseChannel } from "./constants";
3-
import {normalizeBetaForSemver} from "./helper";
3+
import { normalizeForSemver } from "./helper";
44

55
// Validates if the provided version type is a valid enum value or a valid semver version.
66
export const validateVersion = (input: string): void => {
@@ -13,8 +13,8 @@ export const validateVersion = (input: string): void => {
1313
// That's why we need to normalize them before validating.
1414
// Accepts valid semver versions like "2.18.0" or beta-releases like "2.19.0-beta.01"
1515
// or versions with 'v' prefix like "v2.19.0"
16-
const normalized = normalizeBetaForSemver(input)
17-
const normInput = new semver.SemVer(normalized)
16+
const normalized = normalizeForSemver(input);
17+
const normInput = new semver.SemVer(normalized);
1818
if (semver.valid(normInput)) {
1919
return;
2020
}

0 commit comments

Comments
 (0)