|
| 1 | +import { exec } from "child_process"; |
| 2 | +import * as fs from "fs"; |
| 3 | +import * as path from "path"; |
| 4 | +import { promisify } from "util"; |
| 5 | +import * as core from "@actions/core"; |
| 6 | +import * as tc from "@actions/tool-cache"; |
| 7 | +import { CliInstaller, cliUrlBuilder } from "./cli-installer"; |
| 8 | +const execAsync = promisify(exec); |
| 9 | +export class MacOsInstaller extends CliInstaller { |
| 10 | + platform = "darwin"; // Node.js platform identifier for macOS |
| 11 | + constructor(version) { |
| 12 | + super(version); |
| 13 | + } |
| 14 | + async installCli() { |
| 15 | + const urlBuilder = cliUrlBuilder[this.platform]; |
| 16 | + await this.install(urlBuilder(this.version)); |
| 17 | + } |
| 18 | + // @actions/tool-cache package does not support .pkg files, so we need to handle the installation manually |
| 19 | + async install(downloadUrl) { |
| 20 | + console.info(`Downloading 1Password CLI from: ${downloadUrl}`); |
| 21 | + const pkgPath = await tc.downloadTool(downloadUrl); |
| 22 | + const pkgWithExtension = `${pkgPath}.pkg`; |
| 23 | + fs.renameSync(pkgPath, pkgWithExtension); |
| 24 | + const expandDir = "temp-pkg"; |
| 25 | + await execAsync(`pkgutil --expand "${pkgWithExtension}" "${expandDir}"`); |
| 26 | + const payloadPath = path.join(expandDir, "op.pkg", "Payload"); |
| 27 | + console.info("Installing 1Password CLI"); |
| 28 | + const cliPath = await tc.extractTar(payloadPath); |
| 29 | + core.addPath(cliPath); |
| 30 | + fs.rmSync(expandDir, { recursive: true, force: true }); |
| 31 | + fs.rmSync(pkgPath, { force: true }); |
| 32 | + core.info("1Password CLI installed"); |
| 33 | + } |
| 34 | +} |
0 commit comments