Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
monyarm committed Jul 29, 2024
1 parent 9cde0cb commit a1c5537
Show file tree
Hide file tree
Showing 17 changed files with 914 additions and 705 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
25 changes: 13 additions & 12 deletions packages/mcl/src/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ int main(string[] args)

setLogLevel(logLevel);

try switch (args[1])
try
switch (args[1])
{
default:
return wrongUsage("unknown command: `" ~ args[1] ~ "`");
default:
return wrongUsage("unknown command: `" ~ args[1] ~ "`");

static foreach (cmd; supportedCommands)
case __traits(identifier, cmd):
{
case __traits(identifier, cmd):
{

info("Running ", __traits(identifier, cmd));
cmd();
info("Execution Succesfull");
return 0;

}
info("Running ", __traits(identifier, cmd));
cmd();
info("Execution Succesfull");
return 0;
}
}
catch (Exception e)
{
Expand All @@ -53,8 +53,9 @@ int main(string[] args)
void setLogLevel(LogLevel l)
{
import std.logger : globalLogLevel, sharedLog;

globalLogLevel = l;
(cast()sharedLog()).logLevel = l;
(cast() sharedLog()).logLevel = l;
}

int wrongUsage(string error)
Expand Down
107 changes: 54 additions & 53 deletions packages/mcl/src/src/mcl/commands/ci.d
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module mcl.commands.ci;

import std.file : readText;
import std.json : parseJSON,JSONValue;
import std.stdio : writeln,write;
import std.algorithm : map;
import std.json : parseJSON, JSONValue;
import std.stdio : writeln, write;
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,58 +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 a1c5537

Please sign in to comment.