diff --git a/default.nix b/default.nix index b5e217f7659..ba9601a3e08 100644 --- a/default.nix +++ b/default.nix @@ -172,6 +172,7 @@ let stylishHaskell = pkgs.callPackage ./scripts/test/stylish.nix { inherit (cardanoPkgs) stylish-haskell; inherit src localLib; }; walletIntegration = pkgs.callPackage ./scripts/test/wallet/integration/build-test.nix { inherit walletIntegrationTests; }; swaggerSchemaValidation = pkgs.callPackage ./scripts/test/wallet/swaggerSchemaValidation.nix { inherit gitrev; }; + yamlValidation = pkgs.callPackage ./scripts/test/yamlValidation.nix { inherit cardanoPkgs; inherit (localLib) runHaskell; }; }; cardano-sl-explorer-frontend = (import ./explorer/frontend { inherit system config gitrev pkgs; diff --git a/lib.nix b/lib.nix index 3208e9c47ab..0ec489783be 100644 --- a/lib.nix +++ b/lib.nix @@ -82,4 +82,14 @@ in lib // (rec { forEnvironments = f: lib.mapAttrs' (name: env: lib.nameValuePair env.attr (f (env // { environment = name; }))) (lib.filterAttrs (name: env: !env.private) environments); + + runHaskell = name: hspkgs: deps: env: code: let + ghc = hspkgs.ghcWithPackages deps; + builtBinary = pkgs.runCommand "${name}-binary" { buildInputs = [ ghc ]; } '' + mkdir -p $out/bin/ + ghc ${pkgs.writeText "${name}.hs" code} -o $out/bin/${name} + ''; + in pkgs.runCommand name env '' + ${builtBinary}/bin/$name + ''; }) diff --git a/log-configs/template-demo.yaml b/log-configs/template-demo.yaml index b12bac2c694..1884068c7fd 100644 --- a/log-configs/template-demo.yaml +++ b/log-configs/template-demo.yaml @@ -5,10 +5,10 @@ rotation: keepFiles: 20 loggerTree: severity: Debug+ - file: {{file}} + file: tmpFileName handlers: - { name: "json" - , filepath: "{{file}}.json" + , filepath: "tmpFileName.json" , logsafety: PublicLogLevel , severity: Debug , backend: FileJsonBE } diff --git a/scripts/common-functions.sh b/scripts/common-functions.sh index 8edf9ab5327..46031af13da 100644 --- a/scripts/common-functions.sh +++ b/scripts/common-functions.sh @@ -65,8 +65,8 @@ function logs { local conf_file="$conf_dir/$log_file.yaml" # log files are named under the $logs_dir directory - # sed "s|{{file}}|$logs_dir/$log_file|g" "$template" > "$conf_file" - sed "s|{{file}}|$log_file|g" "$template" > "$conf_file" + # sed "s|tmpFileName|$logs_dir/$log_file|g" "$template" > "$conf_file" + sed "s|tmpFileName|$log_file|g" "$template" > "$conf_file" echo -n " --json-log=$logs_dir/logs/node$i.json " echo -n " --logs-prefix $logs_dir/logs --log-config $conf_file " } diff --git a/scripts/test/yamlValidation.nix b/scripts/test/yamlValidation.nix new file mode 100644 index 00000000000..79bf6036e09 --- /dev/null +++ b/scripts/test/yamlValidation.nix @@ -0,0 +1,56 @@ +{ runHaskell, cardanoPkgs }: + +runHaskell "yamlValidation" cardanoPkgs (ps: with ps; [ + cardano-sl-util + cardano-sl-infra + split +]) { + logConfigs = [ + ../../log-configs/daedalus.yaml + #../../log-configs/greppable.yaml + ../../log-configs/connect-to-cluster.yaml + ../../log-configs/cluster.yaml + ../../log-configs/template-demo.yaml + ]; + topologyConfigs = [ + ../../docs/network/example-topologies/mainnet-staging.yaml + ../../docs/network/example-topologies/behind-nat-no-dns.yaml + ../../docs/network/example-topologies/behind-nat-with-dns.yaml + ../../docs/network/example-topologies/p2p.yaml + ../../docs/network/example-topologies/static-no-dns.yaml + ../../docs/network/example-topologies/static-with-dns.yaml + ../../docs/network/example-topologies/traditional.yaml + ]; +} '' + import Pos.Util.Log.LoggerConfig (LoggerConfig) + import Pos.Infra.Network.Yaml (Topology) + import Data.List.Split + import System.Environment + import Data.Yaml + import Control.Monad.Catch + import Data.Monoid + + main :: IO () + main = do + runTest "logConfigs" checkLogConfig + runTest "topologyConfigs" checkTopology + outpath <- getEnv "out" + writeFile outpath "done" + + runTest :: FromJSON a => String -> (String -> IO a) -> IO () + runTest var func = do + paths <- getEnv var + let + pathList = splitOn " " paths + doTest path = do + putStrLn $ "testing: " <> path + func path + mapM_ doTest pathList + + checkLogConfig :: String -> IO LoggerConfig + checkLogConfig path = do + either throwM return =<< decodeFileEither path + + checkTopology :: String -> IO Topology + checkTopology path = either throwM return =<< decodeFileEither path +''