Skip to content

Commit e640764

Browse files
authored
Merge pull request #247 from nils-a/release/7.1.0
Release/7.1.0
2 parents ef523d3 + 8a085f4 commit e640764

15 files changed

Lines changed: 152 additions & 20 deletions

File tree

.github/workflows/build.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
runs-on: ${{ matrix.os }}
2020
strategy:
2121
matrix:
22-
os: [windows-latest, macos-latest, ubuntu-latest]
22+
os: [windows-latest, macos-13, ubuntu-latest]
2323

2424
env:
2525
AZURE_PASSWORD: ${{ secrets.AZURE_PASSWORD }}
@@ -44,13 +44,13 @@ jobs:
4444

4545
steps:
4646
- name: Checkout the repository
47-
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
47+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
4848

4949
- name: Fetch all tags and branches
5050
run: git fetch --prune --unshallow
5151

5252
# codecov and unittests need 2.1, gitversion needs 5.0
53-
- uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4.0.0
53+
- uses: actions/setup-dotnet@6bd8b7f7774af54e05809fcc5431931b3eb1ddee # v4.0.1
5454
with:
5555
dotnet-version: |
5656
2.1
@@ -61,7 +61,7 @@ jobs:
6161
8.0
6262
6363
- name: Cache Tools
64-
uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4
64+
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
6565
with:
6666
path: tools
6767
key: ${{ runner.os }}-tools-${{ hashFiles('recipe.cake') }}
@@ -76,7 +76,7 @@ jobs:
7676

7777
# currently, Cake.Recipe does not upload artifacts when run on gh-actions
7878
- name: Upload Issues
79-
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4
79+
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4
8080
with:
8181
if-no-files-found: warn
8282
name: ${{ matrix.os }} Issues
@@ -85,7 +85,7 @@ jobs:
8585
BuildArtifacts/**/coverlet/*.xml
8686
8787
- name: Upload Packages
88-
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4
88+
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4
8989
if: runner.os == 'Windows'
9090
with:
9191
if-no-files-found: warn

.github/workflows/codeql-analysis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ jobs:
2020

2121
steps:
2222
- name: Checkout repository
23-
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
23+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
2424
with:
2525
fetch-depth: 0
2626

27-
- uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4.0.0
27+
- uses: actions/setup-dotnet@6bd8b7f7774af54e05809fcc5431931b3eb1ddee # v4.0.1
2828
with:
2929
dotnet-version: |
3030
2.1
@@ -35,13 +35,13 @@ jobs:
3535
8.0
3636
3737
- name: Cache Tools
38-
uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4
38+
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
3939
with:
4040
path: tools
4141
key: ${{ runner.os }}-tools-${{ hashFiles('recipe.cake') }}
4242

4343
- name: Initialize CodeQL
44-
uses: github/codeql-action/init@379614612a29c9e28f31f39a59013eb8012a51f0 # v3
44+
uses: github/codeql-action/init@e2b3eafc8d227b0241d48be5f425d47c2d750a13 # v3
4545
with:
4646
languages: ${{ matrix.language }}
4747

@@ -53,4 +53,4 @@ jobs:
5353
cake-version: 1.3.0
5454

5555
- name: Perform CodeQL Analysis
56-
uses: github/codeql-action/analyze@379614612a29c9e28f31f39a59013eb8012a51f0 # v3
56+
uses: github/codeql-action/analyze@e2b3eafc8d227b0241d48be5f425d47c2d750a13 # v3

demo/frosting/build/Build.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
66
</PropertyGroup>
77
<ItemGroup>
8-
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
8+
<PackageReference Include="JetBrains.Annotations" Version="2024.2.0" />
99
<PackageReference Include="Cake.Frosting" Version="4.0.0" />
1010
<ProjectReference Include="$(ProjectDir)../../../src/Cake.AzurePipelines.Module/Cake.AzurePipelines.Module.csproj" />
1111
<ProjectReference Include="$(ProjectDir)../../../src/Cake.GitHubActions.Module/Cake.GitHubActions.Module.csproj" />

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": "8.0.201",
3+
"version": "8.0.402",
44
"rollForward": "latestFeature"
55
}
66
}

recipe.cake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ BuildParameters.SetParameters(
1414
shouldUseDeterministicBuilds: true,
1515
gitterMessage: "@/all " + standardNotificationMessage,
1616
twitterMessage: standardNotificationMessage,
17+
shouldRunCodecov: false,
1718
preferredBuildProviderType: BuildProviderType.GitHubActions,
1819
preferredBuildAgentOperatingSystem: PlatformFamily.Linux);
1920

2021
BuildParameters.PrintParameters(Context);
2122

23+
ToolSettings.SetToolPreprocessorDirectives(
24+
gitReleaseManagerGlobalTool: "#tool dotnet:?package=GitReleaseManager.Tool&version=0.18.0");
25+
2226
ToolSettings.SetToolSettings(context: Context);
2327

2428
Build.RunDotNetCore();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<ItemGroup>
1515
<PackageReference Include="Cake.Core" Version="4.0.0" PrivateAssets="All" />
1616
<PackageReference Include="Cake.Common" Version="4.0.0" PrivateAssets="All" />
17-
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" PrivateAssets="All" />
17+
<PackageReference Include="JetBrains.Annotations" Version="2024.2.0" PrivateAssets="All" />
1818
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
1919
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2020
<PrivateAssets>all</PrivateAssets>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<ItemGroup>
1515
<PackageReference Include="Cake.Core" Version="4.0.0" PrivateAssets="All" />
1616
<PackageReference Include="Cake.Common" Version="4.0.0" PrivateAssets="All" />
17-
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" PrivateAssets="All" />
17+
<PackageReference Include="JetBrains.Annotations" Version="2024.2.0" PrivateAssets="All" />
1818
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
1919
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2020
<PrivateAssets>all</PrivateAssets>

src/Cake.GitLabCI.Module/AnsiEscapeCodes.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ internal static class AnsiEscapeCodes
77
public static readonly string ForegroundYellow = string.Format(FORMAT, 33);
88
public static readonly string ForegroundLightGray = string.Format(FORMAT, 37);
99
public static readonly string ForegroundDarkGray = string.Format(FORMAT, 90);
10+
public static readonly string ForegroundBlue = string.Format(FORMAT, 34);
1011
public static readonly string BackgroundMagenta = string.Format(FORMAT, 45);
1112
public static readonly string BackgroundRed = string.Format(FORMAT, 41);
13+
public static readonly string SectionMarker = "\u001B[0K";
1214

1315
private const string FORMAT = "\u001B[{0}m";
1416
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<ItemGroup>
1515
<PackageReference Include="Cake.Core" Version="4.0.0" PrivateAssets="All" />
1616
<PackageReference Include="Cake.Common" Version="4.0.0" PrivateAssets="All" />
17-
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" PrivateAssets="All" />
17+
<PackageReference Include="JetBrains.Annotations" Version="2024.2.0" PrivateAssets="All" />
1818
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
1919
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2020
<PrivateAssets>all</PrivateAssets>
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text.RegularExpressions;
4+
5+
using Cake.Core;
6+
using Cake.Core.Diagnostics;
7+
using Cake.Module.Shared;
8+
9+
using JetBrains.Annotations;
10+
11+
namespace Cake.GitLabCI.Module
12+
{
13+
/// <summary>
14+
/// <see cref="ICakeEngine"/> implementation for GitLab CI.
15+
/// </summary>
16+
/// <remarks>
17+
/// This engine emits additional console output to make GitLab CI render the output of the indiviudal Cake tasks as collapsible sections
18+
/// (see <see href="https://docs.gitlab.com/ee/ci/yaml/script.html#custom-collapsible-sections">Custom collapsible sections (GitLab Docs)</see>).
19+
/// </remarks>
20+
[UsedImplicitly]
21+
public sealed class GitLabCIEngine : CakeEngineBase
22+
{
23+
private readonly IConsole _console;
24+
private readonly object _sectionNameLock = new object();
25+
private readonly Dictionary<string, string> _taskSectionNames = new Dictionary<string, string>();
26+
private readonly HashSet<string> _sectionNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
27+
28+
/// <summary>
29+
/// Initializes a new instance of the <see cref="GitLabCIEngine"/> class.
30+
/// </summary>
31+
/// <param name="dataService">Implementation of <see cref="ICakeDataService"/>.</param>
32+
/// <param name="log">Implementation of <see cref="ICakeLog"/>.</param>
33+
/// <param name="console">Implementation of <see cref="IConsole"/>.</param>
34+
public GitLabCIEngine(ICakeDataService dataService, ICakeLog log, IConsole console)
35+
: base(new CakeEngine(dataService, log))
36+
{
37+
_console = console;
38+
_engine.BeforeSetup += OnBeforeSetup;
39+
_engine.AfterSetup += OnAfterSetup;
40+
_engine.BeforeTaskSetup += OnBeforeTaskSetup;
41+
_engine.AfterTaskTeardown += OnAfterTaskTeardown;
42+
_engine.BeforeTeardown += OnBeforeTeardown;
43+
_engine.AfterTeardown += OnAfterTeardown;
44+
}
45+
46+
private void OnBeforeSetup(object sender, BeforeSetupEventArgs e)
47+
{
48+
WriteSectionStart("setup", "Executing Setup");
49+
}
50+
51+
private void OnAfterSetup(object sender, AfterSetupEventArgs e)
52+
{
53+
WriteSectionEnd("setup");
54+
}
55+
56+
private void OnBeforeTaskSetup(object sender, BeforeTaskSetupEventArgs e)
57+
{
58+
WriteSectionStart(GetSectionNameForTask(e.TaskSetupContext.Task.Name), $"Executing task \"{e.TaskSetupContext.Task.Name}\"");
59+
}
60+
61+
private void OnAfterTaskTeardown(object sender, AfterTaskTeardownEventArgs e)
62+
{
63+
WriteSectionEnd(GetSectionNameForTask(e.TaskTeardownContext.Task.Name));
64+
}
65+
66+
private void OnBeforeTeardown(object sender, BeforeTeardownEventArgs e)
67+
{
68+
WriteSectionStart("teardown", "Executing Teardown");
69+
}
70+
71+
private void OnAfterTeardown(object sender, AfterTeardownEventArgs e)
72+
{
73+
WriteSectionEnd("teardown");
74+
}
75+
76+
private void WriteSectionStart(string sectionName, string sectionHeader)
77+
{
78+
_console.WriteLine("{0}", $"{AnsiEscapeCodes.SectionMarker}section_start:{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}:{sectionName}\r{AnsiEscapeCodes.SectionMarker}{AnsiEscapeCodes.ForegroundBlue}{sectionHeader}{AnsiEscapeCodes.Reset}");
79+
}
80+
81+
private void WriteSectionEnd(string sectionName)
82+
{
83+
_console.WriteLine("{0}", $"{AnsiEscapeCodes.SectionMarker}section_end:{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}:{sectionName}\r{AnsiEscapeCodes.SectionMarker}");
84+
}
85+
86+
/// <summary>
87+
/// Computes a unique GitLab CI section name for a task name.
88+
/// </summary>
89+
/// <remarks>
90+
/// GitLab CI requires a section name in both the "start" and "end" markers of a section.
91+
/// The name can only be composed of letters, numbers, and the _, ., or - characters.
92+
/// In Cake, each task corresponds to one section.
93+
/// Since the task name may contain characters not allowed in the section name, unsupprted characters are removed from the task name.
94+
/// Additionally, this method ensures that the section name is unique and the same task name will be mapped to the same section name for each call.
95+
/// </remarks>
96+
private string GetSectionNameForTask(string taskName)
97+
{
98+
lock (_sectionNameLock)
99+
{
100+
// If there is already a section name for the task, reuse the same name
101+
if (_taskSectionNames.TryGetValue(taskName, out var sectionName))
102+
{
103+
return sectionName;
104+
}
105+
106+
// Remove unsuported characters from the task name (everything except letters, numbers or the _, ., and - characters
107+
var normalizedTaskName = Regex.Replace(taskName, "[^A-Z|a-z|0-9|_|\\-|\\.]*", string.Empty).ToLowerInvariant();
108+
109+
// Normalizing the task name can cause multiple tasks to be mapped to the same section name
110+
// To avoid name conflicts, append a number to the end to make the section name unique.
111+
sectionName = normalizedTaskName;
112+
var sectionCounter = 0;
113+
while (!_sectionNames.Add(sectionName))
114+
{
115+
sectionName = string.Concat(sectionName, "_", sectionCounter++);
116+
}
117+
118+
// Save task name -> section name mapping for subsequent calls of GetSectionNameForTask()
119+
_taskSectionNames.Add(taskName, sectionName);
120+
return sectionName;
121+
}
122+
}
123+
}
124+
}

0 commit comments

Comments
 (0)