Skip to content

Commit a0a590f

Browse files
authored
setup/evaluate env context after setup steps context. (#309)
1 parent 87a232c commit a0a590f

File tree

2 files changed

+111
-64
lines changed

2 files changed

+111
-64
lines changed

src/Runner.Worker/StepsRunner.cs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -76,38 +76,38 @@ public async Task RunAsync(IExecutionContext jobContext)
7676
// Start
7777
step.ExecutionContext.Start();
7878

79-
// Populate env context for each step
80-
Trace.Info("Initialize Env context for step");
79+
// Initialize scope
80+
if (InitializeScope(step, scopeInputs))
81+
{
82+
// Populate env context for each step
83+
Trace.Info("Initialize Env context for step");
8184
#if OS_WINDOWS
82-
var envContext = new DictionaryContextData();
85+
var envContext = new DictionaryContextData();
8386
#else
84-
var envContext = new CaseSensitiveDictionaryContextData();
87+
var envContext = new CaseSensitiveDictionaryContextData();
8588
#endif
86-
step.ExecutionContext.ExpressionValues["env"] = envContext;
87-
foreach (var pair in step.ExecutionContext.EnvironmentVariables)
88-
{
89-
envContext[pair.Key] = new StringContextData(pair.Value ?? string.Empty);
90-
}
89+
step.ExecutionContext.ExpressionValues["env"] = envContext;
90+
foreach (var pair in step.ExecutionContext.EnvironmentVariables)
91+
{
92+
envContext[pair.Key] = new StringContextData(pair.Value ?? string.Empty);
93+
}
9194

92-
if (step is IActionRunner actionStep)
93-
{
94-
// Set GITHUB_ACTION
95-
step.ExecutionContext.SetGitHubContext("action", actionStep.Action.Name);
96-
97-
// Evaluate and merge action's env block to env context
98-
var templateTrace = step.ExecutionContext.ToTemplateTraceWriter();
99-
var schema = new PipelineTemplateSchemaFactory().CreateSchema();
100-
var templateEvaluator = new PipelineTemplateEvaluator(templateTrace, schema);
101-
var actionEnvironment = templateEvaluator.EvaluateStepEnvironment(actionStep.Action.Environment, step.ExecutionContext.ExpressionValues, VarUtil.EnvironmentVariableKeyComparer);
102-
foreach (var env in actionEnvironment)
95+
if (step is IActionRunner actionStep)
10396
{
104-
envContext[env.Key] = new StringContextData(env.Value ?? string.Empty);
97+
// Set GITHUB_ACTION
98+
step.ExecutionContext.SetGitHubContext("action", actionStep.Action.Name);
99+
100+
// Evaluate and merge action's env block to env context
101+
var templateTrace = step.ExecutionContext.ToTemplateTraceWriter();
102+
var schema = new PipelineTemplateSchemaFactory().CreateSchema();
103+
var templateEvaluator = new PipelineTemplateEvaluator(templateTrace, schema);
104+
var actionEnvironment = templateEvaluator.EvaluateStepEnvironment(actionStep.Action.Environment, step.ExecutionContext.ExpressionValues, VarUtil.EnvironmentVariableKeyComparer);
105+
foreach (var env in actionEnvironment)
106+
{
107+
envContext[env.Key] = new StringContextData(env.Value ?? string.Empty);
108+
}
105109
}
106-
}
107110

108-
// Initialize scope
109-
if (InitializeScope(step, scopeInputs))
110-
{
111111
var expressionManager = HostContext.GetService<IExpressionManager>();
112112
try
113113
{

0 commit comments

Comments
 (0)