Skip to content

Commit

Permalink
Merge pull request #247 from nils-a/release/7.1.0
Browse files Browse the repository at this point in the history
Release/7.1.0
  • Loading branch information
nils-a authored Sep 30, 2024
2 parents ef523d3 + 8a085f4 commit e640764
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 20 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
os: [windows-latest, macos-13, ubuntu-latest]

env:
AZURE_PASSWORD: ${{ secrets.AZURE_PASSWORD }}
Expand All @@ -44,13 +44,13 @@ jobs:

steps:
- name: Checkout the repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4

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

# codecov and unittests need 2.1, gitversion needs 5.0
- uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4.0.0
- uses: actions/setup-dotnet@6bd8b7f7774af54e05809fcc5431931b3eb1ddee # v4.0.1
with:
dotnet-version: |
2.1
Expand All @@ -61,7 +61,7 @@ jobs:
8.0
- name: Cache Tools
uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
with:
path: tools
key: ${{ runner.os }}-tools-${{ hashFiles('recipe.cake') }}
Expand All @@ -76,7 +76,7 @@ jobs:

# currently, Cake.Recipe does not upload artifacts when run on gh-actions
- name: Upload Issues
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4
with:
if-no-files-found: warn
name: ${{ matrix.os }} Issues
Expand All @@ -85,7 +85,7 @@ jobs:
BuildArtifacts/**/coverlet/*.xml
- name: Upload Packages
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4
if: runner.os == 'Windows'
with:
if-no-files-found: warn
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
with:
fetch-depth: 0

- uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4.0.0
- uses: actions/setup-dotnet@6bd8b7f7774af54e05809fcc5431931b3eb1ddee # v4.0.1
with:
dotnet-version: |
2.1
Expand All @@ -35,13 +35,13 @@ jobs:
8.0
- name: Cache Tools
uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
with:
path: tools
key: ${{ runner.os }}-tools-${{ hashFiles('recipe.cake') }}

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

Expand All @@ -53,4 +53,4 @@ jobs:
cake-version: 1.3.0

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@379614612a29c9e28f31f39a59013eb8012a51f0 # v3
uses: github/codeql-action/analyze@e2b3eafc8d227b0241d48be5f425d47c2d750a13 # v3
2 changes: 1 addition & 1 deletion demo/frosting/build/Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
<PackageReference Include="JetBrains.Annotations" Version="2024.2.0" />
<PackageReference Include="Cake.Frosting" Version="4.0.0" />
<ProjectReference Include="$(ProjectDir)../../../src/Cake.AzurePipelines.Module/Cake.AzurePipelines.Module.csproj" />
<ProjectReference Include="$(ProjectDir)../../../src/Cake.GitHubActions.Module/Cake.GitHubActions.Module.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.201",
"version": "8.0.402",
"rollForward": "latestFeature"
}
}
4 changes: 4 additions & 0 deletions recipe.cake
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ BuildParameters.SetParameters(
shouldUseDeterministicBuilds: true,
gitterMessage: "@/all " + standardNotificationMessage,
twitterMessage: standardNotificationMessage,
shouldRunCodecov: false,
preferredBuildProviderType: BuildProviderType.GitHubActions,
preferredBuildAgentOperatingSystem: PlatformFamily.Linux);

BuildParameters.PrintParameters(Context);

ToolSettings.SetToolPreprocessorDirectives(
gitReleaseManagerGlobalTool: "#tool dotnet:?package=GitReleaseManager.Tool&version=0.18.0");

ToolSettings.SetToolSettings(context: Context);

Build.RunDotNetCore();
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ItemGroup>
<PackageReference Include="Cake.Core" Version="4.0.0" PrivateAssets="All" />
<PackageReference Include="Cake.Common" Version="4.0.0" PrivateAssets="All" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" PrivateAssets="All" />
<PackageReference Include="JetBrains.Annotations" Version="2024.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ItemGroup>
<PackageReference Include="Cake.Core" Version="4.0.0" PrivateAssets="All" />
<PackageReference Include="Cake.Common" Version="4.0.0" PrivateAssets="All" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" PrivateAssets="All" />
<PackageReference Include="JetBrains.Annotations" Version="2024.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
2 changes: 2 additions & 0 deletions src/Cake.GitLabCI.Module/AnsiEscapeCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ internal static class AnsiEscapeCodes
public static readonly string ForegroundYellow = string.Format(FORMAT, 33);
public static readonly string ForegroundLightGray = string.Format(FORMAT, 37);
public static readonly string ForegroundDarkGray = string.Format(FORMAT, 90);
public static readonly string ForegroundBlue = string.Format(FORMAT, 34);
public static readonly string BackgroundMagenta = string.Format(FORMAT, 45);
public static readonly string BackgroundRed = string.Format(FORMAT, 41);
public static readonly string SectionMarker = "\u001B[0K";

private const string FORMAT = "\u001B[{0}m";
}
Expand Down
2 changes: 1 addition & 1 deletion src/Cake.GitLabCI.Module/Cake.GitLabCI.Module.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ItemGroup>
<PackageReference Include="Cake.Core" Version="4.0.0" PrivateAssets="All" />
<PackageReference Include="Cake.Common" Version="4.0.0" PrivateAssets="All" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" PrivateAssets="All" />
<PackageReference Include="JetBrains.Annotations" Version="2024.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
124 changes: 124 additions & 0 deletions src/Cake.GitLabCI.Module/GitLabCIEngine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Module.Shared;

using JetBrains.Annotations;

namespace Cake.GitLabCI.Module
{
/// <summary>
/// <see cref="ICakeEngine"/> implementation for GitLab CI.
/// </summary>
/// <remarks>
/// This engine emits additional console output to make GitLab CI render the output of the indiviudal Cake tasks as collapsible sections
/// (see <see href="https://docs.gitlab.com/ee/ci/yaml/script.html#custom-collapsible-sections">Custom collapsible sections (GitLab Docs)</see>).
/// </remarks>
[UsedImplicitly]
public sealed class GitLabCIEngine : CakeEngineBase
{
private readonly IConsole _console;
private readonly object _sectionNameLock = new object();
private readonly Dictionary<string, string> _taskSectionNames = new Dictionary<string, string>();
private readonly HashSet<string> _sectionNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

/// <summary>
/// Initializes a new instance of the <see cref="GitLabCIEngine"/> class.
/// </summary>
/// <param name="dataService">Implementation of <see cref="ICakeDataService"/>.</param>
/// <param name="log">Implementation of <see cref="ICakeLog"/>.</param>
/// <param name="console">Implementation of <see cref="IConsole"/>.</param>
public GitLabCIEngine(ICakeDataService dataService, ICakeLog log, IConsole console)
: base(new CakeEngine(dataService, log))
{
_console = console;
_engine.BeforeSetup += OnBeforeSetup;
_engine.AfterSetup += OnAfterSetup;
_engine.BeforeTaskSetup += OnBeforeTaskSetup;
_engine.AfterTaskTeardown += OnAfterTaskTeardown;
_engine.BeforeTeardown += OnBeforeTeardown;
_engine.AfterTeardown += OnAfterTeardown;
}

private void OnBeforeSetup(object sender, BeforeSetupEventArgs e)
{
WriteSectionStart("setup", "Executing Setup");
}

private void OnAfterSetup(object sender, AfterSetupEventArgs e)
{
WriteSectionEnd("setup");
}

private void OnBeforeTaskSetup(object sender, BeforeTaskSetupEventArgs e)
{
WriteSectionStart(GetSectionNameForTask(e.TaskSetupContext.Task.Name), $"Executing task \"{e.TaskSetupContext.Task.Name}\"");
}

private void OnAfterTaskTeardown(object sender, AfterTaskTeardownEventArgs e)
{
WriteSectionEnd(GetSectionNameForTask(e.TaskTeardownContext.Task.Name));
}

private void OnBeforeTeardown(object sender, BeforeTeardownEventArgs e)
{
WriteSectionStart("teardown", "Executing Teardown");
}

private void OnAfterTeardown(object sender, AfterTeardownEventArgs e)
{
WriteSectionEnd("teardown");
}

private void WriteSectionStart(string sectionName, string sectionHeader)
{
_console.WriteLine("{0}", $"{AnsiEscapeCodes.SectionMarker}section_start:{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}:{sectionName}\r{AnsiEscapeCodes.SectionMarker}{AnsiEscapeCodes.ForegroundBlue}{sectionHeader}{AnsiEscapeCodes.Reset}");
}

private void WriteSectionEnd(string sectionName)
{
_console.WriteLine("{0}", $"{AnsiEscapeCodes.SectionMarker}section_end:{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}:{sectionName}\r{AnsiEscapeCodes.SectionMarker}");
}

/// <summary>
/// Computes a unique GitLab CI section name for a task name.
/// </summary>
/// <remarks>
/// GitLab CI requires a section name in both the "start" and "end" markers of a section.
/// The name can only be composed of letters, numbers, and the _, ., or - characters.
/// In Cake, each task corresponds to one section.
/// Since the task name may contain characters not allowed in the section name, unsupprted characters are removed from the task name.
/// 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.
/// </remarks>
private string GetSectionNameForTask(string taskName)
{
lock (_sectionNameLock)
{
// If there is already a section name for the task, reuse the same name
if (_taskSectionNames.TryGetValue(taskName, out var sectionName))
{
return sectionName;
}

// Remove unsuported characters from the task name (everything except letters, numbers or the _, ., and - characters
var normalizedTaskName = Regex.Replace(taskName, "[^A-Z|a-z|0-9|_|\\-|\\.]*", string.Empty).ToLowerInvariant();

// Normalizing the task name can cause multiple tasks to be mapped to the same section name
// To avoid name conflicts, append a number to the end to make the section name unique.
sectionName = normalizedTaskName;
var sectionCounter = 0;
while (!_sectionNames.Add(sectionName))
{
sectionName = string.Concat(sectionName, "_", sectionCounter++);
}

// Save task name -> section name mapping for subsequent calls of GetSectionNameForTask()
_taskSectionNames.Add(taskName, sectionName);
return sectionName;
}
}
}
}
2 changes: 2 additions & 0 deletions src/Cake.GitLabCI.Module/GitLabCIModule.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;

using Cake.Core;
using Cake.Core.Annotations;
using Cake.Core.Composition;
using Cake.Core.Diagnostics;
Expand All @@ -19,6 +20,7 @@ public void Register(ICakeContainerRegistrar registrar)
if (StringComparer.OrdinalIgnoreCase.Equals(Environment.GetEnvironmentVariable("CI_SERVER"), "yes"))
{
registrar.RegisterType<GitLabCILog>().As<ICakeLog>().Singleton();
registrar.RegisterType<GitLabCIEngine>().As<ICakeEngine>().Singleton();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Cake.Module.Shared/Cake.Module.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ItemGroup>
<PackageReference Include="Cake.Core" Version="4.0.0" PrivateAssets="All" />
<PackageReference Include="Cake.Common" Version="4.0.0" PrivateAssets="All" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" PrivateAssets="All" />
<PackageReference Include="JetBrains.Annotations" Version="2024.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
2 changes: 1 addition & 1 deletion src/Cake.MyGet.Module/Cake.MyGet.Module.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ItemGroup>
<PackageReference Include="Cake.Core" Version="4.0.0" PrivateAssets="All" />
<PackageReference Include="Cake.Common" Version="4.0.0" PrivateAssets="All" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" PrivateAssets="All" />
<PackageReference Include="JetBrains.Annotations" Version="2024.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
2 changes: 1 addition & 1 deletion src/Cake.TeamCity.Module/Cake.TeamCity.Module.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ItemGroup>
<PackageReference Include="Cake.Core" Version="4.0.0" PrivateAssets="All" />
<PackageReference Include="Cake.Common" Version="4.0.0" PrivateAssets="All" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" PrivateAssets="All" />
<PackageReference Include="JetBrains.Annotations" Version="2024.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
2 changes: 1 addition & 1 deletion src/Cake.TravisCI.Module/Cake.TravisCI.Module.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ItemGroup>
<PackageReference Include="Cake.Core" Version="4.0.0" PrivateAssets="All" />
<PackageReference Include="Cake.Common" Version="4.0.0" PrivateAssets="All" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" PrivateAssets="All" />
<PackageReference Include="JetBrains.Annotations" Version="2024.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down

0 comments on commit e640764

Please sign in to comment.