Skip to content

Commit

Permalink
Add test to build
Browse files Browse the repository at this point in the history
  • Loading branch information
visose committed Dec 4, 2021
1 parent 2e15c7e commit 030e561
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
17 changes: 11 additions & 6 deletions build/Robots.Build/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ namespace Robots.Build;

class Commands
{
public static void Build()
public static int Test()
{
Run("dotnet", "build src/Robots.Grasshopper/Robots.Grasshopper.csproj -c Release");
return Run("dotnet", "test tests/Robots.Tests/Robots.Tests.csproj");
}

public static void Package()
public static int Build()
{
return Run("dotnet", "build src/Robots.Grasshopper/Robots.Grasshopper.csproj -c Release");
}

public static int Package()
{
// Pacakge folder
if (Directory.Exists(PackageFolder))
Expand All @@ -36,17 +41,17 @@ public static void Package()

// Build package
string yak = GetYakPath();
Run(yak, "build", PackageFolder);
return Run(yak, "build", PackageFolder);
}

public static void Publish()
public static int Publish()
{
string packagePath = Directory.EnumerateFiles(PackageFolder)
.Single(f => Path.GetExtension(f) == ".yak");

string packageFile = Path.GetFileName(packagePath);
string yak = GetYakPath();
Run(yak, $"push {packageFile}", PackageFolder);
return Run(yak, $"push {packageFile}", PackageFolder);
}

static string GetYakPath()
Expand Down
11 changes: 9 additions & 2 deletions build/Robots.Build/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Robots.Build;

var commandList = new Dictionary<string, Action>
var commandList = new Dictionary<string, Func<int>>
{
{ "test", Commands.Test },
{ "build", Commands.Build },
{ "package", Commands.Package },
{ "publish", Commands.Publish },
Expand All @@ -22,7 +23,13 @@
}

Console.WriteLine($"Starting {arg}...");
action();
int result = action();

if (result != 0)
{
Console.WriteLine("Premature exit.");
return result;
}
}

Console.WriteLine("Finished with no errors.");
Expand Down
2 changes: 1 addition & 1 deletion build/Robots.Build/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"Robots.Build": {
"commandName": "Project",
"commandLineArgs": "build package publish",
"commandLineArgs": "test build package",
"workingDirectory": "../../"
}
}
Expand Down
9 changes: 2 additions & 7 deletions build/Robots.Build/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ static class Util
public static string BuildFolder => Path.Combine(ArtifactsFolder, "bin", "Robots.Grasshopper", "net48");
public static string PackageFolder => Path.Combine(ArtifactsFolder, "package");

public static void Run(string file, string args, string? setCurrentDir = null)
public static int Run(string file, string args, string? setCurrentDir = null)
{
var currentDir = Directory.GetCurrentDirectory();

Expand All @@ -35,11 +35,6 @@ public static void Run(string file, string args, string? setCurrentDir = null)
process.WaitForExit();

Directory.SetCurrentDirectory(currentDir);

if (process.ExitCode != 0)
{
Console.WriteLine("Premature exit.");
Environment.Exit(process.ExitCode);
}
return process.ExitCode;
}
}

0 comments on commit 030e561

Please sign in to comment.