diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 2942875d04b..b128c39aa81 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -4,11 +4,6 @@ steps: agents: system: x86_64-linux - - label: 'stylish-haskell' - command: 'scripts/ci/nix-shell.sh --run scripts/check-stylish.sh' - agents: - system: x86_64-linux - - label: 'stack2nix' command: 'scripts/ci/nix-shell.sh -p cabal2nix stack cabal-install ghc moreutils expect -Q -j 4 --run scripts/check-stack2nix.sh' agents: diff --git a/default.nix b/default.nix index 15e2c851b56..6416df93047 100644 --- a/default.nix +++ b/default.nix @@ -151,12 +151,17 @@ let in args: pkgs.callPackage ./scripts/launch/connect-to-cluster (args // { inherit gitrev; } // walletConfig ); other = rec { + walletIntegrationTests = pkgs.callPackage ./scripts/test/wallet/integration { inherit gitrev; }; validateJson = pkgs.callPackage ./tools/src/validate-json {}; demoCluster = pkgs.callPackage ./scripts/launch/demo-cluster { inherit gitrev; }; - shellcheckTests = pkgs.callPackage ./scripts/test/shellcheck.nix { src = ./.; }; - swaggerSchemaValidation = pkgs.callPackage ./scripts/test/wallet/swaggerSchemaValidation.nix { inherit gitrev; }; - walletIntegrationTests = pkgs.callPackage ./scripts/test/wallet/integration { inherit gitrev; }; - buildWalletIntegrationTests = pkgs.callPackage ./scripts/test/wallet/integration/build-test.nix { inherit walletIntegrationTests pkgs; }; + tests = { + shellcheck = pkgs.callPackage ./scripts/test/shellcheck.nix { src = ./.; }; + hlint = pkgs.callPackage ./scripts/test/hlint.nix { src = ./.; }; + stylishHaskell = pkgs.callPackage ./scripts/test/stylish.nix { src = ./.; stylish-haskell = cardanoPkgs.stylish-haskell; }; + buildWalletIntegration = pkgs.callPackage ./scripts/test/wallet/integration/build-test.nix { inherit walletIntegrationTests pkgs; }; + swaggerSchemaValidation = pkgs.callPackage ./scripts/test/wallet/swaggerSchemaValidation.nix { inherit gitrev; }; + }; + fixStylishHaskell = pkgs.callPackage ./scripts/haskell/stylish.nix { stylish-haskell = cardanoPkgs.stylish-haskell; }; cardano-sl-explorer-frontend = (import ./explorer/frontend { inherit system config gitrev pkgs; cardano-sl-explorer = cardanoPkgs.cardano-sl-explorer-static; diff --git a/release.nix b/release.nix index f41e7807c43..46f06a0db5a 100644 --- a/release.nix +++ b/release.nix @@ -60,9 +60,7 @@ let inherit (mapped'.connectScripts."${cluster}") wallet explorer; }; nixosTests = import ./nixos-tests; - shellcheckTests = iohkPkgs.shellcheckTests; - swaggerSchemaValidation = iohkPkgs.swaggerSchemaValidation; - walletIntegrationTests = iohkPkgs.buildWalletIntegrationTests; + tests = iohkPkgs.tests; makeRelease = cluster: { name = cluster; value = { @@ -71,7 +69,7 @@ let }; }; in mapped // { - inherit walletIntegrationTests swaggerSchemaValidation shellcheckTests; + inherit tests; nixpkgs = let wrapped = pkgs.runCommand "nixpkgs" {} '' ln -sv ${fixedNixpkgs} $out diff --git a/scripts/check-stylish.sh b/scripts/check-stylish.sh deleted file mode 100755 index 686cb1d35db..00000000000 --- a/scripts/check-stylish.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - -# check and warn if commits don't conform to stylish-haskell - -set -xe - -fail_stylish_check() { - git diff --text > /tmp/stylish.patch - buildkite-agent artifact upload /tmp/stylish.patch --job "$BUILDKITE_JOB_ID" - echo "ERROR: you need to (run ./scripts/haskell/stylish-last-10.sh or apply the patch in the buildkite artifact) and commit the changes" >&2 - exit 1 -} - -# Get relative path to script directory -haskellScriptDir=$(dirname -- "$(readlink -f -- "${BASH_SOURCE[0]}")")/haskell/ - -source "${haskellScriptDir}stylish-last-10.sh" - -git diff --text --exit-code || fail_stylish_check diff --git a/scripts/haskell/shell-with-stylish.nix b/scripts/haskell/shell-with-stylish.nix deleted file mode 100644 index cc2625e0229..00000000000 --- a/scripts/haskell/shell-with-stylish.nix +++ /dev/null @@ -1,4 +0,0 @@ -let - cardanoPkgs = import ../../. {}; - pkgs = import ((import ../../lib.nix).fetchNixPkgs) { }; -in pkgs.runCommand "name" { buildInputs = [ cardanoPkgs.stylish-haskell ]; } "" diff --git a/scripts/haskell/stylish-last-10.sh b/scripts/haskell/stylish-last-10.sh deleted file mode 100755 index 9672e7c5b30..00000000000 --- a/scripts/haskell/stylish-last-10.sh +++ /dev/null @@ -1,5 +0,0 @@ -nix-shell ${haskellScriptDir}shell-with-stylish.nix --run "\ - git diff --diff-filter=AMR --name-only -r HEAD~10 |\ - grep '.hs$' |\ - xargs -I '{}' realpath --relative-to=. $(git rev-parse --show-toplevel)/'{}' |\ - xargs -L 1 stylish-haskell -i" diff --git a/scripts/haskell/stylish.sh b/scripts/haskell/stylish.sh deleted file mode 100755 index 9c6548d2672..00000000000 --- a/scripts/haskell/stylish.sh +++ /dev/null @@ -1 +0,0 @@ -find . -type f -name "*hs" -not -path '.git' -not -path '*.stack-work*' -not -name 'HLint.hs' -exec stylish-haskell -i {} \; diff --git a/scripts/test/hlint.nix b/scripts/test/hlint.nix new file mode 100644 index 00000000000..8e9e6e533dc --- /dev/null +++ b/scripts/test/hlint.nix @@ -0,0 +1,36 @@ +{ runCommand, hlint, src, lib }: + +let + cleanSourceFilter = with lib; + name: type: let baseName = baseNameOf (toString name); in ( + (type == "regular" && hasSuffix ".hs" baseName) || + (type == "regular" && hasSuffix ".yaml" baseName) || + (type == "directory") + ); + src' = builtins.filterSource cleanSourceFilter src; +in +runCommand "cardano-hlint-check" { buildInputs = [ hlint ]; } '' + set +e + # Networking is not in here, because it has a very different codestyle (doesn't use universum). + # This is bad and should probably be fixed. + projects=("util" "binary" "crypto" "core" "db" "lrc" "infra" "ssc" "txp" "update" "delegation" "node" "tools" "client" "generator" "auxx" "explorer" "wallet" "wallet-new") + cd ${src'} + hlint lib/src lib/test lib/bench "''${projects[@]}" + EXIT_CODE=$? + if [[ $EXIT_CODE != 0 ]] + then + echo '=====================================================================' + echo 'Note: to ignore a particular hint (e.g. "Reduce duplication"), write' + echo 'this in the source file:' + tput bold + echo '{-# ANN module ("HLint: ignore Reduce duplication" :: Text) #-}' + tput sgr0 + echo 'You can also apply it just to a particular function, which is better:' + tput bold + echo '{-# ANN funcName ("HLint: ignore Reduce duplication" :: Text) #-}' + tput sgr0 + exit $EXIT_CODE + else + echo $EXIT_CODE > $out + fi +'' diff --git a/scripts/test/stylish.nix b/scripts/test/stylish.nix new file mode 100644 index 00000000000..4f5dcfed518 --- /dev/null +++ b/scripts/test/stylish.nix @@ -0,0 +1,34 @@ +{ runCommand, stylish-haskell, src, lib, git }: + +let + cleanSourceFilter = with lib; + name: type: let baseName = baseNameOf (toString name); in ( + (type == "regular" && hasSuffix ".hs" baseName) || + (type == "regular" && hasSuffix ".yaml" baseName) || + (type == "directory") + ); + src' = builtins.filterSource cleanSourceFilter src; +in +runCommand "cardano-stylish-check" { succeedOnFailure = true; buildInputs = [ stylish-haskell git ]; } '' + set +e + cp -a ${src'} tmp-cardano + chmod -R 0755 tmp-cardano + cd tmp-cardano + git init + git add -A + find . -type f -name "*hs" -not -path '.git' -not -path '*.stack-work*' -not -name 'HLint.hs' -exec stylish-haskell -i {} \; + git diff --exit-code + EXIT_CODE=$? + if [[ $EXIT_CODE != 0 ]] + then + mkdir -p $out/nix-support + git diff > $out/stylish.diff + echo "file none $out/stylish.diff" > $out/nix-support/hydra-build-products + echo "*** Stylish-haskell found changes that need addressed first" + echo "*** Please run \`nix-shell -A fixStylishHaskell\` and commit changes" + echo "*** or apply the diff generated by hydra if you don't have nix." + exit $EXIT_CODE + else + echo $EXIT_CODE > $out + fi +'' diff --git a/shell.nix b/shell.nix index 2afa578a8fb..0aadf3f93a3 100644 --- a/shell.nix +++ b/shell.nix @@ -16,8 +16,8 @@ in with pkgs; let hsPkgs = haskell.packages.ghc822; -in - haskell.lib.buildStackProject { + iohkPkgs = import ./. {inherit config system pkgs; }; + cardanoSL = haskell.lib.buildStackProject { name = "cardano-sl"; ghc = hsPkgs.ghc; buildInputs = [ @@ -29,4 +29,25 @@ in # See https://github.com/NixOS/nixpkgs/issues/21200 ] ++ (lib.optionals stdenv.isLinux [ cabal-install stack ]) ++ (lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ Cocoa CoreServices libcxx libiconv ])); - } + }; + fixStylishHaskell = stdenv.mkDerivation { + name = "fix-stylish-haskell"; + buildInputs = [ iohkPkgs.stylish-haskell git ]; + shellHook = '' + git diff > pre-stylish.diff + find . -type f -name "*hs" -not -path '.git' -not -path '*.stack-work*' -not -name 'HLint.hs' -exec stylish-haskell -i {} \; + git diff > post-stylish.diff + diff pre-stylish.diff post-stylish.diff > /dev/null + if [ $? != 0 ] + then + echo "Changes by stylish have been made. Please commit them." + else + echo "No stylish changes were made." + fi + rm pre-stylish.diff post-stylish.diff + exit + ''; + }; +in cardanoSL // { + inherit fixStylishHaskell; +}