mirror of
https://github.com/actions/runner.git
synced 2025-12-11 04:46:58 +00:00
clean up
This commit is contained in:
@@ -183,7 +183,7 @@ namespace GitHub.Runner.Worker
|
||||
var context = CreateContext(executionContext, extraExpressionValues);
|
||||
try
|
||||
{
|
||||
var evaluateResult = TemplateEvaluator.Evaluate(context, "container-runs-env", token, 0, null, omitHeader: true);
|
||||
var evaluateResult = TemplateEvaluator.Evaluate(context, "runs-env", token, 0, null, omitHeader: true);
|
||||
context.Errors.Check();
|
||||
|
||||
Trace.Info($"Environments evaluate result: {StringUtil.ConvertToJson(evaluateResult)}");
|
||||
@@ -215,8 +215,6 @@ namespace GitHub.Runner.Worker
|
||||
return result;
|
||||
}
|
||||
|
||||
// TODO: Add Evaluate Composite Action Env Function Here
|
||||
// Steps will be evaluated already in StepsRunner
|
||||
public Dictionary<string, string> EvaluateCompositeActionEnvironment(
|
||||
IExecutionContext executionContext,
|
||||
MappingToken token,
|
||||
@@ -229,34 +227,19 @@ namespace GitHub.Runner.Worker
|
||||
var context = CreateContext(executionContext, extraExpressionValues);
|
||||
try
|
||||
{
|
||||
var evaluateResult = TemplateEvaluator.Evaluate(context, "container-runs-env", token, 0, null, omitHeader: true);
|
||||
var evaluateResult = TemplateEvaluator.Evaluate(context, "runs-env", token, 0, null, omitHeader: true);
|
||||
context.Errors.Check();
|
||||
if (evaluateResult != null) {
|
||||
Trace.Info($"EvaluateCompositeActionEnvironment evaluateResult {evaluateResult}");
|
||||
} else {
|
||||
Trace.Info($"EvaluateCompositeActionEnvironment evaluateResult is null");
|
||||
}
|
||||
|
||||
|
||||
Trace.Info($"Composite Action Environments evaluate result: {StringUtil.ConvertToJson(evaluateResult)}");
|
||||
|
||||
// Mapping
|
||||
var mapping = evaluateResult.AssertMapping("composite env");
|
||||
if (mapping != null) {
|
||||
Trace.Info($"EvaluateCompositeActionEnvironment Mapping {mapping}");
|
||||
} else {
|
||||
Trace.Info($"EvaluateCompositeActionEnvironment Mapping is null");
|
||||
}
|
||||
|
||||
foreach (var pair in mapping)
|
||||
{
|
||||
// Literal key
|
||||
var key = pair.Key.AssertString("composite env key");
|
||||
Trace.Info($"EvaluateCompositeActionEnvironment Key{key.Value}");
|
||||
|
||||
// Literal value
|
||||
var value = pair.Value.AssertString("composite env value");
|
||||
Trace.Info($"EvaluateCompositeActionEnvironment Value{value.Value}");
|
||||
result[key.Value] = value.Value;
|
||||
|
||||
Trace.Info($"Add env {key} = {value}");
|
||||
|
||||
@@ -105,9 +105,8 @@ namespace GitHub.Runner.Worker
|
||||
// others
|
||||
void ForceTaskComplete();
|
||||
void RegisterPostJobStep(IStep step);
|
||||
IStep RegisterCompositeStep(IStep step, DictionaryContextData inputsData, PipelineContextData envData);
|
||||
IStep RegisterCompositeStep(IStep step, DictionaryContextData inputsData, Dictionary<string, string> envData);
|
||||
void EnqueueAllCompositeSteps(Queue<IStep> steps);
|
||||
ExecutionContext getParentExecutionContext();
|
||||
}
|
||||
|
||||
public sealed class ExecutionContext : RunnerService, IExecutionContext
|
||||
@@ -272,7 +271,7 @@ namespace GitHub.Runner.Worker
|
||||
RegisterCompositeStep is a helper function used in CompositeActionHandler::RunAsync to
|
||||
add a child node, aka a step, to the current job to the front of the queue for processing.
|
||||
*/
|
||||
public IStep RegisterCompositeStep(IStep step, DictionaryContextData inputsData, PipelineContextData envData)
|
||||
public IStep RegisterCompositeStep(IStep step, DictionaryContextData inputsData, Dictionary<string, string> envData)
|
||||
{
|
||||
// ~Brute Force Method~
|
||||
// There is no way to put this current job in front of the queue in < O(n) time where n = # of elements in JobSteps
|
||||
@@ -297,10 +296,15 @@ namespace GitHub.Runner.Worker
|
||||
var newGuid = Guid.NewGuid();
|
||||
step.ExecutionContext = Root.CreateChild(newGuid, step.DisplayName, newGuid.ToString("N"), null, null);
|
||||
step.ExecutionContext.ExpressionValues["inputs"] = inputsData;
|
||||
step.ExecutionContext.ExpressionValues["env"] = envData;
|
||||
|
||||
// TODO add environment variables for individual composite action steps
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
return step;
|
||||
}
|
||||
|
||||
@@ -334,11 +338,6 @@ namespace GitHub.Runner.Worker
|
||||
}
|
||||
}
|
||||
|
||||
public ExecutionContext getParentExecutionContext()
|
||||
{
|
||||
return _parentExecutionContext;
|
||||
}
|
||||
|
||||
public IExecutionContext CreateChild(Guid recordId, string displayName, string refName, string scopeName, string contextName, Dictionary<string, string> intraActionState = null, int? recordOrder = null)
|
||||
{
|
||||
Trace.Entering();
|
||||
|
||||
@@ -36,14 +36,6 @@ namespace GitHub.Runner.Worker.Handlers
|
||||
|
||||
// Resolve action steps
|
||||
var actionSteps = Data.Steps;
|
||||
if (actionSteps == null)
|
||||
{
|
||||
Trace.Error("Data.Steps in CompositeActionHandler is null");
|
||||
}
|
||||
else
|
||||
{
|
||||
Trace.Info($"Data Steps Value for Composite Actions is: {actionSteps}.");
|
||||
}
|
||||
|
||||
// Create Context Data to reuse for each composite action step
|
||||
var inputsData = new DictionaryContextData();
|
||||
@@ -52,31 +44,12 @@ namespace GitHub.Runner.Worker.Handlers
|
||||
inputsData[i.Key] = new StringContextData(i.Value);
|
||||
}
|
||||
|
||||
// Set up parent's environment data and then add on composite action environment data
|
||||
#if OS_WINDOWS
|
||||
var envData = ExecutionContext.ExpressionValues["env"].Clone() as DictionaryContextData;
|
||||
#else
|
||||
var envData = ExecutionContext.ExpressionValues["env"].Clone() as CaseSensitiveDictionaryContextData;
|
||||
#endif
|
||||
// Composite action will have already inherited the root env attributes.
|
||||
// We evaluated the env simimilar to how ContainerActionHandler does it.
|
||||
if (Data.Environment == null) {
|
||||
Trace.Info($"Composite Env Mapping Token is null");
|
||||
} else {
|
||||
Trace.Info($"Composite Env Mapping Token {Data.Environment}");
|
||||
}
|
||||
|
||||
// Get Environment Data for Composite Action
|
||||
var extraExpressionValues = new Dictionary<string, PipelineContextData>(StringComparer.OrdinalIgnoreCase);
|
||||
extraExpressionValues["inputs"] = inputsData;
|
||||
var manifestManager = HostContext.GetService<IActionManifestManager>();
|
||||
var evaluatedEnv = manifestManager.EvaluateCompositeActionEnvironment(ExecutionContext, Data.Environment, extraExpressionValues);
|
||||
foreach (var e in evaluatedEnv)
|
||||
{
|
||||
// How to add to EnvironmentContextData
|
||||
// We need to use IEnvironmentContextData because ScriptHandler uses this type for environment variables
|
||||
Trace.Info($"Composite Action Env Key: {e.Key}");
|
||||
Trace.Info($"Composite Action Env Value: {e.Value}");
|
||||
envData[e.Key] = new StringContextData(e.Value);
|
||||
}
|
||||
var envData = manifestManager.EvaluateCompositeActionEnvironment(ExecutionContext, Data.Environment, extraExpressionValues);
|
||||
|
||||
// Add each composite action step to the front of the queue
|
||||
var compositeActionSteps = new Queue<IStep>();
|
||||
|
||||
@@ -255,14 +255,6 @@ namespace GitHub.Runner.Worker.Handlers
|
||||
Environment[env.Key] = env.Value;
|
||||
}
|
||||
}
|
||||
|
||||
// if (context.Key == "env" && context.Value != null && !String.IsNullOrEmpty(System.Environment.GetEnvironmentVariable("TESTING_COMPOSITE_ACTIONS_ALPHA")))
|
||||
// {
|
||||
// foreach (var env in context.Value as DictionaryContextData)
|
||||
// {
|
||||
// Environment[env.Key] = env.Value as StringContextData;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
// dump out the command
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
"image": "non-empty-string",
|
||||
"entrypoint": "non-empty-string",
|
||||
"args": "container-runs-args",
|
||||
"env": "container-runs-env",
|
||||
"env": "runs-env",
|
||||
"pre-entrypoint": "non-empty-string",
|
||||
"pre-if": "non-empty-string",
|
||||
"post-entrypoint": "non-empty-string",
|
||||
@@ -56,7 +56,7 @@
|
||||
"item-type": "container-runs-context"
|
||||
}
|
||||
},
|
||||
"container-runs-env": {
|
||||
"runs-env": {
|
||||
"context": [
|
||||
"inputs"
|
||||
],
|
||||
@@ -88,7 +88,7 @@
|
||||
"mapping": {
|
||||
"properties": {
|
||||
"using": "non-empty-string",
|
||||
"env": "container-runs-env",
|
||||
"env": "runs-env",
|
||||
"steps": "composite-steps"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user