From 96de6567974eb13848ffb376ce149ac15cbcfbba Mon Sep 17 00:00:00 2001 From: Volodymyr Zotov Date: Wed, 30 Jul 2025 12:25:30 -0500 Subject: [PATCH] Re-write configure action in JS --- .gitignore | 2 +- configure/action.yml | 11 ++--------- configure/dist/index.js | 34 ++++++++++++++++++++++++++++++++++ configure/dist/package.json | 3 +++ configure/entrypoint.sh | 21 --------------------- configure/index.js | 27 +++++++++++++++++++++++++++ package.json | 1 + 7 files changed, 68 insertions(+), 31 deletions(-) create mode 100644 configure/dist/index.js create mode 100644 configure/dist/package.json delete mode 100755 configure/entrypoint.sh create mode 100644 configure/index.js diff --git a/.gitignore b/.gitignore index b509c88..f387123 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ coverage/ -node_modules/ +node_modules/ \ No newline at end of file diff --git a/configure/action.yml b/configure/action.yml index 40ab9eb..6754684 100644 --- a/configure/action.yml +++ b/configure/action.yml @@ -9,12 +9,5 @@ inputs: service-account-token: description: Your 1Password service account token runs: - using: composite - steps: - - shell: bash - env: - INPUT_CONNECT_HOST: ${{ inputs.connect-host }} - INPUT_CONNECT_TOKEN: ${{ inputs.connect-token }} - INPUT_SERVICE_ACCOUNT_TOKEN: ${{ inputs.service-account-token }} - run: | - ${{ github.action_path }}/entrypoint.sh + using: "node20" + main: "dist/index.js" diff --git a/configure/dist/index.js b/configure/dist/index.js new file mode 100644 index 0000000..1d8add8 --- /dev/null +++ b/configure/dist/index.js @@ -0,0 +1,34 @@ +/******/ /* webpack/runtime/compat */ +/******/ +/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = new URL('.', import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/) ? 1 : 0, -1) + "/"; +/******/ +/************************************************************************/ +var __webpack_exports__ = {}; +const core = require("@actions/core"); + +const configure = () => { + const OP_CONNECT_HOST = + core.getInput("connect-host", { required: false }) || + process.env.OP_CONNECT_HOST; + const OP_CONNECT_TOKEN = + core.getInput("connect-token", { required: false }) || + process.env.OP_CONNECT_TOKEN; + const OP_SERVICE_ACCOUNT_TOKEN = + core.getInput("service-account-token", { required: false }) || + process.env.OP_SERVICE_ACCOUNT_TOKEN; + + if (OP_CONNECT_HOST) { + core.exportVariable("OP_CONNECT_HOST", OP_CONNECT_HOST); + } + + if (OP_CONNECT_TOKEN) { + core.exportVariable("OP_CONNECT_TOKEN", OP_CONNECT_TOKEN); + } + + if (OP_SERVICE_ACCOUNT_TOKEN) { + core.exportVariable("OP_SERVICE_ACCOUNT_TOKEN", OP_SERVICE_ACCOUNT_TOKEN); + } +}; + +configure(); + diff --git a/configure/dist/package.json b/configure/dist/package.json new file mode 100644 index 0000000..3dbc1ca --- /dev/null +++ b/configure/dist/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/configure/entrypoint.sh b/configure/entrypoint.sh deleted file mode 100755 index 571791c..0000000 --- a/configure/entrypoint.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -# shellcheck disable=SC2086 -set -e - -# Capture Connect configuration in $GITHUB_ENV, giving (optional) inputs -# precendence over OP_CONNECT_* environment variables. - -OP_CONNECT_HOST="${INPUT_CONNECT_HOST:-$OP_CONNECT_HOST}" -if [ -n "$OP_CONNECT_HOST" ]; then - echo "OP_CONNECT_HOST=$OP_CONNECT_HOST" >> $GITHUB_ENV -fi - -OP_CONNECT_TOKEN="${INPUT_CONNECT_TOKEN:-$OP_CONNECT_TOKEN}" -if [ -n "$OP_CONNECT_TOKEN" ]; then - echo "OP_CONNECT_TOKEN=$OP_CONNECT_TOKEN" >> $GITHUB_ENV -fi - -OP_SERVICE_ACCOUNT_TOKEN="${INPUT_SERVICE_ACCOUNT_TOKEN:-$OP_SERVICE_ACCOUNT_TOKEN}" -if [ -n "$OP_SERVICE_ACCOUNT_TOKEN" ]; then - echo "OP_SERVICE_ACCOUNT_TOKEN=$OP_SERVICE_ACCOUNT_TOKEN" >> $GITHUB_ENV -fi diff --git a/configure/index.js b/configure/index.js new file mode 100644 index 0000000..5f3485d --- /dev/null +++ b/configure/index.js @@ -0,0 +1,27 @@ +const core = require("@actions/core"); + +const configure = () => { + const OP_CONNECT_HOST = + core.getInput("connect-host", { required: false }) || + process.env.OP_CONNECT_HOST; + const OP_CONNECT_TOKEN = + core.getInput("connect-token", { required: false }) || + process.env.OP_CONNECT_TOKEN; + const OP_SERVICE_ACCOUNT_TOKEN = + core.getInput("service-account-token", { required: false }) || + process.env.OP_SERVICE_ACCOUNT_TOKEN; + + if (OP_CONNECT_HOST) { + core.exportVariable("OP_CONNECT_HOST", OP_CONNECT_HOST); + } + + if (OP_CONNECT_TOKEN) { + core.exportVariable("OP_CONNECT_TOKEN", OP_CONNECT_TOKEN); + } + + if (OP_SERVICE_ACCOUNT_TOKEN) { + core.exportVariable("OP_SERVICE_ACCOUNT_TOKEN", OP_SERVICE_ACCOUNT_TOKEN); + } +}; + +configure(); diff --git a/package.json b/package.json index e41bfaa..27d30b2 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ }, "scripts": { "build": "ncc build ./src/index.ts", + "build:configure": "ncc build ./configure/index.js -o ./configure/dist", "format": "prettier --ignore-path ./config/.prettierignore", "format:check": "npm run format -- --check ./", "format:write": "npm run format -- --write ./",