Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

[DEVOPS-936] Hydra CI job for stylish-haskell #3166

Merged
merged 2 commits into from
Jul 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 9 additions & 4 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -71,7 +69,7 @@ let
};
};
in mapped // {
inherit walletIntegrationTests swaggerSchemaValidation shellcheckTests;
inherit tests;
nixpkgs = let
wrapped = pkgs.runCommand "nixpkgs" {} ''
ln -sv ${fixedNixpkgs} $out
Expand Down
19 changes: 0 additions & 19 deletions scripts/check-stylish.sh

This file was deleted.

4 changes: 0 additions & 4 deletions scripts/haskell/shell-with-stylish.nix

This file was deleted.

5 changes: 0 additions & 5 deletions scripts/haskell/stylish-last-10.sh

This file was deleted.

1 change: 0 additions & 1 deletion scripts/haskell/stylish.sh

This file was deleted.

36 changes: 36 additions & 0 deletions scripts/test/hlint.nix
Original file line number Diff line number Diff line change
@@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this use lib.cleanSourceWith (see example in #3174). That will work better with already filtered sources I think.

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
''
34 changes: 34 additions & 0 deletions scripts/test/stylish.nix
Original file line number Diff line number Diff line change
@@ -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
''
27 changes: 24 additions & 3 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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;
}