Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions .config/dotnet-tools.json

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ jobs:
NUGET_APIKEY: ${{steps.login.outputs.NUGET_API_KEY}}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
cake-version: tool-manifest
file-path: cake.cs
target: GitHub-Actions
56 changes: 0 additions & 56 deletions build/helpers.cake

This file was deleted.

61 changes: 61 additions & 0 deletions build/helpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*****************************
* Helpers
*****************************/

public partial class Program
{
static void Main_SetupExtensions()
{
if (BuildSystem.GitHubActions.IsRunningOnGitHubActions)
{
TaskSetup(context => BuildSystem.GitHubActions.Commands.StartGroup(context.Task.Name));
TaskTeardown(context => BuildSystem.GitHubActions.Commands.EndGroup());
}
}
}


public static partial class CakeTaskBuilderExtensions
{
private static ExtensionHelper extensionHelper = new (Task, () => RunTarget(Argument("target", "Default")));

public static CakeTaskBuilder Then(this CakeTaskBuilder cakeTaskBuilder, string name)
=> extensionHelper
.TaskCreate(name)
.IsDependentOn(cakeTaskBuilder);


public static CakeReport Run(this CakeTaskBuilder cakeTaskBuilder)
=> extensionHelper.Run();

public static CakeTaskBuilder Default(this CakeTaskBuilder cakeTaskBuilder)
{
extensionHelper
.TaskCreate("Default")
.IsDependentOn(cakeTaskBuilder);
return cakeTaskBuilder;
}

}

public class FilePathJsonConverter : PathJsonConverter<FilePath>
{
protected override FilePath? ConvertFromString(string value) => FilePath.FromString(value);
}

public abstract class PathJsonConverter<TPath> : System.Text.Json.Serialization.JsonConverter<TPath> where TPath : Cake.Core.IO.Path
{
public override TPath? Read(ref System.Text.Json.Utf8JsonReader reader, Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
{
var value = reader.GetString();

return value is null ? null : ConvertFromString(value);
}

public override void Write(System.Text.Json.Utf8JsonWriter writer, TPath value, System.Text.Json.JsonSerializerOptions options)
{
writer.WriteStringValue(value.FullPath);
}

protected abstract TPath? ConvertFromString(string value);
}
11 changes: 5 additions & 6 deletions build/records.cake → build/records.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#load "helpers.cake"
using System.Text.Json.Serialization;

/*****************************
Expand All @@ -22,15 +21,15 @@ DirectoryPath OutputPath
public DirectoryPath MarkdownPath { get; } = OutputPath.Combine(Markdown);
public FilePath MarkdownIndexPath { get; } = OutputPath.Combine(Markdown).CombineWithFilePath("index.md");

public string GitHubNuGetSource { get; } = System.Environment.GetEnvironmentVariable("GH_PACKAGES_NUGET_SOURCE");
public string GitHubNuGetApiKey { get; } = System.Environment.GetEnvironmentVariable("GH_PACKAGES_NUGET_APIKEY");
public string? GitHubNuGetSource { get; } = System.Environment.GetEnvironmentVariable("GH_PACKAGES_NUGET_SOURCE");
public string? GitHubNuGetApiKey { get; } = System.Environment.GetEnvironmentVariable("GH_PACKAGES_NUGET_APIKEY");

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

public string NuGetSource { get; } = System.Environment.GetEnvironmentVariable("NUGET_SOURCE");
public string NuGetApiKey { get; } = System.Environment.GetEnvironmentVariable("NUGET_APIKEY");
public string? NuGetSource { get; } = System.Environment.GetEnvironmentVariable("NUGET_SOURCE");
public string? NuGetApiKey { get; } = System.Environment.GetEnvironmentVariable("NUGET_APIKEY");
public bool ShouldPushNuGetPackages() => IsMainBranch &&
!ShouldNotPublish &&
!string.IsNullOrWhiteSpace(NuGetSource) &&
Expand All @@ -44,7 +43,7 @@ public bool ShouldPushNuGetPackages() => IsMainBranch &&
};
}

private record ExtensionHelper(Func<string, CakeTaskBuilder> TaskCreate, Func<CakeReport> Run);
internal record ExtensionHelper(Func<string, CakeTaskBuilder> TaskCreate, Func<CakeReport> Run);


public record DPIPackageReference(
Expand Down
28 changes: 14 additions & 14 deletions build.cake → cake.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#tool "dotnet:https://api.nuget.org/v3/index.json?package=GitVersion.Tool&version=6.5.1"
#addin nuget:?package=System.Text.Json&version=10.0.1&loaddependencies=true
#load "build/records.cake"
#load "build/helpers.cake"
#:sdk Cake.Sdk@6.0.0
#:package xunit.v3.assert@3.2.1
#:property IncludeAdditionalFiles=./build/*.cs
using Xunit;

/*****************************
* Setup
*****************************/
Setup(
static context => {
var assertedVersions = context.GitVersion(new GitVersionSettings
InstallTool("dotnet:https://api.nuget.org/v3/index.json?package=GitVersion.Tool&version=6.5.1");
var assertedVersions = context.GitVersion(new GitVersionSettings
{
OutputType = GitVersionOutput.Json
});

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

var gh = context.GitHubActions();
var buildDate = DateTime.UtcNow;
var runNumber = gh.IsRunningOnGitHubActions
? gh.Environment.Workflow.RunNumber
var runNumber = GitHubActions.IsRunningOnGitHubActions
? GitHubActions.Environment.Workflow.RunNumber
: (short)((buildDate - buildDate.Date).TotalSeconds/3);

var version = FormattableString
Expand Down Expand Up @@ -51,7 +51,7 @@
.WithProperty("PackageTags", "tool")
.WithProperty("PackageDescription", "Dependency Inventory .NET Tool - Inventories dependencies to Azure Log Analytics")
.WithProperty("RepositoryUrl", "https://github.com/devlead/DPI.git")
.WithProperty("ContinuousIntegrationBuild", gh.IsRunningOnGitHubActions ? "true" : "false")
.WithProperty("ContinuousIntegrationBuild", GitHubActions.IsRunningOnGitHubActions ? "true" : "false")
.WithProperty("EmbedUntrackedSources", "true"),
artifactsPath,
artifactsPath.Combine(version)
Expand Down Expand Up @@ -100,11 +100,9 @@
.Then("Upload-Artifacts")
.WithCriteria(BuildSystem.IsRunningOnGitHubActions, nameof(BuildSystem.IsRunningOnGitHubActions))
.Does<BuildData>(
static (context, data) => context
.GitHubActions() is var gh && gh != null
? gh.Commands
.UploadArtifact(data.ArtifactsPath, $"Artifact_{gh.Environment.Runner.ImageOS ?? gh.Environment.Runner.OS}_{context.Environment.Runtime.BuiltFramework.Identifier}_{context.Environment.Runtime.BuiltFramework.Version}")
: throw new Exception("GitHubActions not available")
static (context, data) => GitHubActions
.Commands
.UploadArtifact(data.ArtifactsPath, $"Artifact_{GitHubActions.Environment.Runner.ImageOS ?? GitHubActions.Environment.Runner.OS}_{context.Environment.Runtime.BuiltFramework.Identifier}_{context.Environment.Runtime.BuiltFramework.Version}")
)
.Then("Integration-Tests-Restore-MultiTarget")
.Does<BuildData>(
Expand Down Expand Up @@ -191,6 +189,8 @@ out json
string.Concat(json)
);

Assert.NotNull(packageReferences);

Array.ForEach(
packageReferences,
packageReference => Assert.Equal(
Expand Down
6 changes: 3 additions & 3 deletions src/DPI/DPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Devlead.Console" Version="2025.11.25.507" />
<PackageReference Include="Devlead.Console" Version="2025.12.17.530" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
<PackageReference Include="Cake.Core" Version="6.0.0" />
<PackageReference Include="Cake.Common" Version="6.0.0" />
<PackageReference Include="Cake.Bridge.DependencyInjection" Version="2025.11.24.417" />
<PackageReference Include="Cake.Bridge.DependencyInjection" Version="2025.12.17.441" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.1 " Condition="'$(TargetFramework)' == 'net8.0'" />
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.11" Condition="'$(TargetFramework)' == 'net9.0'" />
<PackageReference Include="Microsoft.Extensions.Http" Version="10.0.0" Condition="'$(TargetFramework)' == 'net10.0'" />
<PackageReference Include="Microsoft.Extensions.Http" Version="10.0.1" Condition="'$(TargetFramework)' == 'net10.0'" />
</ItemGroup>

<ItemGroup>
Expand Down