mirror of
https://github.com/actions/runner.git
synced 2025-12-12 15:13:30 +00:00
Composite Actions: Support Env Flow (#557)
* Composite Action Run Steps * Env Flow => Able to get env variables and overwrite current env variables => but it doesn't 'stick' * clean up * Clean up trace messages + add Trace debug in ActionManager * Add debugging message * Optimize runtime of code * Change String to string * Add comma to Composite * Change JobSteps to a List, Change Register Step function name * Add TODO, remove unn. content * Remove unnecessary code * Fix unit tests * Fix env format * Remove comment * Remove TODO message for context * Add verbose trace logs which are only viewable by devs * Sort usings in Composite Action Handler * Change 0 to location * Update context variables in composite action yaml * Add helpful error message for null steps * Fix Workflow Step Env overiding Parent Env * Remove env in composite action scope * Clean up * Revert back * revert back * add back envToken * Remove unnecessary code * Figure out how to handle set-env edge cases * formatting * fix unit tests * Fix windows unit test syntax error
This commit is contained in:
@@ -105,7 +105,7 @@ namespace GitHub.Runner.Worker
|
||||
// others
|
||||
void ForceTaskComplete();
|
||||
void RegisterPostJobStep(IStep step);
|
||||
void RegisterNestedStep(IStep step, DictionaryContextData inputsData, int location);
|
||||
void RegisterNestedStep(IStep step, DictionaryContextData inputsData, int location, Dictionary<string, string> envData);
|
||||
}
|
||||
|
||||
public sealed class ExecutionContext : RunnerService, IExecutionContext
|
||||
@@ -270,13 +270,28 @@ namespace GitHub.Runner.Worker
|
||||
/// Helper function used in CompositeActionHandler::RunAsync to
|
||||
/// add a child node, aka a step, to the current job to the Root.JobSteps based on the location.
|
||||
/// </summary>
|
||||
public void RegisterNestedStep(IStep step, DictionaryContextData inputsData, int location)
|
||||
public void RegisterNestedStep(IStep step, DictionaryContextData inputsData, int location, Dictionary<string, string> envData)
|
||||
{
|
||||
// TODO: For UI purposes, look at figuring out how to condense steps in one node => maybe use the same previous GUID
|
||||
var newGuid = Guid.NewGuid();
|
||||
step.ExecutionContext = Root.CreateChild(newGuid, step.DisplayName, newGuid.ToString("N"), null, null);
|
||||
step.ExecutionContext.ExpressionValues["inputs"] = inputsData;
|
||||
// TODO: confirm whether not copying message contexts is safe
|
||||
|
||||
// Add the composite action environment variables to each step.
|
||||
// If the key already exists, we override it since the composite action env variables will have higher precedence
|
||||
// Note that for each composite action step, it's environment variables will be set in the StepRunner automatically
|
||||
// step.ExecutionContext.SetEnvironmentVariables(envData);
|
||||
#if OS_WINDOWS
|
||||
var envContext = new DictionaryContextData();
|
||||
#else
|
||||
var envContext = new CaseSensitiveDictionaryContextData();
|
||||
#endif
|
||||
foreach (var pair in envData)
|
||||
{
|
||||
envContext[pair.Key] = new StringContextData(pair.Value ?? string.Empty);
|
||||
}
|
||||
step.ExecutionContext.ExpressionValues["env"] = envContext;
|
||||
|
||||
Root.JobSteps.Insert(location, step);
|
||||
}
|
||||
|
||||
|
||||
@@ -84,10 +84,8 @@ namespace GitHub.Runner.Worker.Handlers
|
||||
actionRunner.Stage = stage;
|
||||
actionRunner.Condition = aStep.Condition;
|
||||
actionRunner.DisplayName = aStep.DisplayName;
|
||||
// TODO: Do we need to add any context data from the job message?
|
||||
// (See JobExtension.cs ~line 236)
|
||||
|
||||
ExecutionContext.RegisterNestedStep(actionRunner, inputsData, location);
|
||||
ExecutionContext.RegisterNestedStep(actionRunner, inputsData, location, Environment);
|
||||
location++;
|
||||
}
|
||||
|
||||
|
||||
@@ -93,12 +93,28 @@ namespace GitHub.Runner.Worker
|
||||
#else
|
||||
var envContext = new CaseSensitiveDictionaryContextData();
|
||||
#endif
|
||||
step.ExecutionContext.ExpressionValues["env"] = envContext;
|
||||
// Global env
|
||||
foreach (var pair in step.ExecutionContext.EnvironmentVariables)
|
||||
{
|
||||
envContext[pair.Key] = new StringContextData(pair.Value ?? string.Empty);
|
||||
}
|
||||
|
||||
// Stomps over with outside step env
|
||||
if (step.ExecutionContext.ExpressionValues.TryGetValue("env", out var envContextData))
|
||||
{
|
||||
#if OS_WINDOWS
|
||||
var dict = envContextData as DictionaryContextData;
|
||||
#else
|
||||
var dict = envContextData as CaseSensitiveDictionaryContextData;
|
||||
#endif
|
||||
foreach (var pair in dict)
|
||||
{
|
||||
envContext[pair.Key] = pair.Value;
|
||||
}
|
||||
}
|
||||
|
||||
step.ExecutionContext.ExpressionValues["env"] = envContext;
|
||||
|
||||
bool evaluateStepEnvFailed = false;
|
||||
if (step is IActionRunner actionStep)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user