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
9 changes: 5 additions & 4 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
"version": 1,
"isRoot": true,
"tools": {
"cake.tool": {
"version": "4.0.0",
"microsoft.sbom.dotnettool": {
"version": "4.1.0",
"commands": [
"dotnet-cake"
]
"sbom-tool"
],
"rollForward": true
}
}
}
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: CI
on: [push]

env:
xcodeVersion: 16.2
dotnetVersion: 9.0.200
xcodeVersion: 16.4
dotnetVersion: 9.0.304

jobs:
build:
Expand Down Expand Up @@ -33,9 +33,9 @@ jobs:
run: dotnet tool restore

- name: Run the Cake script
run: dotnet cake
run: dotnet run --project build/Build.csproj --artifactsDir ${{ github.workspace }}/artifacts

- uses: actions/upload-artifact@v4
with:
name: NugetPackage
path: artifacts
path: ${{ github.workspace }}/artifacts
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Resource.designer.cs
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/
Expand Down Expand Up @@ -260,3 +259,5 @@ artifacts/

.DS_Store
.vs/

build/artifacts/
79 changes: 0 additions & 79 deletions build.cake

This file was deleted.

16 changes: 16 additions & 0 deletions build/Build.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Cake.Frosting" Version="5.0.0" />
<PackageReference Include="Cake.GitVersioning" Version="3.8.106-alpha" />
</ItemGroup>

</Project>
193 changes: 193 additions & 0 deletions build/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
using Cake.Common;
using Cake.Common.Diagnostics;
using Cake.Common.IO;
using Cake.Common.Tools.DotNet;
using Cake.Common.Tools.DotNet.Build;
using Cake.GitVersioning;
using Cake.Core;
using Cake.Core.IO;
using Cake.Frosting;
using Nerdbank.GitVersioning;
using Spectre.Console;
using Cake.Common.Tools.DotNet.MSBuild;
using Cake.Common.Build;
using Cake.Core.Diagnostics;
using Cake.Common.Tools.DotNet.Tool;
using Cake.Common.Tools.DotNet.Run;

namespace Build;

public static class Program
{
public static int Main(string[] args)
{
return new CakeHost()
.UseContext<BuildContext>()
.Run(args);
}
}

public class BuildContext : FrostingContext
{
public string AppFileRoot { get; }
public string ProjectName { get; set; } = "BTProgressHUD";
public string Target { get; set; }
public string BuildConfiguration { get; set; }
public string ArtifactsDir { get; set; }
public DirectoryPath OutputDir { get; set; }
public VersionOracle VersionInfo { get; set; }
public FilePath ProjectPath { get; set; }
public DotNetVerbosity VerbosityDotNet { get; set; }

public BuildContext(ICakeContext context)
: base(context)
{
AppFileRoot = context.Argument("root", "..");
Target = context.Argument("target", "Default");
BuildConfiguration = context.Argument("configuration", "Release");
ArtifactsDir = context.Argument("artifactsDir", $"{AppFileRoot}/artifacts");
OutputDir = new DirectoryPath(ArtifactsDir);

ProjectPath = new FilePath($"{AppFileRoot}/{ProjectName}/{ProjectName}.csproj");

VersionInfo = context.GitVersioningGetVersion();

var cakeVersion = typeof(ICakeContext).Assembly.GetName().Version.ToString();

AnsiConsole.Write(new FigletText(ProjectName));
context.Information("Building version {0}, ({1}, {2}) using version {3} of Cake.",
VersionInfo.SemVer2,
BuildConfiguration,
Target,
cakeVersion);

if (context.GitHubActions().Environment.PullRequest.IsPullRequest)
{
context.Information("PR HeadRef: {0}", context.GitHubActions().Environment.Workflow.HeadRef);
context.Information("PR BaseRef: {0}", context.GitHubActions().Environment.Workflow.BaseRef);
}

context.Information("RefName: {0}", context.GitHubActions().Environment.Workflow.RefName);

VerbosityDotNet = context.Log.Verbosity switch
{
Verbosity.Quiet => DotNetVerbosity.Quiet,
Verbosity.Normal => DotNetVerbosity.Normal,
Verbosity.Verbose => DotNetVerbosity.Detailed,
Verbosity.Diagnostic => DotNetVerbosity.Diagnostic,
_ => DotNetVerbosity.Minimal
};
}

public DotNetBuildSettings GetDefaultBuildSettings(DotNetMSBuildSettings msBuildSettings = null)
{
msBuildSettings ??= GetDefaultDotNetMSBuildSettings();

var settings = new DotNetBuildSettings
{
Configuration = BuildConfiguration,
MSBuildSettings = msBuildSettings,
Verbosity = VerbosityDotNet
};

return settings;
}

public DotNetMSBuildSettings GetDefaultDotNetMSBuildSettings()
{
var settings = new DotNetMSBuildSettings
{
Version = VersionInfo.SemVer2,
PackageVersion = VersionInfo.NuGetPackageVersion,
InformationalVersion = VersionInfo.AssemblyInformationalVersion
};

return settings;
}
}

[TaskName("Clean")]
public sealed class CleanTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
context.CleanDirectories($"{context.AppFileRoot}/{context.ProjectName}*/**/bin");
context.CleanDirectories($"{context.AppFileRoot}/{context.ProjectName}*/**/obj");
context.CleanDirectories(context.OutputDir.FullPath);

context.EnsureDirectoryExists(context.OutputDir);
}
}

[TaskName("Restore")]
[IsDependentOn(typeof(CleanTask))]
public sealed class RestoreTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
context.DotNetRestore(context.ProjectPath.ToString());
}
}


[TaskName("Build")]
[IsDependentOn(typeof(RestoreTask))]
public sealed class BuildTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
var settings = context.GetDefaultBuildSettings();
context.DotNetBuild(context.ProjectPath.ToString(), settings);
}
}

[TaskName("GenerateSBOM")]
[IsDependentOn(typeof(BuildTask))]
public sealed class GenerateSbomTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
ProcessArgumentBuilder PrepareSbomArguments(ProcessArgumentBuilder args)
{
args.Append("generate");
args.Append("-b {0}", context.OutputDir.FullPath);
args.Append("-bc {0}", context.AppFileRoot);
args.Append("-nsb https://github.com/redth-org/BTProgressHUD");
args.Append("-ps redth-org");
args.Append("-pn BTProgressHUD");
args.Append("-V Verbose");
args.Append("-pv {0}", context.VersionInfo.SemVer2);
return args;
}

var settings = new DotNetToolSettings
{
ArgumentCustomization = PrepareSbomArguments
};

context.DotNetTool("sbom-tool", settings);
}
}

[TaskName("CopyPackages")]
[IsDependentOn(typeof(BuildTask))]
public sealed class CopyPackagesTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
var packagesDir = context.OutputDir.Combine("NuGet/");
context.EnsureDirectoryExists(packagesDir);

var nugetFiles = context.GetFiles($"{context.AppFileRoot}/{context.ProjectName}*/**/bin/{context.BuildConfiguration}/**/*.nupkg");
context.CopyFiles(nugetFiles, packagesDir);
}
}

[TaskName("Default")]
[IsDependentOn(typeof(CleanTask))]
[IsDependentOn(typeof(BuildTask))]
[IsDependentOn(typeof(GenerateSbomTask))]
[IsDependentOn(typeof(CopyPackagesTask))]
public sealed class DefaultTask : FrostingTask<BuildContext>
{
}
9 changes: 9 additions & 0 deletions version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json",
"version": "2.2",
"publicReleaseRefSpec": [
"^refs/heads/main$",
"^refs/tags/\\d+\\.\\d+",
"^refs/tags/v\\d+\\.\\d+"
]
}