Compare commits

...

6 Commits

Author SHA1 Message Date
Rob Herley
e552c0cced separate logic into attachment summary func 2022-01-25 19:03:14 -05:00
Rob Herley
e112193313 use step id as md file name, queue file attachment 2022-01-25 19:00:12 -05:00
Sven Pfleiderer
386fa86f91 Try to simplify cleaning up file references 2022-01-21 16:56:35 -08:00
Sven Pfleiderer
412dc5c836 Fix file contention issue 2022-01-21 14:32:47 -08:00
Sven Pfleiderer
0361ffcbf9 Merge branch 'main' of github.com:actions/runner into pfleidi/step_summary_file 2022-01-21 11:25:53 -08:00
Sven Pfleiderer
25f6cb1d78 First prototype of step summary environment variable 2022-01-20 17:10:52 -08:00
5 changed files with 66 additions and 2 deletions

View File

@@ -9,6 +9,7 @@ namespace GitHub.Runner.Common
Externals,
Root,
Actions,
StepSummary,
Temp,
Tools,
Update,
@@ -196,6 +197,7 @@ namespace GitHub.Runner.Common
public static readonly string DiagDirectory = "_diag";
public static readonly string ExternalsDirectory = "externals";
public static readonly string RunnerDiagnosticLogPrefix = "Runner_";
public static readonly string StepSummaryDirectory = "_step_summary";
public static readonly string TempDirectory = "_temp";
public static readonly string ToolDirectory = "_tool";
public static readonly string UpdateDirectory = "_update";

View File

@@ -243,6 +243,12 @@ namespace GitHub.Runner.Common
path = new DirectoryInfo(GetDirectory(WellKnownDirectory.Bin)).Parent.FullName;
break;
case WellKnownDirectory.StepSummary:
path = Path.Combine(
GetDirectory(WellKnownDirectory.Temp),
Constants.Path.StepSummaryDirectory);
break;
case WellKnownDirectory.Temp:
path = Path.Combine(
GetDirectory(WellKnownDirectory.Work),

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -103,6 +104,10 @@ namespace GitHub.Runner.Worker
// Set GITHUB_ACTION
step.ExecutionContext.SetGitHubContext("action", actionStep.Action.Name);
var stepSummaryFilePath = CreateStepSummaryFile(step);
step.ExecutionContext.SetGitHubContext("step_summary", stepSummaryFilePath);
envContext["GITHUB_STEP_SUMMARY"] = new StringContextData(stepSummaryFilePath);
try
{
// Evaluate and merge step env
@@ -352,7 +357,52 @@ namespace GitHub.Runner.Worker
{
var executionContext = step.ExecutionContext;
CreateSummaryAttachment(step);
executionContext.Complete(result, resultCode: resultCode);
}
private string CreateStepSummaryFile(IStep step)
{
var stepSummaryDirectory = HostContext.GetDirectory(WellKnownDirectory.StepSummary);
if (!Directory.Exists(stepSummaryDirectory))
{
Trace.Info($"Creating step summary directory: {stepSummaryDirectory}");
Directory.CreateDirectory(stepSummaryDirectory);
}
var stepID = step.ExecutionContext.Id;
var stepSummaryFilePath = Path.Combine(stepSummaryDirectory, $"{stepID}.md");
Trace.Info($"Creating step summary file: {stepSummaryFilePath}");
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);
}
}
}
}
}
}

View File

@@ -102,4 +102,10 @@ namespace GitHub.DistributedTask.WebApi
public static readonly String FileAttachment = "DistributedTask.Core.FileAttachment";
public static readonly String DiagnosticLog = "DistributedTask.Core.DiagnosticLog";
}
[GenerateAllConstants]
public class ChecksAttachmentType
{
public static readonly String StepSummary = "Checks.Step.Summary";
}
}

View File

@@ -1 +1 @@
2.286.0
2.286.2