Skip to content

Commit 2f7965d

Browse files
authored
Merge pull request #307 from gep13/github-report-printer
(#302 #306) Update to Cake 6.0.0 and add GitHub Report Printer
2 parents a4550cd + 513f944 commit 2f7965d

File tree

14 files changed

+179
-24
lines changed

14 files changed

+179
-24
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ jobs:
6161
6.0
6262
7.0
6363
9.0
64+
10.0
6465
6566
- name: Cache Tools
6667
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "9.0.306",
3+
"version": "10.0.100",
44
"rollForward": "latestFeature"
55
}
66
}

src/Cake.AzurePipelines.Module/AzurePipelinesReportPrinter.cs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
using System;
1+
using System;
22
using System.IO;
3+
using System.Linq;
34
using System.Text;
45
using Cake.Common.Build;
56
using Cake.Core;
7+
using Cake.Core.Diagnostics;
68
using Cake.Core.IO;
79
using Cake.Module.Shared;
810
using JetBrains.Annotations;
@@ -53,6 +55,8 @@ public override void Write(CakeReport report)
5355

5456
private void WriteToMarkdown(CakeReport report)
5557
{
58+
var includeSkippedReasonColumn = report.Any(r => !string.IsNullOrEmpty(r.SkippedMessage));
59+
5660
var maxTaskNameLength = 29;
5761
foreach (var item in report)
5862
{
@@ -67,13 +71,30 @@ private void WriteToMarkdown(CakeReport report)
6771

6872
var sb = new StringBuilder();
6973
sb.AppendLine("");
70-
sb.AppendLine("|Task|Duration|");
71-
sb.AppendLine("|:---|-------:|");
74+
75+
if (includeSkippedReasonColumn)
76+
{
77+
sb.AppendLine("|Task|Duration|Status|Skip Reason|");
78+
sb.AppendLine("|:---|-------:|:-----|:----------|");
79+
}
80+
else
81+
{
82+
sb.AppendLine("|Task|Duration|Status|");
83+
sb.AppendLine("|:---|-------:|:-----|");
84+
}
85+
7286
foreach (var item in report)
7387
{
7488
if (ShouldWriteTask(item))
7589
{
76-
sb.AppendLine(string.Format(lineFormat, item.TaskName, FormatDuration(item)));
90+
if (includeSkippedReasonColumn)
91+
{
92+
sb.AppendLine(string.Format(lineFormat, item.TaskName, FormatDuration(item), item.ExecutionStatus.ToReportStatus(), item.SkippedMessage));
93+
}
94+
else
95+
{
96+
sb.AppendLine(string.Format(lineFormat, item.TaskName, FormatDuration(item), item.ExecutionStatus.ToReportStatus()));
97+
}
7798
}
7899
}
79100

src/Cake.AzurePipelines.Module/Cake.AzurePipelines.Module.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
</ItemGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Cake.Core" Version="5.0.0" PrivateAssets="All" />
16-
<PackageReference Include="Cake.Common" Version="5.0.0" PrivateAssets="All" />
15+
<PackageReference Include="Cake.Core" Version="6.0.0" PrivateAssets="All" />
16+
<PackageReference Include="Cake.Common" Version="6.0.0" PrivateAssets="All" />
1717
<PackageReference Include="JetBrains.Annotations" Version="2025.2.2" PrivateAssets="All" />
1818
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
1919
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

src/Cake.BuildSystems.Module/Cake.BuildSystems.Module.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
</ItemGroup>
5959

6060
<ItemGroup>
61-
<PackageReference Include="CakeContrib.Guidelines" Version="1.6.1">
61+
<PackageReference Include="CakeContrib.Guidelines" Version="1.7.0">
6262
<PrivateAssets>all</PrivateAssets>
6363
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
6464
</PackageReference>

src/Cake.GitHubActions.Module/Cake.GitHubActions.Module.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
</ItemGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Cake.Core" Version="5.0.0" PrivateAssets="All" />
16-
<PackageReference Include="Cake.Common" Version="5.0.0" PrivateAssets="All" />
15+
<PackageReference Include="Cake.Core" Version="6.0.0" PrivateAssets="All" />
16+
<PackageReference Include="Cake.Common" Version="6.0.0" PrivateAssets="All" />
1717
<PackageReference Include="JetBrains.Annotations" Version="2025.2.2" PrivateAssets="All" />
1818
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
1919
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

src/Cake.GitHubActions.Module/GitHubActionsModule.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Cake.Core;
1+
using Cake.Core;
22
using Cake.Core.Annotations;
33
using Cake.Core.Composition;
44
using Cake.Core.Diagnostics;
@@ -22,6 +22,7 @@ public void Register(ICakeContainerRegistrar registrar)
2222

2323
registrar.RegisterType<GitHubActionsEngine>().As<ICakeEngine>().Singleton();
2424
registrar.RegisterType<GitHubActionsLog>().As<ICakeLog>().Singleton();
25+
registrar.RegisterType<GitHubActionsReportPrinter>().As<ICakeReportPrinter>().Singleton();
2526
}
2627
}
2728
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
using System;
2+
using System.Linq;
3+
using System.Text;
4+
using Cake.Common.Build;
5+
using Cake.Core;
6+
using Cake.Core.Diagnostics;
7+
using Cake.Module.Shared;
8+
using JetBrains.Annotations;
9+
10+
namespace Cake.GitHubActions.Module
11+
{
12+
/// <summary>
13+
/// The GitHub Actions report printer.
14+
/// </summary>
15+
[UsedImplicitly]
16+
public class GitHubActionsReportPrinter : CakeReportPrinterBase
17+
{
18+
/// <summary>
19+
/// Initializes a new instance of the <see cref="GitHubActionsReportPrinter"/> class.
20+
/// </summary>
21+
/// <param name="console">The console.</param>
22+
/// <param name="context">The context.</param>
23+
public GitHubActionsReportPrinter(IConsole console, ICakeContext context)
24+
: base(console, context)
25+
{
26+
}
27+
28+
/// <inheritdoc />
29+
public override void Write(CakeReport report)
30+
{
31+
if (report == null)
32+
{
33+
throw new ArgumentNullException(nameof(report));
34+
}
35+
36+
try
37+
{
38+
if (_context.GitHubActions().IsRunningOnGitHubActions)
39+
{
40+
WriteToMarkdown(report);
41+
}
42+
43+
WriteToConsole(report);
44+
}
45+
finally
46+
{
47+
_console.ResetColor();
48+
}
49+
}
50+
51+
/// <inheritdoc />
52+
public override void WriteLifeCycleStep(string name, Verbosity verbosity)
53+
{
54+
// Intentionally left blank
55+
}
56+
57+
/// <inheritdoc />
58+
public override void WriteSkippedStep(string name, Verbosity verbosity)
59+
{
60+
// Intentionally left blank
61+
}
62+
63+
/// <inheritdoc />
64+
public override void WriteStep(string name, Verbosity verbosity)
65+
{
66+
// Intentionally left blank
67+
}
68+
69+
private void WriteToMarkdown(CakeReport report)
70+
{
71+
var includeSkippedReasonColumn = report.Any(r => !string.IsNullOrEmpty(r.SkippedMessage));
72+
73+
var sb = new StringBuilder();
74+
sb.AppendLine(string.Empty);
75+
76+
if (includeSkippedReasonColumn)
77+
{
78+
sb.AppendLine("|Task|Duration|Status|Skip Reason|");
79+
sb.AppendLine("|----|--------|------|-----------|");
80+
}
81+
else
82+
{
83+
sb.AppendLine("|Task|Duration|Status|");
84+
sb.AppendLine("|----|--------|------|");
85+
}
86+
87+
foreach (var item in report)
88+
{
89+
if (ShouldWriteTask(item))
90+
{
91+
if (includeSkippedReasonColumn)
92+
{
93+
sb.AppendLine(string.Format("|{0}|{1}|{2}|{3}|", item.TaskName, FormatDuration(item), item.ExecutionStatus.ToReportStatus(), item.SkippedMessage));
94+
}
95+
else
96+
{
97+
sb.AppendLine(string.Format("|{0}|{1}|{2}|", item.TaskName, FormatDuration(item), item.ExecutionStatus.ToReportStatus()));
98+
}
99+
}
100+
}
101+
102+
if (includeSkippedReasonColumn)
103+
{
104+
sb.AppendLine("|||||");
105+
sb.AppendLine(string.Format("|**_{0}_**|**_{1}_**|||", "Total:", GetTotalTime(report)));
106+
}
107+
else
108+
{
109+
sb.AppendLine("||||");
110+
sb.AppendLine(string.Format("|**_{0}_**|**_{1}_**||", "Total:", GetTotalTime(report)));
111+
}
112+
113+
_context.GitHubActions().Commands.SetStepSummary(sb.ToString());
114+
}
115+
}
116+
}

src/Cake.GitLabCI.Module/Cake.GitLabCI.Module.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
</ItemGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Cake.Core" Version="5.0.0" PrivateAssets="All" />
16-
<PackageReference Include="Cake.Common" Version="5.0.0" PrivateAssets="All" />
15+
<PackageReference Include="Cake.Core" Version="6.0.0" PrivateAssets="All" />
16+
<PackageReference Include="Cake.Common" Version="6.0.0" PrivateAssets="All" />
1717
<PackageReference Include="JetBrains.Annotations" Version="2025.2.2" PrivateAssets="All" />
1818
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
1919
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

src/Cake.Module.Shared/Cake.Module.Shared.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Cake.Core" Version="5.0.0" PrivateAssets="All" />
12-
<PackageReference Include="Cake.Common" Version="5.0.0" PrivateAssets="All" />
11+
<PackageReference Include="Cake.Core" Version="6.0.0" PrivateAssets="All" />
12+
<PackageReference Include="Cake.Common" Version="6.0.0" PrivateAssets="All" />
1313
<PackageReference Include="JetBrains.Annotations" Version="2025.2.2" PrivateAssets="All" />
1414
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

0 commit comments

Comments
 (0)