Skip to content

Commit 78f71d4

Browse files
committed
fix(mcl/ci_matrix): Re-implement and fix checkPackage
To correctly pass auth token to private cachix caches.
1 parent a30a831 commit 78f71d4

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

packages/mcl/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
lib.concatStringsSep "|" [
3131
"(nix\\.(build|run))"
3232
"fetchJson|(coda\.)"
33+
"checkPackage"
3334
]
3435
);
3536
in

packages/mcl/src/src/mcl/commands/ci_matrix.d

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -511,21 +511,47 @@ void printTableForCacheStatus(Package[] packages)
511511

512512
Package checkPackage(Package pkg)
513513
{
514-
string curlOutput = execute([
515-
"curl", "--silent", "-H",
516-
"Authorization: Bearer " ~ params.cachixAuthToken, "-I",
517-
pkg.cacheUrl
518-
], false);
519-
bool isAvailable = curlOutput
520-
.split("\n")
521-
.filter!(line => line.startsWith("HTTP"))
522-
.map!(line => line.split(" ")[1])
523-
.map!(code => code == "200")
524-
.any;
525-
pkg.isCached = isAvailable;
514+
import std.algorithm : canFind;
515+
import std.string : lineSplitter;
516+
import std.net.curl : HTTP, httpGet = get, HTTPStatusException;
517+
518+
auto http = HTTP();
519+
http.addRequestHeader("Authorization", "Bearer " ~ params.cachixAuthToken);
520+
521+
try
522+
{
523+
pkg.isCached = httpGet(pkg.cacheUrl, http)
524+
.lineSplitter
525+
.canFind("StorePath: " ~ pkg.output);
526+
}
527+
catch (HTTPStatusException e)
528+
{
529+
pkg.isCached = false;
530+
}
531+
526532
return pkg;
527533
}
528534

535+
@("checkPackage")
536+
unittest
537+
{
538+
const nixosCacheEndpoint = "https://cache.nixos.org/";
539+
const storePathHash = "mdb034kf7sq6g03ric56jxr4a7043l41";
540+
const storePath = "/nix/store/" ~ storePathHash ~ "-hello-2.12.1";
541+
542+
auto testPackage = Package(
543+
output: storePath,
544+
cacheUrl: nixosCacheEndpoint ~ storePathHash ~ ".narinfo",
545+
);
546+
547+
assert(!testPackage.isCached);
548+
assert(checkPackage(testPackage).isCached);
549+
550+
testPackage.cacheUrl = nixosCacheEndpoint ~ "nonexistent.narinfo";
551+
552+
assert(!checkPackage(testPackage).isCached);
553+
}
554+
529555
Package[] getPrecalcMatrix()
530556
{
531557
auto precalcMatrixStr = params.precalcMatrix == "" ? "{\"include\": []}" : params.precalcMatrix;

0 commit comments

Comments
 (0)