Skip to content

Commit 0fd8b51

Browse files
authored
Merge pull request #286 from devlead/feature/cakecs
Migrate from Cake.Tool to Cake.Sdk
2 parents 4192bfe + 00a48ab commit 0fd8b51

File tree

7 files changed

+111
-130
lines changed

7 files changed

+111
-130
lines changed

.config/dotnet-tools.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
AZURE_AUTHORITY_HOST: "https://login.microsoftonline.com"
6161
AZURE_DOMAIN: ${{ secrets.AZURE_DOMAIN }}
6262
with:
63-
cake-version: tool-manifest
63+
file-path: cake.cs
6464
target: GitHub-Actions
6565

6666
- name: Setup Pages

build/helpers.cake

Lines changed: 0 additions & 56 deletions
This file was deleted.

build/helpers.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*****************************
2+
* Helpers
3+
*****************************/
4+
5+
public partial class Program
6+
{
7+
static void Main_SetupExtensions()
8+
{
9+
if (BuildSystem.GitHubActions.IsRunningOnGitHubActions)
10+
{
11+
TaskSetup(context => BuildSystem.GitHubActions.Commands.StartGroup(context.Task.Name));
12+
TaskTeardown(context => BuildSystem.GitHubActions.Commands.EndGroup());
13+
}
14+
}
15+
}
16+
17+
18+
public static partial class CakeTaskBuilderExtensions
19+
{
20+
private static ExtensionHelper extensionHelper = new (Task, () => RunTarget(Argument("target", "Default")));
21+
22+
public static CakeTaskBuilder Then(this CakeTaskBuilder cakeTaskBuilder, string name)
23+
=> extensionHelper
24+
.TaskCreate(name)
25+
.IsDependentOn(cakeTaskBuilder);
26+
27+
28+
public static CakeReport Run(this CakeTaskBuilder cakeTaskBuilder)
29+
=> extensionHelper.Run();
30+
31+
public static CakeTaskBuilder Default(this CakeTaskBuilder cakeTaskBuilder)
32+
{
33+
extensionHelper
34+
.TaskCreate("Default")
35+
.IsDependentOn(cakeTaskBuilder);
36+
return cakeTaskBuilder;
37+
}
38+
39+
}
40+
41+
public class FilePathJsonConverter : PathJsonConverter<FilePath>
42+
{
43+
protected override FilePath ConvertFromString(string value) => FilePath.FromString(value);
44+
}
45+
46+
public abstract class PathJsonConverter<TPath> : System.Text.Json.Serialization.JsonConverter<TPath> where TPath : Cake.Core.IO.Path
47+
{
48+
public override TPath Read(ref System.Text.Json.Utf8JsonReader reader, Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
49+
{
50+
var value = reader.GetString();
51+
52+
return value is null ? null : ConvertFromString(value);
53+
}
54+
55+
public override void Write(System.Text.Json.Utf8JsonWriter writer, TPath value, System.Text.Json.JsonSerializerOptions options)
56+
{
57+
writer.WriteStringValue(value.FullPath);
58+
}
59+
60+
protected abstract TPath ConvertFromString(string value);
61+
}
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#load "helpers.cake"
21
using System.Text.Json.Serialization;
32

43
/*****************************
@@ -25,15 +24,15 @@ DirectoryPath OutputPath
2524
public DirectoryPath StatiqWebPath { get; } = ArtifactsPath.Combine(Web);
2625
public DirectoryPath StatiqWebOutputPath { get; } = ArtifactsPath.Combine(Web).Combine(Output);
2726

28-
public string GitHubNuGetSource { get; } = System.Environment.GetEnvironmentVariable("GH_PACKAGES_NUGET_SOURCE");
29-
public string GitHubNuGetApiKey { get; } = System.Environment.GetEnvironmentVariable("GITHUB_TOKEN");
27+
public string? GitHubNuGetSource { get; } = System.Environment.GetEnvironmentVariable("GH_PACKAGES_NUGET_SOURCE");
28+
public string? GitHubNuGetApiKey { get; } = System.Environment.GetEnvironmentVariable("GITHUB_TOKEN");
3029

3130
public bool ShouldPushGitHubPackages() => !ShouldNotPublish
3231
&& !string.IsNullOrWhiteSpace(GitHubNuGetSource)
3332
&& !string.IsNullOrWhiteSpace(GitHubNuGetApiKey);
3433

35-
public string NuGetSource { get; } = System.Environment.GetEnvironmentVariable("NUGET_SOURCE");
36-
public string NuGetApiKey { get; } = System.Environment.GetEnvironmentVariable("NUGET_APIKEY");
34+
public string? NuGetSource { get; } = System.Environment.GetEnvironmentVariable("NUGET_SOURCE");
35+
public string? NuGetApiKey { get; } = System.Environment.GetEnvironmentVariable("NUGET_APIKEY");
3736
public bool ShouldPushNuGetPackages() => IsMainBranch &&
3837
!ShouldNotPublish &&
3938
!string.IsNullOrWhiteSpace(NuGetSource) &&
@@ -54,8 +53,8 @@ public bool ShouldPushNuGetPackages() => IsMainBranch &&
5453
System.Environment.GetEnvironmentVariable("AZURE_AUTHORITY_HOST")
5554
);
5655

57-
public string AzureTenantId { get; } = System.Environment.GetEnvironmentVariable("AZURE_TENANT_ID");
58-
public string AzureDomain { get; } = System.Environment.GetEnvironmentVariable("AZURE_DOMAIN");
56+
public string? AzureTenantId { get; } = System.Environment.GetEnvironmentVariable("AZURE_TENANT_ID");
57+
public string? AzureDomain { get; } = System.Environment.GetEnvironmentVariable("AZURE_DOMAIN");
5958

6059
public bool ShouldRunIntegrationTests() => !string.IsNullOrWhiteSpace(AzureDomain) &&
6160
(
@@ -65,15 +64,16 @@ public bool ShouldRunIntegrationTests() => !string.IsNullOrWhiteSpace(AzureDoma
6564
}
6665

6766
public record AzureCredentials(
68-
string TenantId,
69-
string ClientId,
70-
string ClientSecret,
71-
string AuthorityHost = "login.microsoftonline.com"
67+
string? TenantId,
68+
string? ClientId,
69+
string? ClientSecret,
70+
string? AuthorityHost = "login.microsoftonline.com"
7271
)
7372
{
7473
public bool AzureCredentialsSpecified { get; } = !string.IsNullOrWhiteSpace(TenantId) &&
7574
!string.IsNullOrWhiteSpace(ClientId) &&
7675
!string.IsNullOrWhiteSpace(ClientSecret) &&
7776
!string.IsNullOrWhiteSpace(AuthorityHost);
7877
}
79-
private record ExtensionHelper(Func<string, CakeTaskBuilder> TaskCreate, Func<CakeReport> Run);
78+
79+
internal record ExtensionHelper(Func<string, CakeTaskBuilder> TaskCreate, Func<CakeReport> Run);

build.cake renamed to cake.cs

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
#tool dotnet:?package=GitVersion.Tool&version=6.5.1
2-
#load "build/records.cake"
3-
#load "build/helpers.cake"
1+
#:sdk Cake.Sdk@6.0.0
2+
#:property IncludeAdditionalFiles=./build/*.cs
43
54
/*****************************
65
* Setup
76
*****************************/
87
Setup(
98
static context => {
10-
var assertedVersions = context.GitVersion(new GitVersionSettings
9+
InstallTool("dotnet:https://api.nuget.org/v3/index.json?package=GitVersion.Tool&version=6.5.1");
10+
InstallTool("dotnet:https://api.nuget.org/v3/index.json?package=DPI&version=2025.12.17.349");
11+
var assertedVersions = context.GitVersion(new GitVersionSettings
1112
{
1213
OutputType = GitVersionOutput.Json
1314
});
1415

1516
var branchName = assertedVersions.BranchName;
1617
var isMainBranch = StringComparer.OrdinalIgnoreCase.Equals("main", branchName);
1718

18-
var gh = context.GitHubActions();
1919
var buildDate = DateTime.UtcNow;
20-
var runNumber = gh.IsRunningOnGitHubActions
21-
? gh.Environment.Workflow.RunNumber
20+
var runNumber = GitHubActions.IsRunningOnGitHubActions
21+
? GitHubActions.Environment.Workflow.RunNumber
2222
: (short)((buildDate - buildDate.Date).TotalSeconds/3);
2323

2424
var version = FormattableString
@@ -41,7 +41,7 @@
4141
version,
4242
isMainBranch,
4343
!context.IsRunningOnWindows(),
44-
context.BuildSystem().IsLocalBuild,
44+
BuildSystem.IsLocalBuild,
4545
projectRoot,
4646
projectPath,
4747
new DotNetMSBuildSettings()
@@ -54,7 +54,7 @@
5454
.WithProperty("PackageTags", "tool;bicep;acr;azure")
5555
.WithProperty("PackageDescription", "Azure Resource Inventory .NET Tool - Inventories and documents Azure Tenant resources")
5656
.WithProperty("RepositoryUrl", "https://github.com/devlead/ARI.git")
57-
.WithProperty("ContinuousIntegrationBuild", gh.IsRunningOnGitHubActions ? "true" : "false")
57+
.WithProperty("ContinuousIntegrationBuild", GitHubActions.IsRunningOnGitHubActions ? "true" : "false")
5858
.WithProperty("EmbedUntrackedSources", "true"),
5959
artifactsPath,
6060
artifactsPath.Combine(version)
@@ -80,27 +80,25 @@
8080
)
8181
.Then("DPI")
8282
.Does<BuildData>(
83-
static (context, data) => context.DotNetTool(
84-
"tool",
85-
new DotNetToolSettings {
86-
ArgumentCustomization = args => args
87-
.Append("run")
88-
.Append("dpi")
89-
.Append("nuget")
90-
.Append("--silent")
91-
.AppendSwitchQuoted("--output", "table")
92-
.Append(
93-
(
94-
!string.IsNullOrWhiteSpace(context.EnvironmentVariable("NuGetReportSettings_SharedKey"))
95-
&&
96-
!string.IsNullOrWhiteSpace(context.EnvironmentVariable("NuGetReportSettings_WorkspaceId"))
97-
)
98-
? "report"
99-
: "analyze"
100-
)
101-
.AppendSwitchQuoted("--buildversion", data.Version)
102-
}
103-
)
83+
static (context, data) => {
84+
Command(
85+
["dpi", "dpi.exe"],
86+
new ProcessArgumentBuilder()
87+
.Append("nuget")
88+
.Append("--silent")
89+
.AppendSwitchQuoted("--output", "table")
90+
.Append(
91+
(
92+
!string.IsNullOrWhiteSpace(context.EnvironmentVariable("NuGetReportSettings_SharedKey"))
93+
&&
94+
!string.IsNullOrWhiteSpace(context.EnvironmentVariable("NuGetReportSettings_WorkspaceId"))
95+
)
96+
? "report"
97+
: "analyze"
98+
)
99+
.AppendSwitchQuoted("--buildversion", data.Version)
100+
);
101+
}
104102
)
105103
.Then("Build")
106104
.Does<BuildData>(
@@ -138,11 +136,9 @@
138136
.Then("Upload-Artifacts")
139137
.WithCriteria(BuildSystem.IsRunningOnGitHubActions, nameof(BuildSystem.IsRunningOnGitHubActions))
140138
.Does<BuildData>(
141-
static (context, data) => context
142-
.GitHubActions() is var gh && gh != null
143-
? gh.Commands
144-
.UploadArtifact(data.ArtifactsPath, $"Artifact_{gh.Environment.Runner.ImageOS ?? gh.Environment.Runner.OS}_{context.Environment.Runtime.BuiltFramework.Identifier}_{context.Environment.Runtime.BuiltFramework.Version}")
145-
: throw new Exception("GitHubActions not available")
139+
static (context, data) => GitHubActions
140+
.Commands
141+
.UploadArtifact(data.ArtifactsPath, $"Artifact_{GitHubActions.Environment.Runner.ImageOS ?? GitHubActions.Environment.Runner.OS}_{context.Environment.Runtime.BuiltFramework.Identifier}_{context.Environment.Runtime.BuiltFramework.Version}")
146142
)
147143
.Then("Integration-Tests-Tool-Manifest")
148144
.Does<BuildData>(
@@ -192,9 +188,9 @@
192188
.WithCriteria(BuildSystem.IsRunningOnGitHubActions, nameof(BuildSystem.IsRunningOnGitHubActions))
193189
.WithCriteria<BuildData>((context, data) => data.ShouldRunIntegrationTests(), "ShouldRunIntegrationTests")
194190
.Does<BuildData>(
195-
async (context, data) => {
191+
static (context, data) => {
196192
var resultPath = data.IntegrationTestPath;
197-
await GitHubActions.Commands.UploadArtifact(
193+
GitHubActions.Commands.UploadArtifact(
198194
resultPath,
199195
$"{data.AzureDomain}_{GitHubActions.Environment.Runner.ImageOS ?? GitHubActions.Environment.Runner.OS}_{context.Environment.Runtime.BuiltFramework.Identifier}_{context.Environment.Runtime.BuiltFramework.Version}"
200196
);
@@ -206,7 +202,7 @@ await GitHubActions.Commands.UploadArtifact(
206202
.SelectMany(line => line)
207203
)
208204
);
209-
}
205+
}
210206
)
211207
.Then("Integration-Tests")
212208
.Then("Generate-Statiq-Web")

src/ARI/ARI.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@
4242
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
4343
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.1 " Condition="'$(TargetFramework)' == 'net8.0'" />
4444
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.11" Condition="'$(TargetFramework)' == 'net9.0'" />
45-
<PackageReference Include="Microsoft.Extensions.Http" Version="10.0.0" Condition="'$(TargetFramework)' == 'net10.0'" />
45+
<PackageReference Include="Microsoft.Extensions.Http" Version="10.0.1" Condition="'$(TargetFramework)' == 'net10.0'" />
4646
<PackageReference Include="System.Linq.Async" Version="7.0.0" Condition="'$(TargetFramework)' != 'net10.0'" />
47-
<PackageReference Include="Cake.Bridge.DependencyInjection" Version="2025.11.24.417" />
47+
<PackageReference Include="Cake.Bridge.DependencyInjection" Version="2025.12.17.441" />
4848
<PackageReference Include="Cake.Common" Version="6.0.0" />
49-
<PackageReference Include="Devlead.Console" Version="2025.11.25.507" />
49+
<PackageReference Include="Devlead.Console" Version="2025.12.17.530" />
5050
</ItemGroup>
5151

5252
<ItemGroup>

0 commit comments

Comments
 (0)