minor cleanup in composite (#1045)

This commit is contained in:
eric sciple
2021-04-30 15:48:53 -05:00
committed by GitHub
parent 5941cceb7c
commit 7cc689b0d9
6 changed files with 136 additions and 174 deletions

View File

@@ -82,24 +82,21 @@ namespace GitHub.Runner.Worker
step.ExecutionContext.ExpressionFunctions.Add(new FunctionInfo<SuccessFunction>(PipelineTemplateConstants.Success, 0, 0));
step.ExecutionContext.ExpressionFunctions.Add(new FunctionInfo<HashFilesFunction>(PipelineTemplateConstants.HashFiles, 1, byte.MaxValue));
// Expression values
step.ExecutionContext.ExpressionValues["steps"] = step.ExecutionContext.Global.StepsContext.GetScope(step.ExecutionContext.ScopeName);
// Populate env context for each step
Trace.Info("Initialize Env context for step");
#if OS_WINDOWS
var envContext = new DictionaryContextData();
#else
var envContext = new CaseSensitiveDictionaryContextData();
#endif
step.ExecutionContext.ExpressionValues["env"] = envContext;
// Global env
// Merge global env
foreach (var pair in step.ExecutionContext.Global.EnvironmentVariables)
{
envContext[pair.Key] = new StringContextData(pair.Value ?? string.Empty);
}
step.ExecutionContext.ExpressionValues["env"] = envContext;
bool evaluateStepEnvFailed = false;
if (step is IActionRunner actionStep)
{
@@ -108,7 +105,7 @@ namespace GitHub.Runner.Worker
try
{
// Evaluate and merge action's env block to env context
// Evaluate and merge step env
var templateEvaluator = step.ExecutionContext.ToPipelineTemplateEvaluator();
var actionEnvironment = templateEvaluator.EvaluateStepEnvironment(actionStep.Action.Environment, step.ExecutionContext.ExpressionValues, step.ExecutionContext.ExpressionFunctions, VarUtil.EnvironmentVariableKeyComparer);
foreach (var env in actionEnvironment)
@@ -118,7 +115,7 @@ namespace GitHub.Runner.Worker
}
catch (Exception ex)
{
// fail the step since there is an evaluate error.
// Fail the step since there is an evaluate error
Trace.Info("Caught exception from expression for step.env");
evaluateStepEnvFailed = true;
step.ExecutionContext.Error(ex);
@@ -136,7 +133,7 @@ namespace GitHub.Runner.Worker
// Test the condition again. The job was canceled after the condition was originally evaluated.
jobCancelRegister = jobContext.CancellationToken.Register(() =>
{
// mark job as cancelled
// Mark job as cancelled
jobContext.Result = TaskResult.Canceled;
jobContext.JobContext.Status = jobContext.Result?.ToActionResult();
@@ -157,7 +154,7 @@ namespace GitHub.Runner.Worker
}
catch (Exception ex)
{
// Cancel the step since we get exception while re-evaluate step condition.
// Cancel the step since we get exception while re-evaluate step condition
Trace.Info("Caught exception from expression when re-test condition on job cancellation.");
step.ExecutionContext.Error(ex);
}
@@ -165,7 +162,7 @@ namespace GitHub.Runner.Worker
if (!conditionReTestResult)
{
// Cancel the step.
// Cancel the step
Trace.Info("Cancel current running step.");
step.ExecutionContext.CancelToken();
}
@@ -175,13 +172,13 @@ namespace GitHub.Runner.Worker
{
if (jobContext.Result != TaskResult.Canceled)
{
// mark job as cancelled
// Mark job as cancelled
jobContext.Result = TaskResult.Canceled;
jobContext.JobContext.Status = jobContext.Result?.ToActionResult();
}
}
// Evaluate condition.
// Evaluate condition
step.ExecutionContext.Debug($"Evaluating condition for step: '{step.DisplayName}'");
var conditionTraceWriter = new ConditionTraceWriter(Trace, step.ExecutionContext);
var conditionResult = false;
@@ -206,22 +203,21 @@ namespace GitHub.Runner.Worker
}
}
// no evaluate error but condition is false
if (!conditionResult && conditionEvaluateError == null)
{
// Condition == false
// Condition is false
Trace.Info("Skipping step due to condition evaluation.");
CompleteStep(step, TaskResult.Skipped, resultCode: conditionTraceWriter.Trace);
}
else if (conditionEvaluateError != null)
{
// fail the step since there is an evaluate error.
// Condition error
step.ExecutionContext.Error(conditionEvaluateError);
CompleteStep(step, TaskResult.Failed);
}
else
{
// Run the step.
// Run the step
await RunStepAsync(step, jobContext.CancellationToken);
CompleteStep(step);
}
@@ -236,7 +232,7 @@ namespace GitHub.Runner.Worker
}
}
// Update the job result.
// Update the job result
if (step.ExecutionContext.Result == TaskResult.Failed)
{
Trace.Info($"Update job result with current step result '{step.ExecutionContext.Result}'.");
@@ -262,7 +258,7 @@ namespace GitHub.Runner.Worker
step.ExecutionContext.UpdateTimelineRecordDisplayName(actionRunner.DisplayName);
}
// Start the step.
// Start the step
Trace.Info("Starting the step.");
step.ExecutionContext.Debug($"Starting: {step.DisplayName}");
@@ -303,7 +299,7 @@ namespace GitHub.Runner.Worker
}
else
{
// Log the exception and cancel the step.
// Log the exception and cancel the step
Trace.Error($"Caught cancellation exception from step: {ex}");
step.ExecutionContext.Error(ex);
step.ExecutionContext.Result = TaskResult.Canceled;
@@ -311,7 +307,7 @@ namespace GitHub.Runner.Worker
}
catch (Exception ex)
{
// Log the error and fail the step.
// Log the error and fail the step
Trace.Error($"Caught exception from step: {ex}");
step.ExecutionContext.Error(ex);
step.ExecutionContext.Result = TaskResult.Failed;
@@ -323,7 +319,7 @@ namespace GitHub.Runner.Worker
step.ExecutionContext.Result = TaskResultUtil.MergeTaskResults(step.ExecutionContext.Result, step.ExecutionContext.CommandResult.Value);
}
// Fixup the step result if ContinueOnError.
// Fixup the step result if ContinueOnError
if (step.ExecutionContext.Result == TaskResult.Failed)
{
var continueOnError = false;
@@ -348,7 +344,7 @@ namespace GitHub.Runner.Worker
}
Trace.Info($"Step result: {step.ExecutionContext.Result}");
// Complete the step context.
// Complete the step context
step.ExecutionContext.Debug($"Finishing: {step.DisplayName}");
}