Skip to content

Commit

Permalink
1MB GitHub Summary
Browse files Browse the repository at this point in the history
  • Loading branch information
thomhurst committed Jan 10, 2025
1 parent b9d24f3 commit 5737b3a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions TUnit.Engine/Reporters/GitHubReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace TUnit.Engine.Reporters;

public class GitHubReporter(IExtension extension) : IDataConsumer, ITestApplicationLifecycleCallbacks
{
private const long MaxFileSizeInBytes = 1 * 1024 * 1024; // 1MB
private string _outputSummaryFilePath = null!;

public async Task<bool> IsEnabledAsync()
Expand Down Expand Up @@ -138,6 +139,17 @@ public Task AfterRunAsync(int exitCode, CancellationToken cancellation)

private Task WriteFile(string contents)
{
var fileInfo = new FileInfo(_outputSummaryFilePath);
var currentFileSize = fileInfo.Exists ? fileInfo.Length : 0;
long newContentSize = Encoding.UTF8.GetByteCount(contents);
var newSize = currentFileSize + newContentSize;

if (newSize > MaxFileSizeInBytes)
{
Console.WriteLine("Appending to the GitHub Step Summary would exceed the 1MB file size limit.");
return Task.CompletedTask;
}

#if NET
return File.AppendAllTextAsync(_outputSummaryFilePath, contents, Encoding.UTF8);
#else
Expand Down

0 comments on commit 5737b3a

Please sign in to comment.