Skip to content

Commit

Permalink
refactor(mcl/utils/json): Refactor and format
Browse files Browse the repository at this point in the history
  • Loading branch information
monyarm committed Aug 8, 2024
1 parent e578c45 commit 879078e
Show file tree
Hide file tree
Showing 14 changed files with 630 additions and 614 deletions.
14 changes: 7 additions & 7 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
};

dlang-nix = {
url = "github:PetarKirov/dlang.nix?branch=feat/build-dub-package&rev=dab4c199ad644dc23b0b9481e2e5a063e9492b84";
url = "github:PetarKirov/dlang.nix?branch=feat/build-dub-package&rev=21b1b3b18b3b635a43b319612aff529d26b1863b";
inputs = {
flake-compat.follows = "flake-compat";
flake-parts.follows = "flake-parts";
Expand Down
1 change: 0 additions & 1 deletion packages/mcl/src/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ int main(string[] args)
cmd();
info("Execution Succesfull");
return 0;

}
}
catch (Exception e)
Expand Down
109 changes: 52 additions & 57 deletions packages/mcl/src/src/mcl/commands/ci.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ module mcl.commands.ci;
import std.file : readText;
import std.json : parseJSON, JSONValue;
import std.stdio : writeln, write;
import std.algorithm : map;
import std.algorithm : map, each;
import std.array : array, join;
import std.conv : to;
import std.process : ProcessPipes;

import mcl.utils.env : optional, parseEnv;
import mcl.commands.ci_matrix : nixEvalJobs, SupportedSystem, Params;
import mcl.commands.shard_matrix : generateShardMatrix;
import mcl.commands.ci_matrix : nixEvalJobs, SupportedSystem, Params, Package;
import mcl.commands.shard_matrix : generateShardMatrix, Shard;
import mcl.utils.path : rootDir, createResultDirs;
import mcl.utils.process : execute;
import mcl.utils.nix : nix;
Expand All @@ -23,64 +23,59 @@ export void ci()
params = parseEnv!Params;

auto shardMatrix = generateShardMatrix();
foreach (shard; shardMatrix.include)
{
writeln("Shard ", shard.prefix ~ " ", shard.postfix ~ " ", shard.digit);
params.flakePre = shard.prefix;
params.flakePost = shard.postfix;
shardMatrix.include.each!(handleShard);
}

if (params.flakePre == "")
{
params.flakePre = "checks";
}
if (params.flakePost != "")
{
params.flakePost = "." ~ params.flakePost;
}
string cachixUrl = "https://" ~ params.cachixCache ~ ".cachix.org";
version (AArch64)
{
string arch = "aarch64";
}
version (X86_64)
{
string arch = "x86_64";
}
static immutable(SupportedSystem) platform()
{
version (AArch64)
static immutable string arch = "aarch64";
else version (X86_64)
static immutable string arch = "x86_64";

version (linux)
{
string os = "linux";
}
version (OSX)
{
string os = "darwin";
}
version (linux)
static immutable string os = "linux";
else version (OSX)
static immutable string os = "darwin";

auto matrix = nixEvalJobs(params, (arch ~ "_" ~ os).to!(SupportedSystem), cachixUrl, false);
foreach (pkg; matrix)
{
if (pkg.isCached)
{
writeln("Package ", pkg.name, " is cached");
}
else
{
writeln("Package ", pkg.name, " is not cached; building...");
ProcessPipes res = execute!ProcessPipes([
"nix", "build", "--json", ".#" ~ pkg.attrPath
]);
return (arch ~ "_" ~ os).to!(SupportedSystem);
}

foreach (line; res.stderr.byLine)
{
"\r".write;
line.write;
}
"".writeln;
auto json = parseJSON(res.stdout.byLine.join("\n").to!string);
auto path = json.array[0]["outputs"]["out"].str;
execute(["cachix", "push", params.cachixCache, path], false, true).writeln;
}
}
void handleShard(Shard shard)
{
writeln("Shard ", shard.prefix ~ " ", shard.postfix ~ " ", shard.digit);
params.flakePre = shard.prefix;
params.flakePost = shard.postfix;

if (params.flakePre == "")
params.flakePre = "checks";
if (params.flakePost != "")
params.flakePost = "." ~ params.flakePost;
string cachixUrl = "https://" ~ params.cachixCache ~ ".cachix.org";

auto matrix = nixEvalJobs(params, platform, cachixUrl, false);
matrix.each!(handlePackage);
}

void handlePackage(Package pkg)
{
if (pkg.isCached)
writeln("Package ", pkg.name, " is cached");
else
{
writeln("Package ", pkg.name, " is not cached; building...");
ProcessPipes res = execute!ProcessPipes([
"nix", "build", "--json", ".#" ~ pkg.attrPath
]);

foreach (line; res.stderr.byLine)
{
"\r".write;
line.write;
}
"".writeln;
auto json = parseJSON(res.stdout.byLine.join("\n").to!string);
auto path = json.array[0]["outputs"]["out"].str;
execute(["cachix", "push", params.cachixCache, path], false, true).writeln;
}
}
Loading

0 comments on commit 879078e

Please sign in to comment.