2024-06-26 13:16:20 +00:00
|
|
|
{ self, ... }:
|
2024-06-15 11:41:51 +00:00
|
|
|
{
|
2024-06-26 13:16:20 +00:00
|
|
|
|
|
|
|
flake.inventory = import ./example.nix { inherit self; };
|
2024-06-15 11:41:51 +00:00
|
|
|
perSystem =
|
|
|
|
{ pkgs, config, ... }:
|
|
|
|
{
|
2024-06-26 13:16:20 +00:00
|
|
|
devShells.inventory-schema = pkgs.mkShell {
|
|
|
|
inputsFrom = [ config.checks.inventory-schema-checks ];
|
2024-06-15 11:41:51 +00:00
|
|
|
};
|
2024-06-19 14:56:26 +00:00
|
|
|
|
2024-06-15 11:41:51 +00:00
|
|
|
checks.inventory-schema-checks = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "inventory-schema-checks";
|
2024-06-26 13:16:20 +00:00
|
|
|
src = ./.;
|
2024-06-15 11:41:51 +00:00
|
|
|
buildInputs = [ pkgs.cue ];
|
|
|
|
buildPhase = ''
|
|
|
|
echo "Running inventory tests..."
|
2024-06-26 13:16:20 +00:00
|
|
|
# Cue is easier to run in the same directory as the schema
|
|
|
|
cd spec
|
2024-06-15 11:41:51 +00:00
|
|
|
|
|
|
|
echo "Export cue as json-schema..."
|
|
|
|
cue export --out openapi root.cue
|
|
|
|
|
|
|
|
echo "Validate test/*.json against inventory-schema..."
|
|
|
|
|
2024-06-26 13:16:20 +00:00
|
|
|
test_dir="../examples"
|
2024-06-15 11:41:51 +00:00
|
|
|
for file in "$test_dir"/*; do
|
|
|
|
# Check if the item is a file
|
|
|
|
if [ -f "$file" ]; then
|
|
|
|
# Print the filename
|
|
|
|
echo "Running test on: $file"
|
|
|
|
|
|
|
|
# Run the cue vet command
|
|
|
|
cue vet "$file" root.cue -d "#Root"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
touch $out
|
|
|
|
'';
|
|
|
|
};
|
2024-06-15 11:41:51 +00:00
|
|
|
};
|
|
|
|
}
|