From e552c0cced4b841c91f4796578451d29e537ff14 Mon Sep 17 00:00:00 2001 From: Rob Herley Date: Tue, 25 Jan 2022 19:03:14 -0500 Subject: [PATCH] separate logic into attachment summary func --- src/Runner.Worker/StepsRunner.cs | 48 ++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/Runner.Worker/StepsRunner.cs b/src/Runner.Worker/StepsRunner.cs index f8ae15b90..fc3d41de5 100644 --- a/src/Runner.Worker/StepsRunner.cs +++ b/src/Runner.Worker/StepsRunner.cs @@ -356,28 +356,8 @@ namespace GitHub.Runner.Worker private void CompleteStep(IStep step, TaskResult? result = null, string resultCode = null) { var executionContext = step.ExecutionContext; - var parentContext = executionContext.Root; - var stepSummaryFilePath = executionContext.GetGitHubContext("step_summary"); - Trace.Info($"Reading step summary data from {stepSummaryFilePath}"); - - var summaryExists = File.Exists(stepSummaryFilePath); - if (summaryExists) - { - Trace.Info($"File exists: {stepSummaryFilePath}"); - - var summaryFileIsEmpty = new FileInfo(stepSummaryFilePath).Length == 0; - if (summaryFileIsEmpty) - { - Trace.Info($"Summary file ({summaryFileIsEmpty}) is empty, skipping attachment upload"); - } - else - { - var stepID = executionContext.Id; - Trace.Info($"Queueing file ({stepSummaryFilePath}) for attachment upload ({stepID})"); - parentContext.QueueAttachFile(ChecksAttachmentType.StepSummary, stepID.ToString(), stepSummaryFilePath); - } - } + CreateSummaryAttachment(step); executionContext.Complete(result, resultCode: resultCode); } @@ -398,5 +378,31 @@ namespace GitHub.Runner.Worker File.Create(stepSummaryFilePath).Close(); return stepSummaryFilePath; } + + private void CreateSummaryAttachment(IStep step) { + var executionContext = step.ExecutionContext; + var parentContext = executionContext.Root; + var stepSummaryFilePath = executionContext.GetGitHubContext("step_summary"); + var stepID = executionContext.Id; + + Trace.Info($"Reading step summary data from {stepSummaryFilePath}"); + + var summaryExists = File.Exists(stepSummaryFilePath); + if (summaryExists) + { + Trace.Info($"File exists: {stepSummaryFilePath}"); + + var summaryFileIsEmpty = new FileInfo(stepSummaryFilePath).Length == 0; + if (summaryFileIsEmpty) + { + Trace.Info($"Summary file ({summaryFileIsEmpty}) is empty, skipping attachment upload"); + } + else + { + Trace.Info($"Queueing file ({stepSummaryFilePath}) for attachment upload ({stepID})"); + parentContext.QueueAttachFile(ChecksAttachmentType.StepSummary, stepID.ToString(), stepSummaryFilePath); + } + } + } } } \ No newline at end of file