@@ -3,14 +3,14 @@ module mcl.commands.ci;
33import std.file : readText;
44import std.json : parseJSON, JSONValue;
55import std.stdio : writeln, write;
6- import std.algorithm : map;
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,64 +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- {
43- string arch = " aarch64" ;
44- }
45- version (X86_64 )
46- {
47- string arch = " x86_64" ;
48- }
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" ;
4935
50- version (linux )
51- {
52- string os = " linux" ;
53- }
54- version (OSX )
55- {
56- string os = " darwin" ;
57- }
36+ version (linux )
37+ static immutable string os = " linux" ;
38+ else version (OSX )
39+ static immutable string os = " darwin" ;
5840
59- auto matrix = nixEvalJobs(params, (arch ~ " _" ~ os).to! (SupportedSystem), cachixUrl, false );
60- foreach (pkg; matrix)
61- {
62- if (pkg.isCached)
63- {
64- writeln(" Package " , pkg.name, " is cached" );
65- }
66- else
67- {
68- writeln(" Package " , pkg.name, " is not cached; building..." );
69- ProcessPipes res = execute! ProcessPipes([
70- " nix" , " build" , " --json" , " .#" ~ pkg.attrPath
71- ]);
41+ return (arch ~ " _" ~ os).to! (SupportedSystem);
42+ }
7243
73- foreach (line; res.stderr.byLine )
74- {
75- " \r " .write ;
76- line.write ;
77- }
78- " " .writeln;
79- auto json = parseJSON(res.stdout.byLine.join( " \n " ).to ! string );
80- auto path = json.array[ 0 ][ " outputs " ][ " out " ].str ;
81- execute([ " cachix " , " push " , params.cachixCache, path], false , true ).writeln;
82- }
83- }
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 " ;
8455
56+ auto matrix = nixEvalJobs(params, platform, cachixUrl, false );
57+ matrix.each! (handlePackage);
58+ }
59+
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;
8580 }
8681}
0 commit comments