Skip to content

Commit f23cd2e

Browse files
committed
Switch build to Cake Frosting
1 parent 7578869 commit f23cd2e

File tree

75 files changed

+2477
-357
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+2477
-357
lines changed

.appveyor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ install:
2929
# Build Script #
3030
#---------------------------------#
3131
build_script:
32-
- ps: .\build.ps1 --target=CI
32+
- ps: .\build.ps1 --target=Publish
3333

3434
# Tests
3535
test: off

.azuredevops/pipelines/templates/stages/build-for-integration-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ stages:
1212
vmImage: 'ubuntu-22.04'
1313
steps:
1414
- template: ../steps/install-required-dotnet-versions-for-building.yml
15-
- bash: ./build.sh --target=Create-NuGet-Packages
15+
- bash: ./build.sh --target=Package
1616
displayName: 'Build'
1717
- publish: $(Build.SourcesDirectory)/BuildArtifacts/Packages/NuGet
1818
artifact: NuGet Package

.config/dotnet-tools.json

-12
This file was deleted.

.github/renovate.json

+13
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@
2424
],
2525
"datasourceTemplate": "nuget",
2626
"versioningTemplate": "nuget"
27+
},
28+
{
29+
"customType": "regex",
30+
"description": "Update NuGet package versions in C# files",
31+
"fileMatch": [
32+
"build/{{arg0}}$",
33+
"src/{{arg1}}$"
34+
],
35+
"matchStrings": [
36+
"// renovate:( datasource=(?<datasource>.*?))? depName=(?<depName>.*?)( versioning=(?<versioning>.*?))?( extractVersion=(?<extractVersion>.*?))?\\s*const string \\w*[vV]ersion = \"(?<currentValue>\\S*)\";\\s?"
37+
],
38+
"datasourceTemplate": "nuget",
39+
"versioningTemplate": "nuget"
2740
}
2841
],
2942
"packageRules": [

.github/workflows/integrationtests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
8.x
3333
9.x
3434
- name: Build
35-
run: ./build.sh --target=Create-NuGet-Packages
35+
run: ./build.sh --target=Package
3636
shell: bash
3737
- name: Publish NuGet package as build artifact
3838
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -305,4 +305,5 @@ __pycache__/
305305
# Project specific
306306

307307
BuildArtifacts/
308+
build/tools/*
308309
docs/.cache/

build.ps1

+2-15
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,2 @@
1-
$ErrorActionPreference = 'Stop'
2-
3-
$SCRIPT_NAME = "recipe.cake"
4-
5-
Write-Host "Restoring .NET Core tools"
6-
dotnet tool restore
7-
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
8-
9-
Write-Host "Bootstrapping Cake"
10-
dotnet cake $SCRIPT_NAME --bootstrap
11-
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
12-
13-
Write-Host "Running Build"
14-
dotnet cake $SCRIPT_NAME @args
15-
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
1+
dotnet run --project build/Build.csproj -- $args
2+
exit $LASTEXITCODE;

build.sh

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,2 @@
11
#!/bin/bash
2-
SCRIPT_NAME="recipe.cake"
3-
4-
echo "Restoring .NET Core tools"
5-
dotnet tool restore
6-
7-
echo "Bootstrapping Cake"
8-
dotnet cake $SCRIPT_NAME --bootstrap
9-
10-
echo "Running Build"
11-
dotnet cake $SCRIPT_NAME "$@"
2+
dotnet run --project ./build/Build.csproj -- "$@"

build/Build.csproj

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
7+
8+
<!-- Make sure start same folder .NET Core CLI and Visual Studio. -->
9+
<!-- Also expected from Cake.Issues.Recipe to have build directory set as working directory. -->
10+
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="Cake.Codecov" Version="3.0.0" />
15+
<PackageReference Include="Cake.Frosting" Version="5.0.0" />
16+
<PackageReference Include="Cake.Frosting.Issues.Recipe" Version="5.1.1" />
17+
</ItemGroup>
18+
19+
</Project>

build/BuildLifetime.cs

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using Cake.Common;
2+
using Cake.Common.Build;
3+
using Cake.Common.Diagnostics;
4+
using Cake.Common.IO;
5+
using Cake.Common.Tools.GitVersion;
6+
using Cake.Core;
7+
using Cake.Frosting;
8+
using Spectre.Console;
9+
10+
public class BuildLifetime : FrostingLifetime<BuildContext>
11+
{
12+
public override void Setup(BuildContext context, ISetupContext info)
13+
{
14+
AnsiConsole.Write(new FigletText("Cake.Issues").Centered());
15+
16+
// Determine version
17+
DetermineVersion(context);
18+
19+
// Cleanup "dist" folder
20+
context.CleanDirectory(context.Parameters.OutputDirectory);
21+
}
22+
23+
public override void Teardown(BuildContext context, ITeardownContext info)
24+
{
25+
}
26+
27+
private static void DetermineVersion(BuildContext context)
28+
{
29+
var settings = new GitVersionSettings
30+
{
31+
ToolPath = context.Tools.Resolve("dotnet-gitversion.exe")
32+
};
33+
34+
if (settings.ToolPath == null)
35+
{
36+
settings.ToolPath = context.Tools.Resolve("dotnet-gitversion");
37+
}
38+
39+
if (!context.BuildSystem().IsLocalBuild)
40+
{
41+
settings.UpdateAssemblyInfo = true;
42+
settings.UpdateAssemblyInfoFilePath =
43+
context.State.RepositoryRootDirectory
44+
.GetRelativePath(context.Paths.SrcDirectoryPath)
45+
.CombineWithFilePath("SolutionInfo.cs");
46+
}
47+
48+
context.State.Version = context.GitVersion(settings);
49+
50+
context.Information("Building version {0}", context.State.Version.FullSemVer);
51+
}
52+
}

build/Context/BuildContext.cs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Cake.Core;
2+
3+
/// <summary>
4+
/// Class holding state during execution of build.
5+
/// </summary>
6+
public class BuildContext : IssuesContext<BuildParameters, BuildState>
7+
{
8+
public Paths Paths { get; }
9+
10+
public BuildContext(ICakeContext context)
11+
: base(context)
12+
{
13+
Paths = new Paths(this);
14+
}
15+
16+
protected override BuildParameters CreateIssuesParameters()
17+
{
18+
return new BuildParameters(this);
19+
}
20+
21+
protected override BuildState CreateIssuesState()
22+
{
23+
return new BuildState(this);
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Cake.Core;
2+
3+
public class BuildParameters : IssuesParameters
4+
{
5+
public CodeCoverageParameters CodeCoverage { get; }
6+
7+
public MsBuildParameters Build { get; }
8+
9+
public PackagingParameters Packaging { get; }
10+
11+
public BuildParameters(ICakeContext context)
12+
{
13+
this.OutputDirectory = "../BuildArtifacts";
14+
this.CodeCoverage = new CodeCoverageParameters(context);
15+
this.Build = new MsBuildParameters(context);
16+
this.Packaging = new PackagingParameters(context);
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using Cake.Common;
2+
using Cake.Core;
3+
4+
public class CodeCoverageParameters(ICakeContext context)
5+
{
6+
public string CodecovRepoToken { get; } = context.EnvironmentVariable("CODECOV_REPO_TOKEN");
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Cake.Common.Build;
2+
using Cake.Common.Tools.DotNet.MSBuild;
3+
using Cake.Core;
4+
5+
public class MsBuildParameters(ICakeContext context)
6+
{
7+
public string Configuration { get; } = "Release"; // Configuration is also hardcoded in nuspec files
8+
9+
public DotNetMSBuildSettings GetSettings()
10+
{
11+
return new DotNetMSBuildSettings()
12+
.SetConfiguration(this.Configuration)
13+
.WithProperty("ContinuousIntegrationBuild", (!context.BuildSystem().IsLocalBuild).ToString());
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using Cake.Common;
2+
using Cake.Core;
3+
4+
public class PackagingParameters(ICakeContext context)
5+
{
6+
public string NuGetApiKey { get; } = context.EnvironmentVariable("NUGET_API_KEY");
7+
}

build/Context/Paths.cs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Cake.Common.IO;
2+
using Cake.Core.IO;
3+
4+
public class Paths
5+
{
6+
public FilePath SolutionFilePath { get; }
7+
8+
public DirectoryPath SrcDirectoryPath { get; }
9+
10+
public DirectoryPath NuspecDirectoryPath { get; }
11+
12+
public DirectoryPath OutputLogsDirectoryPath { get; }
13+
14+
public DirectoryPath OutputPackagesNuGetDirectoryPath { get; }
15+
16+
public DirectoryPath OutputTestResultsDirectoryPath { get; }
17+
18+
public Paths(BuildContext context)
19+
{
20+
this.SrcDirectoryPath = context.State.RepositoryRootDirectory.Combine("src");
21+
this.NuspecDirectoryPath = context.State.RepositoryRootDirectory.Combine("nuspec").Combine("nuget");
22+
23+
this.OutputLogsDirectoryPath = context.Parameters.OutputDirectory.Combine("logs");
24+
this.OutputPackagesNuGetDirectoryPath = context.Parameters.OutputDirectory.Combine("Packages").Combine("NuGet");
25+
this.OutputTestResultsDirectoryPath = context.Parameters.OutputDirectory.Combine("TestResults");
26+
27+
this.SolutionFilePath = this.SrcDirectoryPath.CombineWithFilePath("Cake.Issues.sln");
28+
29+
context.EnsureDirectoryExists(context.Parameters.OutputDirectory);
30+
}
31+
}

build/Context/State/BuildState.cs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Cake.Common.Tools.GitVersion;
2+
3+
public class BuildState : IssuesState
4+
{
5+
public GitVersion Version { get; set; }
6+
7+
public BuildState(BuildContext context)
8+
: base(context, RepositoryInfoProviderType.CakeGit)
9+
{
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Cake.Core.Packaging;
2+
using Cake.Frosting;
3+
4+
internal static class ServiceProviderExtensions
5+
{
6+
public static void InstallTool(this IServiceProvider provider, string packageName, string packageVersion)
7+
{
8+
var toolInstaller = (IToolInstaller)provider.GetService(typeof(IToolInstaller));
9+
toolInstaller.Install(new PackageReference($"nuget:?package={packageName}&version={packageVersion}"));
10+
}
11+
}

build/Program.cs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Cake.Frosting;
2+
using System.Reflection;
3+
4+
public static class Program
5+
{
6+
public static int Main(string[] args)
7+
{
8+
// renovate: depName=GitVersion.Tool
9+
const string nuGetVersion = "6.1.0";
10+
11+
return new CakeHost()
12+
.UseContext<BuildContext>()
13+
.UseLifetime<BuildLifetime>()
14+
.AddAssembly(Assembly.GetAssembly(typeof(IssuesTask)))
15+
.InstallTool(new Uri($"dotnet:?package=GitVersion.Tool&version={nuGetVersion}"))
16+
.Run(args);
17+
}
18+
}
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Cake.Common.Tools.DotNet;
2+
using Cake.Common.Tools.DotNet.Build;
3+
using Cake.Common.Tools.DotNet.MSBuild;
4+
using Cake.Frosting;
5+
6+
[TaskName("Build-Solution")]
7+
[IsDependentOn(typeof(RestoreSolutionTask))]
8+
[IsDependeeOf(typeof(ReadIssuesTask))]
9+
public sealed class BuildSolutionTask : FrostingTask<BuildContext>
10+
{
11+
public override void Run(BuildContext context)
12+
{
13+
var msBuildLogFilePath = context.Paths.OutputLogsDirectoryPath.CombineWithFilePath("build.binlog");
14+
15+
var settings = new DotNetBuildSettings
16+
{
17+
NoRestore = true,
18+
MSBuildSettings =
19+
context.Parameters.Build.GetSettings()
20+
.WithLogger(
21+
"BinaryLogger," + context.Environment.ApplicationRoot.CombineWithFilePath("StructuredLogger.dll"),
22+
"",
23+
msBuildLogFilePath.FullPath)
24+
.WithTarget("Rebuild"),
25+
};
26+
27+
context.DotNetBuild(context.Paths.SolutionFilePath.FullPath, settings);
28+
29+
// Read issues
30+
context.Parameters.InputFiles.AddMsBuildBinaryLogFilePath(msBuildLogFilePath);
31+
}
32+
}

build/Tasks/Build/BuildTask.cs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using Cake.Frosting;
2+
3+
[TaskName("Build")]
4+
[IsDependentOn(typeof(BuildSolutionTask))]
5+
public sealed class BuildTask : FrostingTask
6+
{
7+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Cake.Common.Build;
2+
using Cake.Common.Tools.DotNet;
3+
using Cake.Common.Tools.DotNet.Restore;
4+
using Cake.Frosting;
5+
6+
[TaskName("Restore-Solution")]
7+
public sealed class RestoreSolutionTask : FrostingTask<BuildContext>
8+
{
9+
public override void Run(BuildContext context)
10+
{
11+
// Enforce up to date lock files in CI builds.
12+
// On local builds lock files will be updated if necessary.
13+
var settings = new DotNetRestoreSettings
14+
{
15+
LockedMode = !context.BuildSystem().IsLocalBuild,
16+
MSBuildSettings = context.Parameters.Build.GetSettings(),
17+
};
18+
19+
context.DotNetRestore(context.Paths.SolutionFilePath.FullPath, settings);
20+
}
21+
}

0 commit comments

Comments
 (0)