Skip to content

Commit 39c6643

Browse files
Revert to install CLI script
1 parent c16cc93 commit 39c6643

File tree

4 files changed

+109
-11
lines changed

4 files changed

+109
-11
lines changed

.github/workflows/acceptance-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090
if: ${{ inputs.export-env }}
9191
uses: ./ # 1password/load-secrets-action@<version>
9292
with:
93-
unset-previous: "true"
93+
unset-previous: true
9494
- name: Assert removed secrets [exported env]
9595
if: ${{ inputs.export-env }}
9696
run: ./tests/assert-env-unset.sh

action.yml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@ inputs:
1414
export-env:
1515
description: Export the secrets as environment variables
1616
default: "true"
17+
#runs:
18+
# using: "composite"
19+
# steps:
20+
# - name: Install 1Password CLI
21+
# uses: 1password/install-cli-action@main # change to v2 as soon as install-cli-action@v2 released
22+
# with:
23+
# version: ${{ inputs.version }}
24+
#
25+
# - name: Load secrets
26+
# shell: bash
27+
# run: node dist/index.js
1728
runs:
18-
using: "composite"
19-
steps:
20-
- name: Install 1Password CLI
21-
uses: 1password/install-cli-action@main # change to v2 as soon as install-cli-action@v2 released
22-
with:
23-
version: ${{ inputs.version }}
24-
25-
- name: Load secrets
26-
shell: bash
27-
run: node dist/index.js
29+
using: "node20"
30+
main: "dist/index.js"

dist/index.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29227,13 +29227,48 @@ module.exports = /*#__PURE__*/JSON.parse('{"name":"@1password/op-js","version":"
2922729227
/******/ }
2922829228
/******/
2922929229
/************************************************************************/
29230+
/******/ /* webpack/runtime/compat get default export */
29231+
/******/ (() => {
29232+
/******/ // getDefaultExport function for compatibility with non-harmony modules
29233+
/******/ __nccwpck_require__.n = (module) => {
29234+
/******/ var getter = module && module.__esModule ?
29235+
/******/ () => (module['default']) :
29236+
/******/ () => (module);
29237+
/******/ __nccwpck_require__.d(getter, { a: getter });
29238+
/******/ return getter;
29239+
/******/ };
29240+
/******/ })();
29241+
/******/
29242+
/******/ /* webpack/runtime/define property getters */
29243+
/******/ (() => {
29244+
/******/ // define getter functions for harmony exports
29245+
/******/ __nccwpck_require__.d = (exports, definition) => {
29246+
/******/ for(var key in definition) {
29247+
/******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) {
29248+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
29249+
/******/ }
29250+
/******/ }
29251+
/******/ };
29252+
/******/ })();
29253+
/******/
29254+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
29255+
/******/ (() => {
29256+
/******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
29257+
/******/ })();
29258+
/******/
2923029259
/******/ /* webpack/runtime/compat */
2923129260
/******/
2923229261
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = new URL('.', import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/) ? 1 : 0, -1) + "/";
2923329262
/******/
2923429263
/************************************************************************/
2923529264
var __webpack_exports__ = {};
2923629265

29266+
// EXTERNAL MODULE: external "path"
29267+
var external_path_ = __nccwpck_require__(6928);
29268+
var external_path_default = /*#__PURE__*/__nccwpck_require__.n(external_path_);
29269+
// EXTERNAL MODULE: external "url"
29270+
var external_url_ = __nccwpck_require__(7016);
29271+
var external_url_default = /*#__PURE__*/__nccwpck_require__.n(external_url_);
2923729272
// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js
2923829273
var core = __nccwpck_require__(7484);
2923929274
// EXTERNAL MODULE: ./node_modules/@actions/exec/lib/exec.js
@@ -29321,6 +29356,10 @@ const unsetPrevious = () => {
2932129356
;// CONCATENATED MODULE: ./src/index.ts
2932229357

2932329358

29359+
29360+
29361+
29362+
2932429363
const loadSecretsAction = async () => {
2932529364
try {
2932629365
// Get action inputs
@@ -29332,6 +29371,8 @@ const loadSecretsAction = async () => {
2933229371
}
2933329372
// Validate that a proper authentication configuration is set for the CLI
2933429373
validateAuth();
29374+
// Download and install the CLI
29375+
await installCLI();
2933529376
// Load secrets
2933629377
await loadSecrets(shouldExportEnv);
2933729378
}
@@ -29349,5 +29390,26 @@ const loadSecretsAction = async () => {
2934929390
core.setFailed(message);
2935029391
}
2935129392
};
29393+
// This function's name is an exception from the naming convention
29394+
// since we refer to the 1Password CLI here.
29395+
// eslint-disable-next-line @typescript-eslint/naming-convention
29396+
const installCLI = async () => {
29397+
// validateCli checks if there's an existing 1Password CLI installed on the runner.
29398+
// If there's no CLI installed, then validateCli will throw an error, which we will use
29399+
// as an indicator that we need to execute the installation script.
29400+
await (0,dist.validateCli)().catch(async () => {
29401+
const currentFile = external_url_default().fileURLToPath(import.meta.url);
29402+
const currentDir = external_path_default().dirname(currentFile);
29403+
const parentDir = external_path_default().resolve(currentDir, "..");
29404+
// Execute bash script
29405+
const cmdOut = await exec.getExecOutput(`sh -c "` + parentDir + `/install_cli.sh"`);
29406+
// Add path to 1Password CLI to $PATH
29407+
const outArr = cmdOut.stdout.split("\n");
29408+
if (outArr[0] && process.env.PATH) {
29409+
const cliPath = outArr[0]?.replace(/^(::debug::OP_INSTALL_DIR: )/, "");
29410+
core.addPath(cliPath);
29411+
}
29412+
});
29413+
};
2935229414
void loadSecretsAction();
2935329415

src/index.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
import path from "path";
2+
import url from "url";
13
import * as core from "@actions/core";
4+
import * as exec from "@actions/exec";
5+
import { validateCli } from "@1password/op-js";
26
import { loadSecrets, unsetPrevious, validateAuth } from "./utils";
37

48
const loadSecretsAction = async () => {
@@ -15,6 +19,9 @@ const loadSecretsAction = async () => {
1519
// Validate that a proper authentication configuration is set for the CLI
1620
validateAuth();
1721

22+
// Download and install the CLI
23+
await installCLI();
24+
1825
// Load secrets
1926
await loadSecrets(shouldExportEnv);
2027
} catch (error) {
@@ -31,4 +38,30 @@ const loadSecretsAction = async () => {
3138
}
3239
};
3340

41+
// This function's name is an exception from the naming convention
42+
// since we refer to the 1Password CLI here.
43+
// eslint-disable-next-line @typescript-eslint/naming-convention
44+
const installCLI = async (): Promise<void> => {
45+
// validateCli checks if there's an existing 1Password CLI installed on the runner.
46+
// If there's no CLI installed, then validateCli will throw an error, which we will use
47+
// as an indicator that we need to execute the installation script.
48+
await validateCli().catch(async () => {
49+
const currentFile = url.fileURLToPath(import.meta.url);
50+
const currentDir = path.dirname(currentFile);
51+
const parentDir = path.resolve(currentDir, "..");
52+
53+
// Execute bash script
54+
const cmdOut = await exec.getExecOutput(
55+
`sh -c "` + parentDir + `/install_cli.sh"`,
56+
);
57+
58+
// Add path to 1Password CLI to $PATH
59+
const outArr = cmdOut.stdout.split("\n");
60+
if (outArr[0] && process.env.PATH) {
61+
const cliPath = outArr[0]?.replace(/^(::debug::OP_INSTALL_DIR: )/, "");
62+
core.addPath(cliPath);
63+
}
64+
});
65+
};
66+
3467
void loadSecretsAction();

0 commit comments

Comments
 (0)