Skip to content

Commit 2a92683

Browse files
committed
Fix environment variable naming for nested actions
- Updated input forwarding to ensure proper GitHub Actions environment variable format - Converted hyphens to underscores in environment variable names - Added extensive fallback mechanism to find who-to-greet in various formats - Enhanced debugging to verify INPUT_WHO_TO_GREET is set properly
1 parent 76fe447 commit 2a92683

File tree

1 file changed

+56
-29
lines changed

1 file changed

+56
-29
lines changed

index.js

Lines changed: 56 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -578,16 +578,33 @@ async function runActionWithWitness(actionDir, witnessOptions) {
578578

579579
// If this is not a wrapper-specific input, preserve it for the nested action
580580
if (!wrapperSpecificInputs.includes(inputName)) {
581+
// The name GitHub Actions would use (replace hyphens with underscores)
582+
const normalizedKey = 'INPUT_' + inputName.replace(/-/g, '_');
583+
581584
// Passthrough any input that isn't specific to the wrapper
582-
core.info(`➡️ Forwarding ${key}="${process.env[key]}" to nested action`);
585+
core.info(`➡️ Forwarding ${normalizedKey}="${process.env[key]}" to nested action`);
583586

584-
// Re-set it in the environment to ensure it's passed to the subprocess
585-
envVars[key] = process.env[key];
587+
// Re-set it in the environment with proper naming (underscores, not hyphens)
588+
envVars[normalizedKey] = process.env[key];
586589
} else {
587590
core.debug(`Skipping wrapper-specific input: ${key}`);
588591
}
589592
});
590593

594+
// Explicitly look for the who-to-greet input in various forms
595+
let whoToGreetInput = Object.keys(process.env)
596+
.filter(key => key.toUpperCase().includes('WHO') && key.toUpperCase().includes('GREET'))
597+
.reduce((found, key) => {
598+
core.info(`Found potential who-to-greet input: ${key}=${process.env[key]}`);
599+
return found || process.env[key];
600+
}, null);
601+
602+
// If found, ensure it's correctly set in the normalized format
603+
if (whoToGreetInput) {
604+
envVars['INPUT_WHO_TO_GREET'] = whoToGreetInput;
605+
core.info(`✅ Explicitly set INPUT_WHO_TO_GREET="${whoToGreetInput}"`);
606+
}
607+
591608
// For debugging, log all environment vars being passed to the nested action
592609
core.info(`Passing these inputs to nested action Witness command:`);
593610
Object.keys(envVars)
@@ -596,16 +613,16 @@ async function runActionWithWitness(actionDir, witnessOptions) {
596613
core.info(` ${key}=${envVars[key]}`);
597614
});
598615

599-
// Debug specifically the who-to-greet input which is required for hello-world action
616+
// Final check for who-to-greet which is required for hello-world action
600617
if (envVars['INPUT_WHO_TO_GREET']) {
601-
core.info(`✅ Found required input WHO_TO_GREET = ${envVars['INPUT_WHO_TO_GREET']}`);
618+
core.info(`✅ Confirmed required INPUT_WHO_TO_GREET is set to "${envVars['INPUT_WHO_TO_GREET']}"`);
602619
} else {
603-
core.warning(`❌ Required input WHO_TO_GREET not found in environment variables!`);
604-
// Display all available input-* variables for debugging
605-
Object.keys(process.env)
606-
.filter(key => key.startsWith('INPUT_') && key.includes('WHO_TO_GREET'))
620+
core.warning(`❌ Required input INPUT_WHO_TO_GREET still not found in environment variables!`);
621+
// Display all available inputs for debugging
622+
Object.keys(envVars)
623+
.filter(key => key.startsWith('INPUT_'))
607624
.forEach(key => {
608-
core.warning(` Found similar input: ${key}=${process.env[key]}`);
625+
core.warning(` Available input: ${key}=${envVars[key]}`);
609626
});
610627
}
611628

@@ -899,16 +916,33 @@ async function runDirectCommandWithWitness(command, witnessOptions) {
899916

900917
// If this is not a wrapper-specific input, preserve it for the command
901918
if (!wrapperSpecificInputs.includes(inputName)) {
919+
// The name GitHub Actions would use (replace hyphens with underscores)
920+
const normalizedKey = 'INPUT_' + inputName.replace(/-/g, '_');
921+
902922
// Passthrough any input that isn't specific to the wrapper
903-
core.info(`➡️ For direct command: Forwarding ${key}="${process.env[key]}"`);
923+
core.info(`➡️ For direct command: Forwarding ${normalizedKey}="${process.env[key]}"`);
904924

905-
// Re-set it in the environment to ensure it's passed to the subprocess
906-
execOptions.env[key] = process.env[key];
925+
// Re-set it in the environment with proper naming (underscores, not hyphens)
926+
execOptions.env[normalizedKey] = process.env[key];
907927
} else {
908928
core.debug(`For direct command: Skipping wrapper-specific input: ${key}`);
909929
}
910930
});
911931

932+
// Explicitly look for the who-to-greet input in various forms
933+
let whoToGreetInput = Object.keys(process.env)
934+
.filter(key => key.toUpperCase().includes('WHO') && key.toUpperCase().includes('GREET'))
935+
.reduce((found, key) => {
936+
core.info(`For direct command: Found potential who-to-greet input: ${key}=${process.env[key]}`);
937+
return found || process.env[key];
938+
}, null);
939+
940+
// If found, ensure it's correctly set in the normalized format
941+
if (whoToGreetInput) {
942+
execOptions.env['INPUT_WHO_TO_GREET'] = whoToGreetInput;
943+
core.info(`✅ For direct command: Explicitly set INPUT_WHO_TO_GREET="${whoToGreetInput}"`);
944+
}
945+
912946
// For debugging, log all inputs that will be passed to the command
913947
core.info(`Direct command will have these inputs available:`);
914948
Object.keys(execOptions.env)
@@ -917,24 +951,17 @@ async function runDirectCommandWithWitness(command, witnessOptions) {
917951
core.info(` ${key}=${execOptions.env[key]}`);
918952
});
919953

920-
// Debug specifically the who-to-greet input which is required for hello-world action
954+
// Final check for who-to-greet which is required for hello-world action
921955
if (execOptions.env['INPUT_WHO_TO_GREET']) {
922-
core.info(`✅ For direct command: Found required input WHO_TO_GREET = ${execOptions.env['INPUT_WHO_TO_GREET']}`);
956+
core.info(`✅ For direct command: Confirmed required INPUT_WHO_TO_GREET is set to "${execOptions.env['INPUT_WHO_TO_GREET']}"`);
923957
} else {
924-
core.warning(`⚠️ For direct command: WHO_TO_GREET missing from envVars - adding it from explicit source`);
925-
const whoToGreet = process.env['INPUT_INPUT_WHO_TO_GREET'] || process.env['INPUT_WHO_TO_GREET'];
926-
if (whoToGreet) {
927-
execOptions.env['INPUT_WHO_TO_GREET'] = whoToGreet;
928-
core.info(`✓ Set INPUT_WHO_TO_GREET=${whoToGreet} from explicit source`);
929-
} else {
930-
core.error(`❌ Failed to find who-to-greet input in any form!`);
931-
// Display all available input-* variables for debugging
932-
Object.keys(process.env)
933-
.filter(key => key.startsWith('INPUT_') && key.includes('WHO'))
934-
.forEach(key => {
935-
core.warning(` Found similar input: ${key}=${process.env[key]}`);
936-
});
937-
}
958+
core.warning(`❌ For direct command: Required input INPUT_WHO_TO_GREET still not found in environment variables!`);
959+
// Display all available inputs for debugging
960+
Object.keys(execOptions.env)
961+
.filter(key => key.startsWith('INPUT_'))
962+
.forEach(key => {
963+
core.warning(` Available input: ${key}=${execOptions.env[key]}`);
964+
});
938965
}
939966

940967
// Execute and capture output

0 commit comments

Comments
 (0)