Skip to content

Commit

Permalink
fix(mcl.commands.ci_matrix): Centralize initialization of Parms struct
Browse files Browse the repository at this point in the history
  • Loading branch information
PetarKirov committed Aug 14, 2024
1 parent b25f308 commit a6e265a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
40 changes: 24 additions & 16 deletions packages/mcl/src/src/mcl/commands/ci_matrix.d
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,15 @@ version (unittest)
];
}

Params params;
immutable Params params;

export void ci_matrix()
shared static this()
{
params = parseEnv!Params;
}

export void ci_matrix()
{
createResultDirs();
nixEvalForAllSystems().array.printTableForCacheStatus();
}
Expand Down Expand Up @@ -184,7 +187,6 @@ Package[] checkCacheStatus(Package[] packages)

export void print_table()
{
params = parseEnv!Params;
createResultDirs();

getPrecalcMatrix()
Expand All @@ -194,7 +196,7 @@ export void print_table()

struct Params
{
@optional() string flakePre;
@optional() string flakePre = "checks";
@optional() string flakePost;
@optional() string precalcMatrix;
@optional() int maxWorkers;
Expand Down Expand Up @@ -393,9 +395,6 @@ SupportedSystem[] getSupportedSystems(string flakeRef = ".")

Package[] nixEvalForAllSystems()
{
if (params.flakePre == "")
params.flakePre = "checks";

const cachixUrl = "https://" ~ params.cachixCache ~ ".cachix.org";
const systems = getSupportedSystems();

Expand Down Expand Up @@ -536,15 +535,15 @@ unittest
}
}

string getStatus(JSONValue pkg, string key)
string getStatus(JSONValue pkg, string key, bool isInitial)
{
if (key in pkg)
{
if (pkg[key]["isCached"].boolean)
{
return "[✅ cached](" ~ pkg[key]["cacheUrl"].str ~ ")";
}
else if (params.isInitial)
else if (isInitial)
{
return "⏳ building...";
}
Expand All @@ -559,7 +558,10 @@ string getStatus(JSONValue pkg, string key)
}
}

SummaryTableEntry[] convertNixEvalToTableSummary(Package[] packages)
SummaryTableEntry[] convertNixEvalToTableSummary(
const Package[] packages,
bool isInitial
)
{

SummaryTableEntry[] tableSummary = packages
Expand All @@ -574,9 +576,10 @@ SummaryTableEntry[] convertNixEvalToTableSummary(Package[] packages)
}
SummaryTableEntry entry = {
name, {
getStatus(pkg, "x86_64_linux"), getStatus(pkg, "x86_64_darwin")
getStatus(pkg, "x86_64_linux", isInitial),
getStatus(pkg, "x86_64_darwin", isInitial)
}, {
getStatus(pkg, "aarch64_darwin")
getStatus(pkg, "aarch64_darwin", isInitial)
}
};
return entry;
Expand All @@ -590,7 +593,10 @@ SummaryTableEntry[] convertNixEvalToTableSummary(Package[] packages)
@("convertNixEvalToTableSummary/getStatus")
unittest
{
auto tableSummary = convertNixEvalToTableSummary(cast(Package[]) testPackageArray);
auto tableSummary = convertNixEvalToTableSummary(
testPackageArray,
isInitial: false
);
assert(tableSummary[0].name == testPackageArray[0].name);
assert(tableSummary[0].x86_64.linux == "[✅ cached](https://testPackage.com)");
assert(tableSummary[0].x86_64.darwin == "🚫 not supported");
Expand All @@ -600,9 +606,11 @@ unittest
assert(tableSummary[1].x86_64.darwin == "🚫 not supported");
assert(tableSummary[1].aarch64.darwin == "❌ build failed");

params.isInitial = true;
tableSummary = convertNixEvalToTableSummary(cast(Package[]) testPackageArray);
params.isInitial = false;
tableSummary = convertNixEvalToTableSummary(
testPackageArray,
isInitial: true
);
testPackageArray, isInitial: true);
assert(tableSummary[0].name == testPackageArray[0].name);
assert(tableSummary[0].x86_64.linux == "[✅ cached](https://testPackage.com)");
assert(tableSummary[0].x86_64.darwin == "🚫 not supported");
Expand Down
2 changes: 0 additions & 2 deletions packages/mcl/src/src/mcl/commands/deploy_spec.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ export void deploy_spec()
{
const deploySpecFile = resultDir.buildPath("cachix-deploy-spec.json");

params = parseEnv!Params;

if (!exists(deploySpecFile))
{
auto nixosConfigs = flakeAttr("legacyPackages", SupportedSystem.x86_64_linux, "bareMetalMachines")
Expand Down

0 comments on commit a6e265a

Please sign in to comment.