From f679968cb2a6ef1d6b31a3d823e84721f9c9a494 Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Fri, 14 Aug 2026 14:07:15 -0400 Subject: [PATCH] refactor: export into helper function Extract repeated env var export logic into a shared `exportEnvVar` helper, eliminating duplication across JSON and KEY=VALUE parsing paths in `processEnvVars`. Signed-off-by: Ryan Johnson --- dist/index.js | 30 ++++++++++++++---------------- dist/main.js | 30 ++++++++++++++---------------- src/main.ts | 31 +++++++++++++++---------------- 3 files changed, 43 insertions(+), 48 deletions(-) diff --git a/dist/index.js b/dist/index.js index de7bee9..e722c8b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -98352,6 +98352,18 @@ async function verifyInstallation() { void run().catch(error => { main_logger.setFailed(`Action failed: ${error instanceof Error ? error.message : String(error)}`); }); +/** + * Export a single environment variable to the process and GitHub Actions. + */ +function exportEnvVar(key, value) { + const trimmedKey = key.trim(); + const trimmedValue = value?.trim() || ''; + process.env[trimmedKey] = trimmedValue; + main_logger.exportVariable(trimmedKey, trimmedValue); + if (isVerbose) { + main_logger.debug(`Exported environment variable: ${trimmedKey}=${trimmedValue}`); + } +} /** * Process environment variables from input. * @param inputValue The environment variables input value @@ -98368,14 +98380,7 @@ function processEnvVars(inputValue) { if (typeof envVars === 'object' && envVars !== null) { for (const [key, value] of Object.entries(envVars)) { if (key) { - const trimmedKey = key.trim(); - const trimmedValue = value?.trim() || ''; - process.env[trimmedKey] = trimmedValue; - // Export using GitHub Actions' exportVariable to ensure it's available to subsequent steps. - main_logger.exportVariable(trimmedKey, trimmedValue); - if (isVerbose) { - main_logger.debug(`Exported environment variable: ${trimmedKey}=${trimmedValue}`); - } + exportEnvVar(key, value); } else { main_logger.warning(`Invalid environment variable format: ${key}`); @@ -98400,14 +98405,7 @@ function processEnvVars(inputValue) { if (match) { const [, key, value] = match; if (key) { - const trimmedKey = key.trim(); - const trimmedValue = value?.trim() || ''; - process.env[trimmedKey] = trimmedValue; - // Export using GitHub Actions' exportVariable to ensure it's available to subsequent steps. - main_logger.exportVariable(trimmedKey, trimmedValue); - if (isVerbose) { - main_logger.debug(`Exported variable: ${trimmedKey}=${trimmedValue}`); - } + exportEnvVar(key, value); } } else { diff --git a/dist/main.js b/dist/main.js index eea6f8f..002519d 100644 --- a/dist/main.js +++ b/dist/main.js @@ -205,6 +205,18 @@ async function verifyInstallation() { void run().catch(error => { logger.setFailed(`Action failed: ${error instanceof Error ? error.message : String(error)}`); }); +/** + * Export a single environment variable to the process and GitHub Actions. + */ +function exportEnvVar(key, value) { + const trimmedKey = key.trim(); + const trimmedValue = value?.trim() || ''; + process.env[trimmedKey] = trimmedValue; + logger.exportVariable(trimmedKey, trimmedValue); + if (isVerbose) { + logger.debug(`Exported environment variable: ${trimmedKey}=${trimmedValue}`); + } +} /** * Process environment variables from input. * @param inputValue The environment variables input value @@ -221,14 +233,7 @@ export function processEnvVars(inputValue) { if (typeof envVars === 'object' && envVars !== null) { for (const [key, value] of Object.entries(envVars)) { if (key) { - const trimmedKey = key.trim(); - const trimmedValue = value?.trim() || ''; - process.env[trimmedKey] = trimmedValue; - // Export using GitHub Actions' exportVariable to ensure it's available to subsequent steps. - logger.exportVariable(trimmedKey, trimmedValue); - if (isVerbose) { - logger.debug(`Exported environment variable: ${trimmedKey}=${trimmedValue}`); - } + exportEnvVar(key, value); } else { logger.warning(`Invalid environment variable format: ${key}`); @@ -253,14 +258,7 @@ export function processEnvVars(inputValue) { if (match) { const [, key, value] = match; if (key) { - const trimmedKey = key.trim(); - const trimmedValue = value?.trim() || ''; - process.env[trimmedKey] = trimmedValue; - // Export using GitHub Actions' exportVariable to ensure it's available to subsequent steps. - logger.exportVariable(trimmedKey, trimmedValue); - if (isVerbose) { - logger.debug(`Exported variable: ${trimmedKey}=${trimmedValue}`); - } + exportEnvVar(key, value); } } else { diff --git a/src/main.ts b/src/main.ts index 8744216..078c92b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -242,6 +242,19 @@ void run().catch(error => { logger.setFailed(`Action failed: ${error instanceof Error ? error.message : String(error)}`); }); +/** + * Export a single environment variable to the process and GitHub Actions. + */ +function exportEnvVar(key: string, value?: string): void { + const trimmedKey = key.trim(); + const trimmedValue = value?.trim() || ''; + process.env[trimmedKey] = trimmedValue; + logger.exportVariable(trimmedKey, trimmedValue); + if (isVerbose) { + logger.debug(`Exported environment variable: ${trimmedKey}=${trimmedValue}`); + } +} + /** * Process environment variables from input. * @param inputValue The environment variables input value @@ -259,14 +272,7 @@ export function processEnvVars(inputValue: string): boolean { if (typeof envVars === 'object' && envVars !== null) { for (const [key, value] of Object.entries(envVars)) { if (key) { - const trimmedKey = key.trim(); - const trimmedValue = value?.trim() || ''; - process.env[trimmedKey] = trimmedValue; - // Export using GitHub Actions' exportVariable to ensure it's available to subsequent steps. - logger.exportVariable(trimmedKey, trimmedValue); - if (isVerbose) { - logger.debug(`Exported environment variable: ${trimmedKey}=${trimmedValue}`); - } + exportEnvVar(key, value); } else { logger.warning(`Invalid environment variable format: ${key}`); } @@ -292,14 +298,7 @@ export function processEnvVars(inputValue: string): boolean { if (match) { const [, key, value] = match; if (key) { - const trimmedKey = key.trim(); - const trimmedValue = value?.trim() || ''; - process.env[trimmedKey] = trimmedValue; - // Export using GitHub Actions' exportVariable to ensure it's available to subsequent steps. - logger.exportVariable(trimmedKey, trimmedValue); - if (isVerbose) { - logger.debug(`Exported variable: ${trimmedKey}=${trimmedValue}`); - } + exportEnvVar(key, value); } } else { logger.warning(`Invalid variable format: ${line}`);