Skip to content

Commit

Permalink
Clean Up Composite UI (actions#610)
Browse files Browse the repository at this point in the history
* Remove redundant code (display name is already evaluated in ActionRunner beforehand for each step)

* remove

* Remove nesting information for composite steps.

* put messages in debug logs if composite. if not, put these messages as outputs

* Fix group issue

* Fix end group issue
  • Loading branch information
ethanchewy authored Jul 23, 2020
1 parent 4e82243 commit 2057cad
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
12 changes: 9 additions & 3 deletions src/Runner.Worker/ExecutionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ public interface IExecutionContext : IRunnerService

bool EchoOnActionCommand { get; set; }

bool InsideComposite { get; }

ExecutionContext Root { get; }

// Initialize
void InitializeJob(Pipelines.AgentJobRequestMessage message, CancellationToken token);
void CancelToken();
IExecutionContext CreateChild(Guid recordId, string displayName, string refName, string scopeName, string contextName, Dictionary<string, string> intraActionState = null, int? recordOrder = null, IPagingLogger logger = null, CancellationTokenSource cancellationTokenSource = null);
IExecutionContext CreateChild(Guid recordId, string displayName, string refName, string scopeName, string contextName, Dictionary<string, string> intraActionState = null, int? recordOrder = null, IPagingLogger logger = null, bool insideComposite = false, CancellationTokenSource cancellationTokenSource = null);

// logging
long Write(string tag, string message);
Expand Down Expand Up @@ -152,6 +154,8 @@ public sealed class ExecutionContext : RunnerService, IExecutionContext

public bool EchoOnActionCommand { get; set; }

public bool InsideComposite { get; private set; }

public TaskResult? Result
{
get
Expand Down Expand Up @@ -256,7 +260,7 @@ public IStep CreateCompositeStep(
DictionaryContextData inputsData,
Dictionary<string, string> envData)
{
step.ExecutionContext = Root.CreateChild(_record.Id, step.DisplayName, _record.Id.ToString("N"), scopeName, step.Action.ContextName, logger: _logger, cancellationTokenSource: CancellationTokenSource.CreateLinkedTokenSource(_cancellationTokenSource.Token));
step.ExecutionContext = Root.CreateChild(_record.Id, step.DisplayName, _record.Id.ToString("N"), scopeName, step.Action.ContextName, logger: _logger, insideComposite: true, cancellationTokenSource: CancellationTokenSource.CreateLinkedTokenSource(_cancellationTokenSource.Token));
step.ExecutionContext.ExpressionValues["inputs"] = inputsData;
step.ExecutionContext.ExpressionValues["steps"] = Global.StepsContext.GetScope(step.ExecutionContext.GetFullyQualifiedContextName());

Expand All @@ -275,7 +279,7 @@ public IStep CreateCompositeStep(
return step;
}

public IExecutionContext CreateChild(Guid recordId, string displayName, string refName, string scopeName, string contextName, Dictionary<string, string> intraActionState = null, int? recordOrder = null, IPagingLogger logger = null, CancellationTokenSource cancellationTokenSource = null)
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 insideComposite = false, CancellationTokenSource cancellationTokenSource = null)
{
Trace.Entering();

Expand Down Expand Up @@ -322,6 +326,8 @@ public IExecutionContext CreateChild(Guid recordId, string displayName, string r
child._logger.Setup(_mainTimelineId, recordId);
}

child.InsideComposite = insideComposite;

return child;
}

Expand Down
6 changes: 0 additions & 6 deletions src/Runner.Worker/Handlers/CompositeActionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,6 @@ private async Task RunStepsAsync(List<IStep> compositeSteps)

private async Task RunStepAsync(IStep step)
{
// Try to evaluate the display name
if (step is IActionRunner actionRunner && actionRunner.Stage == ActionRunStage.Main)
{
actionRunner.TryEvaluateDisplayName(step.ExecutionContext.ExpressionValues, step.ExecutionContext);
}

// Start the step.
Trace.Info("Starting the step.");
step.ExecutionContext.Debug($"Starting: {step.DisplayName}");
Expand Down
27 changes: 20 additions & 7 deletions src/Runner.Worker/Handlers/ScriptHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ public sealed class ScriptHandler : Handler, IScriptHandler

public override void PrintActionDetails(ActionRunStage stage)
{
// We don't want to display the internal workings if composite (similar/equivalent information can be found in debug)
void writeDetails(string message)
{
if (ExecutionContext.InsideComposite)
{
ExecutionContext.Debug(message);
}
else
{
ExecutionContext.Output(message);
}
}

if (stage == ActionRunStage.Post)
{
throw new NotSupportedException("Script action should not have 'Post' job action.");
Expand All @@ -39,7 +52,7 @@ public override void PrintActionDetails(ActionRunStage stage)
firstLine = firstLine.Substring(0, firstNewLine);
}

ExecutionContext.Output($"##[group]Run {firstLine}");
writeDetails(ExecutionContext.InsideComposite ? $"Run {firstLine}" : $"##[group]Run {firstLine}");
}
else
{
Expand All @@ -50,7 +63,7 @@ public override void PrintActionDetails(ActionRunStage stage)
foreach (var line in multiLines)
{
// Bright Cyan color
ExecutionContext.Output($"\x1b[36;1m{line}\x1b[0m");
writeDetails($"\x1b[36;1m{line}\x1b[0m");
}

string argFormat;
Expand Down Expand Up @@ -109,23 +122,23 @@ public override void PrintActionDetails(ActionRunStage stage)

if (!string.IsNullOrEmpty(shellCommandPath))
{
ExecutionContext.Output($"shell: {shellCommandPath} {argFormat}");
writeDetails($"shell: {shellCommandPath} {argFormat}");
}
else
{
ExecutionContext.Output($"shell: {shellCommand} {argFormat}");
writeDetails($"shell: {shellCommand} {argFormat}");
}

if (this.Environment?.Count > 0)
{
ExecutionContext.Output("env:");
writeDetails("env:");
foreach (var env in this.Environment)
{
ExecutionContext.Output($" {env.Key}: {env.Value}");
writeDetails($" {env.Key}: {env.Value}");
}
}

ExecutionContext.Output("##[endgroup]");
writeDetails(ExecutionContext.InsideComposite ? "" : "##[endgroup]");
}

public async Task RunAsync(ActionRunStage stage)
Expand Down

0 comments on commit 2057cad

Please sign in to comment.