Optimize runtime of code

This commit is contained in:
Ethan Chiu
2020-06-18 17:34:17 -04:00
parent 96e003706f
commit 496064f72d
2 changed files with 25 additions and 7 deletions

View File

@@ -107,6 +107,7 @@ namespace GitHub.Runner.Worker
void RegisterPostJobStep(IStep step);
IStep RegisterCompositeStep(IStep step, DictionaryContextData inputsData, Dictionary<string, string> envData);
void EnqueueAllCompositeSteps(Queue<IStep> steps);
public void SetEnvironmentVariables(Dictionary<string, string> dict);
}
public sealed class ExecutionContext : RunnerService, IExecutionContext
@@ -298,14 +299,16 @@ namespace GitHub.Runner.Worker
// 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
foreach (var e in envData)
{
step.ExecutionContext.EnvironmentVariables[e.Key] = e.Value;
}
step.ExecutionContext.SetEnvironmentVariables(envData);
return step;
}
public void SetEnvironmentVariables(Dictionary<string, string> dict)
{
this.EnvironmentVariables = dict;
}
// Add Composite Steps first and then requeue the rest of the job steps.
public void EnqueueAllCompositeSteps(Queue<IStep> steps)
{
@@ -333,7 +336,6 @@ namespace GitHub.Runner.Worker
}
}
}
public IExecutionContext CreateChild(Guid recordId, string displayName, string refName, string scopeName, string contextName, Dictionary<string, string> intraActionState = null, int? recordOrder = null)
{
Trace.Entering();

View File

@@ -44,12 +44,28 @@ namespace GitHub.Runner.Worker.Handlers
inputsData[i.Key] = new StringContextData(i.Value);
}
// Get Environment Data for Composite Action
var extraExpressionValues = new Dictionary<string, PipelineContextData>(StringComparer.OrdinalIgnoreCase);
extraExpressionValues["inputs"] = inputsData;
var manifestManager = HostContext.GetService<IActionManifestManager>();
var envData = manifestManager.EvaluateCompositeActionEnvironment(ExecutionContext, Data.Environment, extraExpressionValues);
// 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
var compositeEnvData = manifestManager.EvaluateCompositeActionEnvironment(ExecutionContext, Data.Environment, extraExpressionValues);
var envData = new Dictionary<string, string>();
// Copy over parent environment
foreach (var env in ExecutionContext.EnvironmentVariables)
{
envData[env.Key] = env.Value;
}
// Overwrite with current env
foreach (var env in compositeEnvData)
{
envData[env.Key] = env.Value;
}
// Add each composite action step to the front of the queue
var compositeActionSteps = new Queue<IStep>();