11module mcl.commands.ci ;
22
33import std.file : readText;
4- import std.json : parseJSON,JSONValue;
5- import std.stdio : writeln,write;
6- import std.algorithm : map;
4+ import std.json : parseJSON, JSONValue;
5+ import std.stdio : writeln, write;
6+ import std.algorithm : map, each ;
77import std.array : array, join;
88import std.conv : to;
99import std.process : ProcessPipes;
1010
1111import mcl.utils.env : optional, parseEnv;
12- import mcl.commands.ci_matrix: nixEvalJobs, SupportedSystem, Params;
13- import mcl.commands.shard_matrix: generateShardMatrix;
12+ import mcl.commands.ci_matrix : nixEvalJobs, SupportedSystem, Params, Package ;
13+ import mcl.commands.shard_matrix : generateShardMatrix, Shard ;
1414import mcl.utils.path : rootDir, createResultDirs;
1515import mcl.utils.process : execute;
1616import mcl.utils.nix : nix;
@@ -23,58 +23,59 @@ export void ci()
2323 params = parseEnv! Params;
2424
2525 auto shardMatrix = generateShardMatrix();
26- foreach (shard; shardMatrix.include)
27- {
28- writeln(" Shard " , shard.prefix ~ " " , shard.postfix ~ " " , shard.digit);
29- params.flakePre = shard.prefix;
30- params.flakePost = shard.postfix;
26+ shardMatrix.include.each! (handleShard);
27+ }
3128
32- if (params.flakePre == " " )
33- {
34- params.flakePre = " checks" ;
35- }
36- if (params.flakePost != " " )
37- {
38- params.flakePost = " ." ~ params.flakePost;
39- }
40- string cachixUrl = " https://" ~ params.cachixCache ~ " .cachix.org" ;
41- version (AArch64 ) {
42- string arch = " aarch64" ;
43- }
44- version (X86_64 ) {
45- string arch = " x86_64" ;
46- }
29+ static immutable (SupportedSystem) platform ()
30+ {
31+ version (AArch64 )
32+ static immutable string arch = " aarch64" ;
33+ else version (X86_64 )
34+ static immutable string arch = " x86_64" ;
4735
48- version (linux ) {
49- string os = " linux" ;
50- }
51- version (OSX ) {
52- string os = " darwin" ;
53- }
36+ version (linux )
37+ static immutable string os = " linux" ;
38+ else version (OSX )
39+ static immutable string os = " darwin" ;
5440
55- auto matrix = nixEvalJobs(params, (arch ~ " _" ~ os).to! (SupportedSystem), cachixUrl, false );
56- foreach (pkg; matrix)
57- {
58- if (pkg.isCached)
59- {
60- writeln(" Package " , pkg.name, " is cached" );
61- }
62- else
63- {
64- writeln(" Package " , pkg.name, " is not cached; building..." );
65- ProcessPipes res = execute! ProcessPipes([" nix" , " build" , " --json" , " .#" ~ pkg.attrPath]);
41+ return (arch ~ " _" ~ os).to! (SupportedSystem);
42+ }
6643
67- foreach (line; res.stderr.byLine)
68- {
69- " \r " .write;
70- line.write;
71- }
72- " " .writeln;
73- auto json = parseJSON(res.stdout.byLine.join(" \n " ).to! string );
74- auto path = json.array[0 ][" outputs" ][" out" ].str;
75- execute([" cachix" , " push" , params.cachixCache, path], false , true ).writeln;
76- }
77- }
44+ void handleShard (Shard shard)
45+ {
46+ writeln(" Shard " , shard.prefix ~ " " , shard.postfix ~ " " , shard.digit);
47+ params.flakePre = shard.prefix;
48+ params.flakePost = shard.postfix;
49+
50+ if (params.flakePre == " " )
51+ params.flakePre = " checks" ;
52+ if (params.flakePost != " " )
53+ params.flakePost = " ." ~ params.flakePost;
54+ string cachixUrl = " https://" ~ params.cachixCache ~ " .cachix.org" ;
55+
56+ auto matrix = nixEvalJobs(params, platform, cachixUrl, false );
57+ matrix.each! (handlePackage);
58+ }
7859
60+ void handlePackage (Package pkg)
61+ {
62+ if (pkg.isCached)
63+ writeln(" Package " , pkg.name, " is cached" );
64+ else
65+ {
66+ writeln(" Package " , pkg.name, " is not cached; building..." );
67+ ProcessPipes res = execute! ProcessPipes([
68+ " nix" , " build" , " --json" , " .#" ~ pkg.attrPath
69+ ]);
70+
71+ foreach (line; res.stderr.byLine)
72+ {
73+ " \r " .write;
74+ line.write;
75+ }
76+ " " .writeln;
77+ auto json = parseJSON(res.stdout.byLine.join(" \n " ).to! string );
78+ auto path = json.array[0 ][" outputs" ][" out" ].str;
79+ execute([" cachix" , " push" , params.cachixCache, path], false , true ).writeln;
7980 }
8081}
0 commit comments