@@ -3,7 +3,7 @@ module mcl.commands.ci_matrix;
33import std.stdio : writeln, stderr, stdout;
44import std.traits : EnumMembers;
55import std.string : indexOf, splitLines;
6- import std.algorithm : map, filter, reduce, chunkBy, find, any, sort, startsWith, each;
6+ import std.algorithm : map, filter, reduce, chunkBy, find, any, sort, startsWith, each, canFind ;
77import std.file : write, readText;
88import std.range : array, front, join, split;
99import std.conv : to;
@@ -14,7 +14,7 @@ import std.path : buildPath;
1414import std.process : pipeProcess, wait, Redirect, kill;
1515import std.exception : enforce;
1616import std.format : fmt = format;
17- import std.logger : tracef, infof, errorf;
17+ import std.logger : tracef, infof, errorf, warningf ;
1818
1919import mcl.utils.env : optional, MissingEnvVarsException, parseEnv;
2020import mcl.utils.string : enumToString, StringRepresentation, MaxWidth, writeRecordAsTable;
@@ -318,29 +318,32 @@ Package[] nixEvalJobs(string flakeAttrPrefix, string cachixUrl, bool doCheck = t
318318 " --flake" , rootDir ~ " #" ~ flakeAttrPrefix
319319 ];
320320
321+ const commandString = args.join(" " );
322+
321323 tracef(" %-(%s %)" , args);
322324
323325 auto pipes = pipeProcess(args, Redirect.stdout | Redirect.stderr);
324326
327+ void logWarning (string errorMsg)
328+ {
329+ warningf(" Command `%s` stderr:\n ---\n %s\n ---" , commandString, errorMsg);
330+ }
331+
325332 void logError (string errorMsg)
326333 {
327- errorf(" Command `%s` failed with error:\n ---\n %s\n ---" ,
328- args, errorMsg);
334+ errorf(" Command `%s` failed with error:\n ---\n %s\n ---" , commandString, errorMsg);
329335 }
330336
337+ bool jobFailed = false ;
338+
331339 foreach (line; pipes.stdout.byLine)
332340 {
333- if (line.indexOf(" {" ) == - 1 )
334- {
335- errorf(" Expected JSON object on stdout from nix-eval-jobs, got: `%s`" , line);
336- continue ;
337- }
338-
339341 auto json = parseJSON(line);
340342
341343 if (auto err = " error" in json)
342344 {
343345 logError((* err).str);
346+ jobFailed = true ;
344347 continue ; // drain the output
345348 }
346349
@@ -365,16 +368,25 @@ Package[] nixEvalJobs(string flakeAttrPrefix, string cachixUrl, bool doCheck = t
365368 output: pkg.output
366369 ).writeRecordAsTable(stderr.lockingTextWriter);
367370 }
371+
372+ pipes.stderr.byLine
373+ .filter! (line => uselessWarnings.canFind(line))
374+ .join
375+ .writeln;
376+
377+ string bufferedOutput = " " ;
368378 foreach (line; pipes.stderr.byLine)
369379 {
370380 if (uselessWarnings.map! ((warning) => line.indexOf(warning) != - 1 ).any)
371381 continue ;
372382
373- logError( line.idup) ;
383+ bufferedOutput ~= line ~ " \n " ;
374384 }
375385
386+ logWarning(bufferedOutput);
387+
376388 int status = wait(pipes.pid);
377- enforce(status == 0 , " Command `%s` failed with status %s" .fmt(args, status));
389+ enforce(status == 0 && ! jobFailed , " Command `%s` failed with status %s" .fmt(args, status));
378390
379391 return result;
380392}
0 commit comments