Skip to content

Commit d442de0

Browse files
Pass env vars to node.js script as env vars
1 parent 39c6643 commit d442de0

File tree

3 files changed

+13
-108
lines changed

3 files changed

+13
-108
lines changed

action.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +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
2817
runs:
29-
using: "node20"
30-
main: "dist/index.js"
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: |
28+
export INPUT_UNSET_PREVIOUS="${{ inputs.unset-previous }}"
29+
export INPUT_EXPORT_ENV="${{ inputs.export-env }}"
30+
node dist/index.js

dist/index.js

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -29227,48 +29227,13 @@ 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-
/******/
2925929230
/******/ /* webpack/runtime/compat */
2926029231
/******/
2926129232
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = new URL('.', import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/) ? 1 : 0, -1) + "/";
2926229233
/******/
2926329234
/************************************************************************/
2926429235
var __webpack_exports__ = {};
2926529236

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_);
2927229237
// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js
2927329238
var core = __nccwpck_require__(7484);
2927429239
// EXTERNAL MODULE: ./node_modules/@actions/exec/lib/exec.js
@@ -29356,10 +29321,6 @@ const unsetPrevious = () => {
2935629321
;// CONCATENATED MODULE: ./src/index.ts
2935729322

2935829323

29359-
29360-
29361-
29362-
2936329324
const loadSecretsAction = async () => {
2936429325
try {
2936529326
// Get action inputs
@@ -29371,8 +29332,6 @@ const loadSecretsAction = async () => {
2937129332
}
2937229333
// Validate that a proper authentication configuration is set for the CLI
2937329334
validateAuth();
29374-
// Download and install the CLI
29375-
await installCLI();
2937629335
// Load secrets
2937729336
await loadSecrets(shouldExportEnv);
2937829337
}
@@ -29390,26 +29349,5 @@ const loadSecretsAction = async () => {
2939029349
core.setFailed(message);
2939129350
}
2939229351
};
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-
};
2941429352
void loadSecretsAction();
2941529353

src/index.ts

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

84
const loadSecretsAction = async () => {
@@ -19,9 +15,6 @@ const loadSecretsAction = async () => {
1915
// Validate that a proper authentication configuration is set for the CLI
2016
validateAuth();
2117

22-
// Download and install the CLI
23-
await installCLI();
24-
2518
// Load secrets
2619
await loadSecrets(shouldExportEnv);
2720
} catch (error) {
@@ -38,30 +31,4 @@ const loadSecretsAction = async () => {
3831
}
3932
};
4033

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-
6734
void loadSecretsAction();

0 commit comments

Comments
 (0)