Skip to content

Commit

Permalink
Add install/uninstall targets to the Cake script.
Browse files Browse the repository at this point in the history
Installing Novadrop tools from source can now be done simply as `./cake install`.

Closes #97.
  • Loading branch information
alexrp committed Dec 12, 2023
1 parent b871de5 commit 1b19f03
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions novadrop.cake
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,36 @@ DotNetMSBuildSettings ConfigureMSBuild(string target)
};
}

void RunDotNet(Func<ProcessArgumentBuilder, ProcessArgumentBuilder> appender, Func<string, string, bool> checker)
{
var code = StartProcess(
Context.Tools.Resolve(new[] { "dotnet", "dotnet.exe" }) ??
throw new CakeException(".NET CLI: Could not locate executable."),
new()
{
Arguments = appender(new()),
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectedStandardOutputHandler = text =>
{
Console.Out.WriteLine(text);

return text;
},
RedirectedStandardErrorHandler = text =>
{
Console.Error.WriteLine(text);

return text;
},
},
out var stdOut,
out var stdErr);

if (code != 0 && checker(string.Join(null, stdOut), string.Join(null, stdErr)))
throw new CakeException(code, $".NET CLI: Process returned an error (exit code {code}).");
}

// Tasks

Task("default")
Expand Down Expand Up @@ -131,6 +161,42 @@ Task("pack-core")
Task("pack")
.IsDependentOn("pack-core");

Task("install-core")
.IsDependentOn("pack-core")
.Does(() =>
{
foreach (var tool in new[] { "dc", "rc" })
RunDotNet(
args =>
args
.Append("tool")
.Append("update")
.Append($"novadrop-{tool}")
.Append("--prerelease")
.Append("-g"),
(_, _) => true);
});

Task("install")
.IsDependentOn("install-core");

Task("uninstall-core")
.Does(() =>
{
foreach (var tool in new[] { "dc", "rc" })
RunDotNet(
args =>
args
.Append("tool")
.Append("uninstall")
.Append($"novadrop-{tool}")
.Append("-g"),
(_, stdErr) => !stdErr.StartsWith($"A tool with the package Id 'novadrop-{tool}' could not be found."));
});

Task("uninstall")
.IsDependentOn("uninstall-core");

Task("upload-core-github")
.WithCriteria(BuildSystem.GitHubActions.Environment.Workflow.Ref == "refs/heads/master")
.WithCriteria(configuration == "Debug")
Expand Down

0 comments on commit 1b19f03

Please sign in to comment.