Skip to content

Commit

Permalink
test(mcl): run nix tests in seperate ci workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
monyarm committed Apr 19, 2024
1 parent af307ba commit b81bf09
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 19 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ jobs:
run: |
set -euo pipefail
nix run github:Mic92/nix-fast-build -- --debug --systems ${{ matrix.system }} --skip-cached --no-nom --flake '.#${{ matrix.attrPath }}' 3>&1 1>&2 2>&3 3>&- | grep --color=always -v "warning: Git tree" | grep --color=always -v "warning: unknown setting" | grep --color=always -v "error (ignored): error: SQLite database"
results:
runs-on: ubuntu-latest
name: Final Results
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/mcl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: "MCL"

on:
workflow_dispatch:
merge_group:
push:
branches:
- main
pull_request:
branches:
- main
workflow_call:

concurrency:
group: ${{ github.workflow }}-${{ github.repository }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
mcl-test:
runs-on: ubuntu-latest
name: Build and test MCL
steps:
- uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v9
with:
extra-conf: accept-flake-config = true
nix-installer-tag: v0.15.1

- uses: cachix/cachix-action@v14
with:
name: ${{ vars.CACHIX_CACHE }}
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
extraPullNames: ${{ vars.EXTRA_CACHIX_CACHES }}

- name: Build and test MCL
run: |
set -euo pipefail
nix build .#mcl
5 changes: 3 additions & 2 deletions packages/mcl/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ in
version = "unstable";
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.fileFilter (file: builtins.any file.hasExt ["d" "sdl" "json"]) ./.;
fileset = lib.fileset.fileFilter (file: builtins.any file.hasExt ["d" "sdl" "json" "nix"]) ./.;
};

nativeBuildInputs = [pkgs.makeWrapper] ++ deps;
Expand All @@ -22,7 +22,8 @@ in
postFixup = ''
wrapProgram $out/bin/${pname} --set PATH ${lib.makeBinPath deps}
'';
dubTestFlags = ["--" "-e" "(nix\\.(build|eval|run)\\!JSONValue)|(nix\\.(build|eval|run))|fetchJson"];

dubTestFlags = ["--" "-e" "(nix\\.(build|run)\\!JSONValue)|(nix\\.(build|run))|fetchJson"];

meta.mainProgram = pname;
}
1 change: 1 addition & 0 deletions packages/mcl/dub.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ targetPath "build"
dflags "-preview=shortenedMethods"
dflags "-defaultlib=libphobos2.so" platform="dmd"
lflags "-fuse-ld=gold" platform="dmd"
libs "curl"
1 change: 1 addition & 0 deletions packages/mcl/src/src/mcl/commands/ci_matrix.d
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export void print_table()
{
params = parseEnv!Params;

createResultDirs();
Package[] precalcMatrix = getPrecalcMatrix();
auto checkedPackages = precalcMatrix.map!(checkPackage).array;
printTableForCacheStatus(checkedPackages);
Expand Down
26 changes: 11 additions & 15 deletions packages/mcl/src/src/mcl/utils/nix.d
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ struct NixCommand
version (unittest)
{
auto command = [
"nix", "--experimental-features", "nix-command", commandName,
"nix", "--experimental-features", "nix-command flakes",
commandName,
(isJSON ? "--json" : "")
] ~ args ~ path;
}
Expand Down Expand Up @@ -112,7 +113,7 @@ unittest

auto p = __FILE__.absolutePath.dirName;

string output = nix().run(p ~ "/test/test.nix", ["--file"]);
string output = nix().run(p ~ "/test/test.nix", [ "--file"]);
assert(output == "Hello World");
}

Expand All @@ -133,17 +134,12 @@ unittest
@("nix.eval!JSONValue")
unittest
{
auto result = nix.eval!JSONValue(".#mcl.meta");
result["position"] = JSONValue("N/A");
assert(result == JSONValue([
"available": JSONValue(true),
"broken": JSONValue(false),
"insecure": JSONValue(false),
"mainProgram": JSONValue("mcl"),
"name": JSONValue("mcl"),
"outputsToInstall": JSONValue(["out"]),
"position": JSONValue("N/A"),
"unfree": JSONValue(false),
"unsupported": JSONValue(false)
]));
import std.file : readText;
import std.path : absolutePath, dirName;
import std.json : parseJSON;

auto p = __FILE__.absolutePath.dirName;

auto result = nix().eval!JSONValue(p ~ "/test/eval.nix", ["--file"]);
assert(result == ((p ~ "/test/eval.json").readText.parseJSON));
}
33 changes: 33 additions & 0 deletions packages/mcl/src/src/mcl/utils/test/eval.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "../../books-schema.json",
"sources": [
"https://middle-earth.xenite.org/what-are-the-various-books-named-in-the-lord-of-the-rings/"
],
"books": [{
"title": "The Red Book of Westmarch",
"author": "Bilbo/Frodo/Sam",
"category": []
},
{
"title": "Herblore of the Shire ",
"author": "Meriadoc Brandybuck, Master of Buckland",
"category": []
},
{
"title": "Reckoning of Years",
"author": "Meriadoc Brandybuck, Master of Buckland",
"category": [
"Scholarly"
]
},
{
"title": "The Tale of Years",
"category": []
},
{
"title": "The Book of Mazarbul",
"author": "Ori",
"category": []
}
]
}
30 changes: 30 additions & 0 deletions packages/mcl/src/src/mcl/utils/test/eval.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema" = "../../books-schema.json";
books = [
{
author = "Bilbo/Frodo/Sam";
category = [];
title = "The Red Book of Westmarch";
}
{
author = "Meriadoc Brandybuck, Master of Buckland";
category = [];
title = "Herblore of the Shire ";
}
{
author = "Meriadoc Brandybuck, Master of Buckland";
category = ["Scholarly"];
title = "Reckoning of Years";
}
{
category = [];
title = "The Tale of Years";
}
{
author = "Ori";
category = [];
title = "The Book of Mazarbul";
}
];
sources = ["https://middle-earth.xenite.org/what-are-the-various-books-named-in-the-lord-of-the-rings/"];
}
2 changes: 1 addition & 1 deletion packages/mcl/src/src/mcl/utils/test/test.nix
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
with import <nixpkgs> {};
pkgs.writeShellScriptBin "helloWorld" "echo Hello World"
writeShellScriptBin "helloWorld" "echo Hello World"

0 comments on commit b81bf09

Please sign in to comment.