mirror of
https://github.com/actions/runner.git
synced 2025-12-12 15:13:30 +00:00
use step id as md file name, queue file attachment
This commit is contained in:
@@ -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";
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -104,7 +104,7 @@ namespace GitHub.Runner.Worker
|
||||
// Set GITHUB_ACTION
|
||||
step.ExecutionContext.SetGitHubContext("action", actionStep.Action.Name);
|
||||
|
||||
var stepSummaryFilePath = GetStepSummaryPath(step);
|
||||
var stepSummaryFilePath = CreateStepSummaryFile(step);
|
||||
step.ExecutionContext.SetGitHubContext("step_summary", stepSummaryFilePath);
|
||||
envContext["GITHUB_STEP_SUMMARY"] = new StringContextData(stepSummaryFilePath);
|
||||
|
||||
@@ -356,30 +356,46 @@ 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}");
|
||||
Trace.Info($"File exists: {stepSummaryFilePath} {File.Exists(stepSummaryFilePath)}");
|
||||
|
||||
using (var fileStream = new FileStream(stepSummaryFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
using (var sr = new StreamReader(fileStream))
|
||||
var summaryExists = File.Exists(stepSummaryFilePath);
|
||||
if (summaryExists)
|
||||
{
|
||||
Trace.Info($"Step summary data: {sr.ReadToEnd()}");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
executionContext.Complete(result, resultCode: resultCode);
|
||||
}
|
||||
|
||||
private string GetStepSummaryPath(IStep step)
|
||||
private string CreateStepSummaryFile(IStep step)
|
||||
{
|
||||
var stepSummaryDirectory = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Temp), "_step_summary");
|
||||
var stepSummaryDirectory = HostContext.GetDirectory(WellKnownDirectory.StepSummary);
|
||||
if (!Directory.Exists(stepSummaryDirectory))
|
||||
{
|
||||
Trace.Info($"Creating step summary directory: {stepSummaryDirectory}");
|
||||
Directory.CreateDirectory(stepSummaryDirectory);
|
||||
var stepSummaryFilePath = Path.Combine(stepSummaryDirectory, $"{Guid.NewGuid().ToString()}.md");
|
||||
|
||||
using (File.Create(stepSummaryFilePath)) {
|
||||
Trace.Info($"Using step summary file '{stepSummaryFilePath}'");
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user