Skip to content

Commit e5e10e4

Browse files
authored
Merge pull request #171 from gep13/feature/cake-5
(#170) Retrofit demo/{script,frosting} ahead of v8.0.0 release
2 parents 8e85991 + 49ae5dc commit e5e10e4

22 files changed

Lines changed: 439 additions & 3 deletions

.github/workflows/build.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,24 @@ jobs:
8383
verbosity: Normal
8484
cake-version: tool-manifest
8585

86+
# The demo/ folders exercise the just-built addin DLL under
87+
# Cake-major-matching cake.tool / Cake.Frosting versions. They run
88+
# in their OWN tool/package context (independent of recipe.cake's
89+
# cake.tool, which is constrained by Cake.Recipe's runtime). Both
90+
# consume the addin from BuildArtifacts/temp/_PublishedLibraries/
91+
# populated by DotNetCore-Pack. demo/sdk joins at the Cake 6
92+
# catch-up release.
93+
94+
- name: Run demo/script
95+
if: success()
96+
shell: pwsh
97+
run: ./demo/script/build.ps1
98+
99+
- name: Run demo/frosting
100+
if: success()
101+
shell: pwsh
102+
run: ./demo/frosting/build.ps1
103+
86104
- name: Upload Issues-Report
87105
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5
88106
with:

demo/frosting/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
bin/
2+
obj/
3+
output/
4+
.vscode/

demo/frosting/build.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
$ErrorActionPreference = 'Stop'
2+
3+
Set-Location -LiteralPath $PSScriptRoot
4+
5+
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = '1'
6+
$env:DOTNET_CLI_TELEMETRY_OPTOUT = '1'
7+
$env:DOTNET_NOLOGO = '1'
8+
9+
dotnet run --project build/Build.csproj -- @args
10+
exit $LASTEXITCODE;

demo/frosting/build.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
set -euox pipefail
3+
4+
cd "$(dirname "${BASH_SOURCE[0]}")"
5+
6+
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
7+
export DOTNET_CLI_TELEMETRY_OPTOUT=1
8+
export DOTNET_NOLOGO=1
9+
10+
dotnet run --project build/Build.csproj -- "$@"

demo/frosting/build/Build.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<RunWorkingDirectory>$(MSBuildProjectDirectory)\</RunWorkingDirectory>
6+
<Nullable>disable</Nullable>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<Reference Include="Cake.FileHelpers">
10+
<HintPath>$(MSBuildProjectDirectory)\..\..\..\BuildArtifacts\temp\_PublishedLibraries\Cake.FileHelpers\net8.0\Cake.FileHelpers.dll</HintPath>
11+
</Reference>
12+
<PackageReference Include="Cake.Frosting" Version="5.1.0" />
13+
</ItemGroup>
14+
</Project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Cake.Core;
2+
using Cake.Core.IO;
3+
using Cake.Frosting;
4+
5+
namespace Build
6+
{
7+
public class BuildContext : FrostingContext
8+
{
9+
public DirectoryPath WorkDir { get; } = "./BuildArtifacts/temp/test-filehelpers-frosting";
10+
11+
public FilePath SampleFile => WorkDir.CombineWithFilePath("sample.txt");
12+
13+
public FilePath SampleFile2 => WorkDir.CombineWithFilePath("sample2.txt");
14+
15+
public FilePath WrittenFile => WorkDir.CombineWithFilePath("written.txt");
16+
17+
public FilePath TouchFile => WorkDir.CombineWithFilePath("touched.txt");
18+
19+
public BuildContext(ICakeContext context)
20+
: base(context)
21+
{
22+
}
23+
}
24+
}

demo/frosting/build/DefaultTask.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Build.Tasks;
2+
using Cake.Frosting;
3+
4+
namespace Build
5+
{
6+
[TaskName("Default")]
7+
[IsDependentOn(typeof(CleanupTask))]
8+
public sealed class DefaultTask : FrostingTask
9+
{
10+
}
11+
}

demo/frosting/build/Program.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Cake.Frosting;
2+
3+
namespace Build
4+
{
5+
public static class Program
6+
{
7+
public static int Main(string[] args)
8+
{
9+
return new CakeHost()
10+
.UseContext<BuildContext>()
11+
.Run(args);
12+
}
13+
}
14+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using Cake.Common.Diagnostics;
3+
using Cake.FileHelpers;
4+
using Cake.Frosting;
5+
6+
namespace Build.Tasks
7+
{
8+
[TaskName("Append-Operations")]
9+
[IsDependentOn(typeof(WriteOperationsTask))]
10+
public sealed class AppendOperationsTask : FrostingTask<BuildContext>
11+
{
12+
public override void Run(BuildContext context)
13+
{
14+
var beforeLines = context.FileReadLines(context.WrittenFile);
15+
16+
context.FileAppendText(context.WrittenFile, "appended text\n");
17+
context.FileAppendLines(context.WrittenFile, new[] { "appended line 1", "appended line 2" });
18+
var afterLines = context.FileReadLines(context.WrittenFile);
19+
20+
AssertThat(
21+
afterLines.Length == beforeLines.Length + 3,
22+
$"Append: expected {beforeLines.Length + 3} lines, got {afterLines.Length}");
23+
AssertThat(
24+
afterLines[afterLines.Length - 1] == "appended line 2",
25+
"Append: last line mismatch");
26+
context.Information("FileAppendText + FileAppendLines OK ({0} lines after append)", afterLines.Length);
27+
}
28+
29+
private static void AssertThat(bool condition, string message)
30+
{
31+
if (!condition)
32+
{
33+
throw new Exception("Assertion failed: " + message);
34+
}
35+
}
36+
}
37+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Cake.Common.Diagnostics;
2+
using Cake.Common.IO;
3+
using Cake.Frosting;
4+
5+
namespace Build.Tasks
6+
{
7+
[TaskName("Cleanup")]
8+
[IsDependentOn(typeof(ReplaceOperationsTask))]
9+
public sealed class CleanupTask : FrostingTask<BuildContext>
10+
{
11+
public override void Run(BuildContext context)
12+
{
13+
if (context.DirectoryExists(context.WorkDir))
14+
{
15+
context.DeleteDirectory(
16+
context.WorkDir,
17+
new DeleteDirectorySettings { Recursive = true });
18+
}
19+
20+
context.Information("Cleanup complete.");
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)