Skip to content

Commit

Permalink
Generate a nice build summary for ci
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenHodgson committed Jan 29, 2023
1 parent 6e789cf commit 9436dc5
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 21 deletions.
4 changes: 4 additions & 0 deletions Editor/Logging/AbstractCILogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System;
using System.Linq;
using UnityEditor.Build.Reporting;
using UnityEngine;
using Object = UnityEngine.Object;

Expand Down Expand Up @@ -88,5 +89,8 @@ public void LogException(Exception exception, Object context)

/// <inheritdoc />
public virtual string ResetColor => "\u001b[0m";

/// <inheritdoc />
public virtual void GenerateBuildSummary(BuildReport buildReport) { }
}
}
3 changes: 3 additions & 0 deletions Editor/Logging/CILoggingUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.Build.Reporting;
using UnityEngine;

namespace Utilities.Editor.BuildPipeline.Logging
Expand Down Expand Up @@ -62,5 +63,7 @@ static CILoggingUtility()
Logger = new GitHubActionsLogger();
}
}

public static void GenerateBuildReport(BuildReport buildReport) => Logger?.GenerateBuildSummary(buildReport);
}
}
51 changes: 51 additions & 0 deletions Editor/Logging/GitHubActionsLogger.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using UnityEditor.Build.Reporting;
using UnityEngine;

namespace Utilities.Editor.BuildPipeline.Logging
{
/// <summary>
Expand All @@ -13,5 +17,52 @@ public class GitHubActionsLogger : AbstractCILogger

/// <inheritdoc />
public override string Error => "::error::";

/// <inheritdoc />
public override void GenerateBuildSummary(BuildReport buildReport)
{
var buildResultMessage = $"Build success? {buildReport.summary.result}\nBuild time: {buildReport.summary.totalTime:g}";

switch (buildReport.summary.result)
{
case BuildResult.Succeeded:
Debug.Log($"::notice::{buildResultMessage}");
break;
case BuildResult.Unknown:
case BuildResult.Cancelled:
Debug.Log($"{Warning}{buildResultMessage}");
break;
case BuildResult.Failed:
Debug.Log($"{Error}{buildResultMessage}");
break;
default:
throw new ArgumentOutOfRangeException();
}

foreach (var step in buildReport.steps)
{
Debug.Log($"::notice::Build Step: {step.name} | Duration: {step.duration:g}");

foreach (var message in step.messages)
{
switch (message.type)
{
case LogType.Error:
case LogType.Assert:
case LogType.Exception:
Debug.Log($"{Error} {message.content}");
break;
case LogType.Warning:
Debug.Log($"{Warning} {message.content}");
break;
case LogType.Log:
Debug.Log($"{message.content}");
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
}
}
}
7 changes: 7 additions & 0 deletions Editor/Logging/ICILogger.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using UnityEditor.Build.Reporting;
using UnityEngine;

namespace Utilities.Editor.BuildPipeline.Logging
Expand Down Expand Up @@ -43,5 +44,11 @@ public interface ICILogger : ILogHandler
/// ANSI Reset color code.
/// </summary>
string ResetColor { get; }

/// <summary>
/// Generate a nicely formatted build summary for the CI Logger.
/// </summary>
/// <param name="buildReport"><see cref="BuildReport"/>.</param>
void GenerateBuildSummary(BuildReport buildReport);
}
}
22 changes: 2 additions & 20 deletions Editor/UnityPlayerBuildTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,26 +352,8 @@ public static void StartCommandLineBuild()
return;
}

var buildResultMessage = $"Exiting command line build...\nBuild success? {buildReport.summary.result}\nBuild time: {buildReport.summary.totalTime:g}";
var buildEventLogs = string.Join("\n", buildReport.steps.SelectMany(step => step.messages.Select(message => $"[{message.type}] {message.content}")));

switch (buildReport.summary.result)
{
case BuildResult.Succeeded:
Debug.Log(buildResultMessage);
break;
case BuildResult.Unknown:
case BuildResult.Cancelled:
Debug.LogWarning($"{buildResultMessage}\nBuild Event Logs:\n{buildEventLogs}");
break;
case BuildResult.Failed:
Debug.LogWarning($"{buildResultMessage}\nBuild Event Logs:\n{buildEventLogs}");
break;

default:
throw new ArgumentOutOfRangeException();
}

CILoggingUtility.GenerateBuildReport(buildReport);
Debug.Log("Exiting command line build...");
EditorApplication.Exit(buildReport.summary.result == BuildResult.Succeeded ? 0 : 1);
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Build Pipeline Utilities",
"description": "The Build Pipeline Utilities aims to give developers more tools and options when making builds with the command line or with continuous integration.",
"keywords": [],
"version": "1.0.9",
"version": "1.1.0",
"unity": "2019.4",
"license": "MIT",
"repository": {
Expand Down

0 comments on commit 9436dc5

Please sign in to comment.