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
18 changes: 18 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,24 @@ jobs:
verbosity: Normal
cake-version: tool-manifest

# The demo/ folders exercise the just-built addin DLL under
# Cake-major-matching cake.tool / Cake.Frosting versions. They run
# in their OWN tool/package context (independent of recipe.cake's
# cake.tool, which is constrained by Cake.Recipe's runtime). Both
# consume the addin from BuildArtifacts/temp/_PublishedLibraries/
# populated by DotNetCore-Pack. demo/sdk joins at the Cake 6
# catch-up release.

- name: Run demo/script
if: success()
shell: pwsh
run: ./demo/script/build.ps1

- name: Run demo/frosting
if: success()
shell: pwsh
run: ./demo/frosting/build.ps1

- name: Upload Issues-Report
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5
with:
Expand Down
4 changes: 4 additions & 0 deletions demo/frosting/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bin/
obj/
output/
.vscode/
10 changes: 10 additions & 0 deletions demo/frosting/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
$ErrorActionPreference = 'Stop'

Set-Location -LiteralPath $PSScriptRoot

$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = '1'
$env:DOTNET_CLI_TELEMETRY_OPTOUT = '1'
$env:DOTNET_NOLOGO = '1'

dotnet run --project build/Build.csproj -- @args
exit $LASTEXITCODE;
10 changes: 10 additions & 0 deletions demo/frosting/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -euox pipefail

cd "$(dirname "${BASH_SOURCE[0]}")"

export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_NOLOGO=1

dotnet run --project build/Build.csproj -- "$@"
14 changes: 14 additions & 0 deletions demo/frosting/build/Build.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RunWorkingDirectory>$(MSBuildProjectDirectory)\</RunWorkingDirectory>
<Nullable>disable</Nullable>
</PropertyGroup>
<ItemGroup>
<Reference Include="Cake.FileHelpers">
<HintPath>$(MSBuildProjectDirectory)\..\..\..\BuildArtifacts\temp\_PublishedLibraries\Cake.FileHelpers\net8.0\Cake.FileHelpers.dll</HintPath>
</Reference>
<PackageReference Include="Cake.Frosting" Version="5.1.0" />
</ItemGroup>
</Project>
24 changes: 24 additions & 0 deletions demo/frosting/build/BuildContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Cake.Core;
using Cake.Core.IO;
using Cake.Frosting;

namespace Build
{
public class BuildContext : FrostingContext
{
public DirectoryPath WorkDir { get; } = "./BuildArtifacts/temp/test-filehelpers-frosting";

public FilePath SampleFile => WorkDir.CombineWithFilePath("sample.txt");

public FilePath SampleFile2 => WorkDir.CombineWithFilePath("sample2.txt");

public FilePath WrittenFile => WorkDir.CombineWithFilePath("written.txt");

public FilePath TouchFile => WorkDir.CombineWithFilePath("touched.txt");

public BuildContext(ICakeContext context)
: base(context)
{
}
}
}
11 changes: 11 additions & 0 deletions demo/frosting/build/DefaultTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Build.Tasks;
using Cake.Frosting;

namespace Build
{
[TaskName("Default")]
[IsDependentOn(typeof(CleanupTask))]
public sealed class DefaultTask : FrostingTask
{
}
}
14 changes: 14 additions & 0 deletions demo/frosting/build/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Cake.Frosting;

namespace Build
{
public static class Program
{
public static int Main(string[] args)
{
return new CakeHost()
.UseContext<BuildContext>()
.Run(args);
}
}
}
37 changes: 37 additions & 0 deletions demo/frosting/build/Tasks/AppendOperationsTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using Cake.Common.Diagnostics;
using Cake.FileHelpers;
using Cake.Frosting;

namespace Build.Tasks
{
[TaskName("Append-Operations")]
[IsDependentOn(typeof(WriteOperationsTask))]
public sealed class AppendOperationsTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
var beforeLines = context.FileReadLines(context.WrittenFile);

context.FileAppendText(context.WrittenFile, "appended text\n");
context.FileAppendLines(context.WrittenFile, new[] { "appended line 1", "appended line 2" });
var afterLines = context.FileReadLines(context.WrittenFile);

AssertThat(
afterLines.Length == beforeLines.Length + 3,
$"Append: expected {beforeLines.Length + 3} lines, got {afterLines.Length}");
AssertThat(
afterLines[afterLines.Length - 1] == "appended line 2",
"Append: last line mismatch");
context.Information("FileAppendText + FileAppendLines OK ({0} lines after append)", afterLines.Length);
}

private static void AssertThat(bool condition, string message)
{
if (!condition)
{
throw new Exception("Assertion failed: " + message);
}
}
}
}
23 changes: 23 additions & 0 deletions demo/frosting/build/Tasks/CleanupTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Cake.Common.Diagnostics;
using Cake.Common.IO;
using Cake.Frosting;

namespace Build.Tasks
{
[TaskName("Cleanup")]
[IsDependentOn(typeof(ReplaceOperationsTask))]
public sealed class CleanupTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
if (context.DirectoryExists(context.WorkDir))
{
context.DeleteDirectory(
context.WorkDir,
new DeleteDirectorySettings { Recursive = true });
}

context.Information("Cleanup complete.");
}
}
}
54 changes: 54 additions & 0 deletions demo/frosting/build/Tasks/FindOperationsTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Text.RegularExpressions;
using Cake.Common.Diagnostics;
using Cake.FileHelpers;
using Cake.Frosting;

namespace Build.Tasks
{
[TaskName("Find-Operations")]
[IsDependentOn(typeof(TouchTask))]
public sealed class FindOperationsTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
var samples = context.WorkDir.CombineWithFilePath("sample*.txt").FullPath;

var byText = context.FindTextInFiles(samples, "alpha");
AssertThat(byText.Length == 2, "FindTextInFiles 'alpha': expected 2 files, got " + byText.Length);
context.Information("FindTextInFiles 'alpha' OK ({0} files)", byText.Length);

var byRegex = context.FindRegexInFiles(samples, @"\d+");
AssertThat(byRegex.Length == 1, "FindRegexInFiles digits: expected 1 file (sample.txt has '42'), got " + byRegex.Length);
context.Information("FindRegexInFiles digits OK ({0} file)", byRegex.Length);

var single = context.FindRegexMatchInFile(context.SampleFile, @"\d+", RegexOptions.None);
AssertThat(single == "1", "FindRegexMatchInFile: expected first digit run '1' (from 'line 1'), got " + (single ?? "null"));
context.Information("FindRegexMatchInFile digits OK ('{0}')", single);

var many = context.FindRegexMatchesInFile(context.SampleFile, @"alpha", RegexOptions.None);
AssertThat(many != null && many.Count == 2, $"FindRegexMatchesInFile 'alpha': expected 2 matches, got {many?.Count ?? 0}");
context.Information("FindRegexMatchesInFile 'alpha' OK ({0} matches)", many.Count);

var group = context.FindRegexMatchGroupInFile(context.SampleFile, @"gamma (\d+)", 1, RegexOptions.None);
AssertThat(group != null && group.Value == "42", "FindRegexMatchGroupInFile: expected group '42', got " + (group?.Value ?? "null"));
context.Information("FindRegexMatchGroupInFile OK ('{0}')", group.Value);

var groups = context.FindRegexMatchGroupsInFile(context.SampleFile, @"(alpha) (line)", RegexOptions.None);
AssertThat(groups != null && groups.Count == 3, $"FindRegexMatchGroupsInFile: expected 3 groups (full + 2 captures), got {groups?.Count ?? 0}");
context.Information("FindRegexMatchGroupsInFile OK ({0} groups)", groups.Count);

var allGroups = context.FindRegexMatchesGroupsInFile(context.SampleFile, @"(alpha) (line)", RegexOptions.None);
AssertThat(allGroups != null && allGroups.Count == 2, $"FindRegexMatchesGroupsInFile: expected 2 matches, got {allGroups?.Count ?? 0}");
context.Information("FindRegexMatchesGroupsInFile OK ({0} matches)", allGroups.Count);
}

private static void AssertThat(bool condition, string message)
{
if (!condition)
{
throw new Exception("Assertion failed: " + message);
}
}
}
}
33 changes: 33 additions & 0 deletions demo/frosting/build/Tasks/ReadOperationsTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using Cake.Common.Diagnostics;
using Cake.FileHelpers;
using Cake.Frosting;

namespace Build.Tasks
{
[TaskName("Read-Operations")]
[IsDependentOn(typeof(SetupTask))]
public sealed class ReadOperationsTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
var lines = context.FileReadLines(context.SampleFile);
AssertThat(lines.Length == 4, "FileReadLines: expected 4 lines, got " + lines.Length);
AssertThat(lines[0] == "alpha line 1", "FileReadLines: first line mismatch");
AssertThat(lines[3] == "alpha line 4", "FileReadLines: last line mismatch");
context.Information("FileReadLines OK ({0} lines)", lines.Length);

var text = context.FileReadText(context.SampleFile);
AssertThat(text.Contains("gamma 42 delta"), "FileReadText: expected content not found");
context.Information("FileReadText OK ({0} chars)", text.Length);
}

private static void AssertThat(bool condition, string message)
{
if (!condition)
{
throw new Exception("Assertion failed: " + message);
}
}
}
}
40 changes: 40 additions & 0 deletions demo/frosting/build/Tasks/ReplaceOperationsTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using Cake.Common.Diagnostics;
using Cake.FileHelpers;
using Cake.Frosting;

namespace Build.Tasks
{
[TaskName("Replace-Operations")]
[IsDependentOn(typeof(FindOperationsTask))]
public sealed class ReplaceOperationsTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
var samples = context.WorkDir.CombineWithFilePath("sample*.txt").FullPath;

var changed = context.ReplaceTextInFiles(samples, "alpha", "ALPHA");
AssertThat(changed.Length == 2, "ReplaceTextInFiles 'alpha'->'ALPHA': expected 2 changed files, got " + changed.Length);

var afterText = context.FileReadText(context.SampleFile);
AssertThat(
afterText.Contains("ALPHA") && !afterText.Contains("alpha"),
"ReplaceTextInFiles: replacement not applied to sample.txt");
context.Information("ReplaceTextInFiles OK ({0} files modified)", changed.Length);

var changedRx = context.ReplaceRegexInFiles(samples, @"beta", "BETA");
AssertThat(changedRx.Length == 1, "ReplaceRegexInFiles 'beta'->'BETA': expected 1 changed file (only sample.txt has 'beta'), got " + changedRx.Length);
var afterRegex = context.FileReadText(context.SampleFile);
AssertThat(afterRegex.Contains("BETA"), "ReplaceRegexInFiles: replacement not applied");
context.Information("ReplaceRegexInFiles OK ({0} files modified)", changedRx.Length);
}

private static void AssertThat(bool condition, string message)
{
if (!condition)
{
throw new Exception("Assertion failed: " + message);
}
}
}
}
32 changes: 32 additions & 0 deletions demo/frosting/build/Tasks/SetupTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.IO;
using Cake.Common.Diagnostics;
using Cake.Common.IO;
using Cake.Frosting;

namespace Build.Tasks
{
[TaskName("Setup")]
public sealed class SetupTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
if (context.DirectoryExists(context.WorkDir))
{
context.DeleteDirectory(
context.WorkDir,
new DeleteDirectorySettings { Recursive = true });
}

context.EnsureDirectoryExists(context.WorkDir);

File.WriteAllLines(
context.MakeAbsolute(context.SampleFile).FullPath,
new[] { "alpha line 1", "beta line 2", "gamma 42 delta", "alpha line 4" });
File.WriteAllText(
context.MakeAbsolute(context.SampleFile2).FullPath,
"second file with the word alpha");

context.Information("Setup complete.");
}
}
}
39 changes: 39 additions & 0 deletions demo/frosting/build/Tasks/TouchTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.IO;
using System.Threading;
using Cake.Common.Diagnostics;
using Cake.Common.IO;
using Cake.FileHelpers;
using Cake.Frosting;

namespace Build.Tasks
{
[TaskName("Touch")]
[IsDependentOn(typeof(AppendOperationsTask))]
public sealed class TouchTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
// FileTouch updates the timestamps of an existing file (it does NOT create).
var touchPath = context.MakeAbsolute(context.TouchFile).FullPath;
File.WriteAllText(touchPath, string.Empty);
var beforeUtc = File.GetLastWriteTimeUtc(touchPath);
Thread.Sleep(10);
context.FileTouch(context.TouchFile);
var afterUtc = File.GetLastWriteTimeUtc(touchPath);

AssertThat(
afterUtc > beforeUtc,
$"FileTouch: timestamp did not advance (before={beforeUtc:o}, after={afterUtc:o})");
context.Information("FileTouch OK (advanced from {0:o} to {1:o})", beforeUtc, afterUtc);
}

private static void AssertThat(bool condition, string message)
{
if (!condition)
{
throw new Exception("Assertion failed: " + message);
}
}
}
}
Loading
Loading