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 ab7dfe5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
42 changes: 25 additions & 17 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,16 @@ version (unittest)
];
}

Params params;
immutable Params params;

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

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

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

getPrecalcMatrix()
Expand All @@ -194,7 +197,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 +396,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 +536,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 +559,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 +577,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 +594,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 +607,10 @@ 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
);
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 @@ -621,7 +629,7 @@ void printTableForCacheStatus(Package[] packages)
saveGHCIMatrix(packages);
}
saveCachixDeploySpec(packages);
saveGHCIComment(convertNixEvalToTableSummary(packages));
saveGHCIComment(convertNixEvalToTableSummary(packages, params.isInitial));
}

Package checkPackage(Package pkg)
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 ab7dfe5

Please sign in to comment.