Skip to content
Merged
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
41 changes: 21 additions & 20 deletions packages/mcl/src/src/mcl/commands/ci_matrix.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module mcl.commands.ci_matrix;
import std.stdio : writeln, stderr, stdout;
import std.traits : EnumMembers;
import std.string : indexOf, splitLines;
import std.algorithm : map, filter, reduce, chunkBy, find, any, sort, startsWith, each;
import std.algorithm : map, filter, reduce, chunkBy, find, any, sort, startsWith, each, canFind, fold;
import std.file : write, readText;
import std.range : array, front, join, split;
import std.conv : to;
Expand All @@ -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, errorf;
import std.logger : tracef, infof, errorf, warningf;

import mcl.utils.env : optional, MissingEnvVarsException, parseEnv;
import mcl.utils.string : enumToString, StringRepresentation, MaxWidth, writeRecordAsTable;
Expand Down Expand Up @@ -318,30 +318,29 @@ Package[] nixEvalJobs(string flakeAttrPrefix, string cachixUrl, bool doCheck = t
"--flake", rootDir ~ "#" ~ flakeAttrPrefix
];

const commandString = args.join(" ");

tracef("%-(%s %)", args);

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

void logError(string errorMsg)
void logWarning(const char[] msg)
{
errorf("Command `%s` failed with error:\n---\n%s\n---",
args, errorMsg);
warningf("Command `%s` stderr:\n---\n%s\n---", commandString, msg);
}

foreach (line; pipes.stdout.byLine)
void logError(const char[] msg)
{
if (line.indexOf("{") == -1)
{
errorf("Expected JSON object on stdout from nix-eval-jobs, got: `%s`", line);
continue;
}
errorf("Command `%s` failed with error:\n---\n%s\n---", commandString, msg);
}

const errorsReported = pipes.stdout.byLine.fold!((errorsReported, line) {
auto json = parseJSON(line);

if (auto err = "error" in json)
{
logError((*err).str);
continue; // drain the output
return true;
}

Package pkg = json.packageFromNixEvalJobsJson(
Expand All @@ -364,17 +363,19 @@ Package[] nixEvalJobs(string flakeAttrPrefix, string cachixUrl, bool doCheck = t
attr: pkg.attrPath,
output: pkg.output
).writeRecordAsTable(stderr.lockingTextWriter);
}
foreach (line; pipes.stderr.byLine)
{
if (uselessWarnings.map!((warning) => line.indexOf(warning) != -1).any)
continue;

logError(line.idup);
}
return errorsReported;
})(false);

const stderrLogs = pipes.stderr.byLine
.filter!(line => !uselessWarnings.canFind(line))
.join("\n");

logWarning(stderrLogs);

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

enforce(status == 0 && !errorsReported, "Command `%s` failed with status %s".fmt(commandString, status));

return result;
}
Expand Down