|
| 1 | +# CreativeCoders.CakeBuild |
| 2 | + |
| 3 | +A reusable build automation framework built on [Cake Frosting](https://cakebuild.net/docs/running-builds/runners/cake-frosting) for .NET projects. Provides a fluent builder API with pre-built CI/CD tasks — clean, build, test, pack, publish, create GitHub releases, and more — so you can set up a complete build pipeline with minimal code. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- 🏗️ **Fluent Builder API** — Configure your build pipeline with `CakeHostBuilder` in just a few lines |
| 8 | +- 📦 **Pre-built Tasks** — Standard CI/CD tasks out of the box: Clean, Restore, Build, Test, Pack, Publish, NuGet Push, Code Coverage, GitHub Releases, Distribution Packages |
| 9 | +- ⚙️ **Settings Interfaces** — Customize task behavior by implementing strongly-typed settings interfaces |
| 10 | +- 🔍 **Auto-Discovery** — Automatically finds Git root, solution files, and test projects |
| 11 | +- 🏷️ **GitVersion Integration** — Semantic versioning via GitVersion with static fallback |
| 12 | +- 🐙 **GitHub Actions Support** — Log grouping and build server integration |
| 13 | + |
| 14 | +## Getting Started |
| 15 | + |
| 16 | +### Prerequisites |
| 17 | + |
| 18 | +- [.NET 10 SDK](https://dotnet.microsoft.com/download) or later |
| 19 | + |
| 20 | +### Setup |
| 21 | + |
| 22 | +Create a new console application and reference the `CreativeCoders.CakeBuild` package: |
| 23 | + |
| 24 | +```xml |
| 25 | +<Project Sdk="Microsoft.NET.Sdk"> |
| 26 | + <PropertyGroup> |
| 27 | + <OutputType>Exe</OutputType> |
| 28 | + <TargetFramework>net10.0</TargetFramework> |
| 29 | + </PropertyGroup> |
| 30 | + |
| 31 | + <ProjectReference Include="CreativeCoders.CakeBuild" Version="LATEST" /> |
| 32 | +</Project> |
| 33 | +``` |
| 34 | + |
| 35 | +### Minimal Example |
| 36 | + |
| 37 | +```csharp |
| 38 | +using CreativeCoders.CakeBuild; |
| 39 | + |
| 40 | +CakeHostBuilder.Create() |
| 41 | + .UseBuildContext<MyBuildContext>() |
| 42 | + .AddDefaultTasks() |
| 43 | + .AddBuildServerIntegration() |
| 44 | + .InstallTools( |
| 45 | + new DotNetToolInstallation("GitVersion.Tool", "6.5.1"), |
| 46 | + new DotNetToolInstallation("dotnet-reportgenerator-globaltool", "5.5.1")) |
| 47 | + .Build() |
| 48 | + .Run(args); |
| 49 | +``` |
| 50 | + |
| 51 | +## Usage |
| 52 | + |
| 53 | +### Custom Build Context |
| 54 | + |
| 55 | +Extend `CakeBuildContext` and implement the settings interfaces for the tasks you want to configure: |
| 56 | + |
| 57 | +```csharp |
| 58 | +public class MyBuildContext(ICakeContext context) : CakeBuildContext(context), |
| 59 | + IDefaultTaskSettings, |
| 60 | + ICreateDistPackagesTaskSettings |
| 61 | +{ |
| 62 | + public string Copyright => $"{DateTime.Now.Year} My Company"; |
| 63 | + |
| 64 | + public string PackageProjectUrl => "https://github.com/my-org/my-repo"; |
| 65 | + |
| 66 | + public string PackageLicenseExpression => PackageLicenseExpressions.Apache20; |
| 67 | + |
| 68 | + public string NuGetFeedUrl => "https://api.nuget.org/v3/index.json"; |
| 69 | + |
| 70 | + public IEnumerable<DistPackage> DistPackages => |
| 71 | + [ |
| 72 | + new("my-app-linux-x64", "artifacts/publish/my-app/linux-x64", DistPackageFormat.TarGz), |
| 73 | + new("my-app-win-x64", "artifacts/publish/my-app/win-x64", DistPackageFormat.Zip) |
| 74 | + ]; |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +### Available Tasks |
| 79 | + |
| 80 | +All default tasks are registered via `AddDefaultTasks()` and execute in dependency order: |
| 81 | + |
| 82 | +| Task | Description | Depends On | |
| 83 | +|------|-------------|------------| |
| 84 | +| **Clean** | Removes `bin/`, `obj/`, and artifact directories | — | |
| 85 | +| **Restore** | Restores NuGet packages | Clean | |
| 86 | +| **Build** | Builds the solution with version info from GitVersion | Restore | |
| 87 | +| **Test** | Runs tests with optional code coverage collection | Build | |
| 88 | +| **CodeCoverage** | Generates coverage reports via ReportGenerator | Test | |
| 89 | +| **Pack** | Creates NuGet packages with metadata | Build | |
| 90 | +| **NuGetPush** | Pushes packages to a NuGet feed | Pack | |
| 91 | +| **Publish** | Publishes applications to output directories | Build | |
| 92 | +| **CreateDistPackages** | Creates `.tar.gz` / `.zip` distribution archives | Publish | |
| 93 | +| **CreateGitHubRelease** | Creates a GitHub release with assets via Octokit | — | |
| 94 | + |
| 95 | +### Settings Interfaces |
| 96 | + |
| 97 | +Each task reads its configuration from a settings interface. Implement only the ones you need: |
| 98 | + |
| 99 | +| Interface | Configures | |
| 100 | +|-----------|------------| |
| 101 | +| `ICleanTaskSettings` | Directories to clean | |
| 102 | +| `ITestTaskSettings` | Test projects, coverage options | |
| 103 | +| `ICodeCoverageTaskSettings` | Report types and file patterns | |
| 104 | +| `IPackTaskSettings` | Package output, metadata (URL, license, copyright) | |
| 105 | +| `INuGetPushTaskSettings` | Feed URL, API key, skip flag | |
| 106 | +| `IPublishTaskSettings` | Per-project publish configuration (runtime, self-contained) | |
| 107 | +| `ICreateDistPackagesTaskSettings` | Distribution package definitions and output path | |
| 108 | +| `ICreateGitHubReleaseTaskSettings` | Release metadata, assets, GitHub token | |
| 109 | + |
| 110 | +> [!TIP] |
| 111 | +> Implement `IDefaultTaskSettings` to get all standard settings interfaces in one go. |
| 112 | +
|
| 113 | +### Tool Installation |
| 114 | + |
| 115 | +Register external tools via the builder: |
| 116 | + |
| 117 | +```csharp |
| 118 | +CakeHostBuilder.Create() |
| 119 | + .InstallTools( |
| 120 | + new DotNetToolInstallation("GitVersion.Tool", "6.5.1"), |
| 121 | + new DotNetToolInstallation("dotnet-reportgenerator-globaltool", "5.5.1")) |
| 122 | + // ... |
| 123 | +``` |
| 124 | + |
| 125 | +### GitHub Actions Integration |
| 126 | + |
| 127 | +Enable log grouping for GitHub Actions: |
| 128 | + |
| 129 | +```csharp |
| 130 | +CakeHostBuilder.Create() |
| 131 | + .AddBuildServerIntegration() |
| 132 | + // ... |
| 133 | +``` |
| 134 | + |
| 135 | +This registers task setup/teardown hooks that create collapsible log groups in GitHub Actions. |
| 136 | + |
| 137 | +### Generic Task Templates |
| 138 | + |
| 139 | +For advanced scenarios, use the generic task templates (`BuildTask<T>`, `TestTask<T>`, etc.) with a custom context type instead of the default `CakeBuildContext`: |
| 140 | + |
| 141 | +```csharp |
| 142 | +[TaskName("Build")] |
| 143 | +[IsDependentOn(typeof(RestoreTask<MyContext>))] |
| 144 | +public class MyBuildTask : BuildTask<MyContext> { } |
| 145 | +``` |
| 146 | + |
| 147 | +## Sample |
| 148 | + |
| 149 | +See [`samples/CakeBuildSample`](../../../samples/CakeBuildSample) for a complete working example that demonstrates the full pipeline setup with custom context, publishing, and distribution package creation. |
0 commit comments