From 2e50dffb37286b0ddbe3c80fd94518af2e896c77 Mon Sep 17 00:00:00 2001 From: Ethan Chiu <17chiue@gmail.com> Date: Thu, 23 Jul 2020 09:45:00 -0400 Subject: [PATCH] Clean Up Composite UI (#610) * 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 --- src/Runner.Worker/ExecutionContext.cs | 12 ++++++--- .../Handlers/CompositeActionHandler.cs | 6 ----- src/Runner.Worker/Handlers/ScriptHandler.cs | 27 ++++++++++++++----- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/Runner.Worker/ExecutionContext.cs b/src/Runner.Worker/ExecutionContext.cs index 5385490d7..1aad95c9c 100644 --- a/src/Runner.Worker/ExecutionContext.cs +++ b/src/Runner.Worker/ExecutionContext.cs @@ -60,12 +60,14 @@ namespace GitHub.Runner.Worker 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 intraActionState = null, int? recordOrder = null, IPagingLogger logger = null, CancellationTokenSource cancellationTokenSource = null); + IExecutionContext CreateChild(Guid recordId, string displayName, string refName, string scopeName, string contextName, Dictionary intraActionState = null, int? recordOrder = null, IPagingLogger logger = null, bool insideComposite = false, CancellationTokenSource cancellationTokenSource = null); // logging long Write(string tag, string message); @@ -152,6 +154,8 @@ namespace GitHub.Runner.Worker public bool EchoOnActionCommand { get; set; } + public bool InsideComposite { get; private set; } + public TaskResult? Result { get @@ -256,7 +260,7 @@ namespace GitHub.Runner.Worker DictionaryContextData inputsData, Dictionary 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()); @@ -275,7 +279,7 @@ namespace GitHub.Runner.Worker return step; } - public IExecutionContext CreateChild(Guid recordId, string displayName, string refName, string scopeName, string contextName, Dictionary 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 intraActionState = null, int? recordOrder = null, IPagingLogger logger = null, bool insideComposite = false, CancellationTokenSource cancellationTokenSource = null) { Trace.Entering(); @@ -322,6 +326,8 @@ namespace GitHub.Runner.Worker child._logger.Setup(_mainTimelineId, recordId); } + child.InsideComposite = insideComposite; + return child; } diff --git a/src/Runner.Worker/Handlers/CompositeActionHandler.cs b/src/Runner.Worker/Handlers/CompositeActionHandler.cs index 3ab7957cf..50015a574 100644 --- a/src/Runner.Worker/Handlers/CompositeActionHandler.cs +++ b/src/Runner.Worker/Handlers/CompositeActionHandler.cs @@ -215,12 +215,6 @@ namespace GitHub.Runner.Worker.Handlers 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}"); diff --git a/src/Runner.Worker/Handlers/ScriptHandler.cs b/src/Runner.Worker/Handlers/ScriptHandler.cs index f7d90dc45..397d9a176 100644 --- a/src/Runner.Worker/Handlers/ScriptHandler.cs +++ b/src/Runner.Worker/Handlers/ScriptHandler.cs @@ -23,6 +23,19 @@ namespace GitHub.Runner.Worker.Handlers 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."); @@ -39,7 +52,7 @@ namespace GitHub.Runner.Worker.Handlers firstLine = firstLine.Substring(0, firstNewLine); } - ExecutionContext.Output($"##[group]Run {firstLine}"); + writeDetails(ExecutionContext.InsideComposite ? $"Run {firstLine}" : $"##[group]Run {firstLine}"); } else { @@ -50,7 +63,7 @@ namespace GitHub.Runner.Worker.Handlers 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; @@ -109,23 +122,23 @@ namespace GitHub.Runner.Worker.Handlers 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)