Skip to content

Commit

Permalink
fix(mcl.commands.ci_matrix): Fail-fast if nix-eval-jobs returns an …
Browse files Browse the repository at this point in the history
…error
  • Loading branch information
PetarKirov committed Aug 12, 2024
1 parent 3210d94 commit cb38131
Showing 1 changed file with 39 additions and 40 deletions.
79 changes: 39 additions & 40 deletions packages/mcl/src/src/mcl/commands/ci_matrix.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import std.path : buildPath;
import std.process : pipeProcess, wait, Redirect, kill;
import std.exception : enforce;
import std.format : fmt = format;
import std.logger : tracef, infof;
import std.logger : tracef, infof, errorf;

import mcl.utils.env : optional, MissingEnvVarsException, parseEnv;
import mcl.utils.string : enumToString, StringRepresentation, MaxWidth, writeRecordAsTable;
Expand Down Expand Up @@ -141,8 +141,6 @@ version (unittest)
];
}

int exit_code = 0;

Params params;

export void ci_matrix()
Expand Down Expand Up @@ -318,60 +316,61 @@ Package[] nixEvalJobs(string flakeAttrPrefix, string cachixUrl, bool doCheck = t
tracef("%-(%s %)", args);

auto pipes = pipeProcess(args, Redirect.stdout | Redirect.stderr);

void logError(string errorMsg)
{
errorf("Command `%s` failed with error:\n---\n%s\n---",
args, errorMsg);
}

foreach (line; pipes.stdout.byLine)
{
if (line.indexOf("error:") != -1)
if (line.indexOf("{") == -1)
{
stderr.writeln(line);
pipes.pid.kill();
wait(pipes.pid);
exit_code = 1;
errorf("Expected JSON object on stdout from nix-eval-jobs, got: `%s`", line);
continue;
}
else if (line.indexOf("{") != -1)

auto json = parseJSON(line);

if (auto err = "error" in json)
{
Package pkg = line.parseJSON
.packageFromNixEvalJobsJson(flakeAttrPrefix, cachixUrl);
logError((*err).str);
continue; // drain the output
}

if (doCheck) pkg = pkg.checkPackage();
Package pkg = json.packageFromNixEvalJobsJson(
flakeAttrPrefix, cachixUrl);

result ~= pkg;
if (doCheck)pkg = pkg.checkPackage();

struct Output {
bool isCached;
GitHubOS os;
@MaxWidth(50) string attr;
@MaxWidth(80) string output;
}
result ~= pkg;

Output(
isCached: pkg.isCached,
os: pkg.os,
attr: pkg.attrPath,
output: pkg.output
).writeRecordAsTable(stderr.lockingTextWriter);
struct Output {
bool isCached;
GitHubOS os;
@MaxWidth(50) string attr;
@MaxWidth(80) string output;
}

Output(
isCached: pkg.isCached,
os: pkg.os,
attr: pkg.attrPath,
output: pkg.output
).writeRecordAsTable(stderr.lockingTextWriter);
}
foreach (line; pipes.stderr.byLine)
{
if (uselessWarnings.map!((warning) => line.indexOf(warning) != -1).any)
{
continue;
}
else if (line.indexOf("error:") != -1)
{
stderr.writeln(line);
pipes.pid.kill();
wait(pipes.pid);
exit_code = 1;
return result;
}
else
{
stderr.writeln(line);
}

logError(line.idup);
}

wait(pipes.pid);
int status = wait(pipes.pid);
enforce(status == 0, "Command `%s` failed with status %s".fmt(args, status));

return result;
}

Expand Down

0 comments on commit cb38131

Please sign in to comment.