Skip to content

Commit aeae15d

Browse files
committed
Add safety check to prevent from checking defaults in ScriptHandler for composite action
1 parent 6602117 commit aeae15d

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/Runner.Worker/ExecutionContext.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ public interface IExecutionContext : IRunnerService
6060

6161
bool EchoOnActionCommand { get; set; }
6262

63+
bool IsComposite { get; }
64+
6365
// Initialize
6466
void InitializeJob(Pipelines.AgentJobRequestMessage message, CancellationToken token);
6567
void CancelToken();
66-
IExecutionContext CreateChild(Guid recordId, string displayName, string refName, string scopeName, string contextName, Dictionary<string, string> intraActionState = null, int? recordOrder = null, IPagingLogger logger = null);
68+
IExecutionContext CreateChild(Guid recordId, string displayName, string refName, string scopeName, string contextName, Dictionary<string, string> intraActionState = null, int? recordOrder = null, IPagingLogger logger = null, bool isComposite = false);
6769

6870
// logging
6971
long Write(string tag, string message);
@@ -126,6 +128,7 @@ public sealed class ExecutionContext : RunnerService, IExecutionContext
126128
// only job level ExecutionContext will track throttling delay.
127129
private long _totalThrottlingDelayInMilliseconds = 0;
128130

131+
129132
public Guid Id => _record.Id;
130133
public string ScopeName { get; private set; }
131134
public string ContextName { get; private set; }
@@ -148,6 +151,8 @@ public sealed class ExecutionContext : RunnerService, IExecutionContext
148151
// Only job level ExecutionContext has StepsWithPostRegistered
149152
public HashSet<Guid> StepsWithPostRegistered { get; private set; }
150153

154+
public bool IsComposite { get; private set; }
155+
151156
public bool EchoOnActionCommand { get; set; }
152157

153158
public TaskResult? Result
@@ -254,7 +259,7 @@ public IStep CreateCompositeStep(
254259
DictionaryContextData inputsData,
255260
Dictionary<string, string> envData)
256261
{
257-
step.ExecutionContext = Root.CreateChild(_record.Id, step.DisplayName, _record.Id.ToString("N"), scopeName, step.Action.ContextName, logger: _logger);
262+
step.ExecutionContext = Root.CreateChild(_record.Id, step.DisplayName, _record.Id.ToString("N"), scopeName, step.Action.ContextName, logger: _logger, isComposite: true);
258263
step.ExecutionContext.ExpressionValues["inputs"] = inputsData;
259264
step.ExecutionContext.ExpressionValues["steps"] = Global.StepsContext.GetScope(step.ExecutionContext.GetFullyQualifiedContextName());
260265

@@ -273,7 +278,7 @@ public IStep CreateCompositeStep(
273278
return step;
274279
}
275280

276-
public IExecutionContext CreateChild(Guid recordId, string displayName, string refName, string scopeName, string contextName, Dictionary<string, string> intraActionState = null, int? recordOrder = null, IPagingLogger logger = null)
281+
public IExecutionContext CreateChild(Guid recordId, string displayName, string refName, string scopeName, string contextName, Dictionary<string, string> intraActionState = null, int? recordOrder = null, IPagingLogger logger = null, bool isComposite = false)
277282
{
278283
Trace.Entering();
279284

@@ -320,6 +325,8 @@ public IExecutionContext CreateChild(Guid recordId, string displayName, string r
320325
child._logger.Setup(_mainTimelineId, recordId);
321326
}
322327

328+
child.IsComposite = isComposite;
329+
323330
return child;
324331
}
325332

src/Runner.Worker/Handlers/ScriptHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public async Task RunAsync(ActionRunStage stage)
153153
{
154154
// TODO: figure out how defaults interact with template later
155155
// for now, we won't check job.defaults if we are inside a template.
156-
if (string.IsNullOrEmpty(ExecutionContext.ScopeName) && ExecutionContext.Global.JobDefaults.TryGetValue("run", out var runDefaults))
156+
if (!ExecutionContext.IsComposite && string.IsNullOrEmpty(ExecutionContext.ScopeName) && ExecutionContext.Global.JobDefaults.TryGetValue("run", out var runDefaults))
157157
{
158158
if (runDefaults.TryGetValue("working-directory", out workingDirectory))
159159
{
@@ -169,7 +169,7 @@ public async Task RunAsync(ActionRunStage stage)
169169
{
170170
// TODO: figure out how defaults interact with template later
171171
// for now, we won't check job.defaults if we are inside a template.
172-
if (string.IsNullOrEmpty(ExecutionContext.ScopeName) && ExecutionContext.Global.JobDefaults.TryGetValue("run", out var runDefaults))
172+
if (!ExecutionContext.IsComposite && string.IsNullOrEmpty(ExecutionContext.ScopeName) && ExecutionContext.Global.JobDefaults.TryGetValue("run", out var runDefaults))
173173
{
174174
if (runDefaults.TryGetValue("shell", out shell))
175175
{

0 commit comments

Comments
 (0)