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

Commit 491a3b2

Browse files
authored
Merge pull request #3166 from input-output-hk/devops-936-stylish-haskell
[DEVOPS-936] Hydra CI job for stylish-haskell
2 parents 098e28b + 7d0b058 commit 491a3b2

File tree

10 files changed

+105
-45
lines changed

10 files changed

+105
-45
lines changed

.buildkite/pipeline.yml

-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ steps:
44
agents:
55
system: x86_64-linux
66

7-
- label: 'stylish-haskell'
8-
command: 'scripts/ci/nix-shell.sh --run scripts/check-stylish.sh'
9-
agents:
10-
system: x86_64-linux
11-
127
- label: 'stack2nix'
138
command: 'scripts/ci/nix-shell.sh -p cabal2nix stack cabal-install ghc moreutils expect -Q -j 4 --run scripts/check-stack2nix.sh'
149
agents:

default.nix

+9-4
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,17 @@ let
151151
in
152152
args: pkgs.callPackage ./scripts/launch/connect-to-cluster (args // { inherit gitrev; } // walletConfig );
153153
other = rec {
154+
walletIntegrationTests = pkgs.callPackage ./scripts/test/wallet/integration { inherit gitrev; };
154155
validateJson = pkgs.callPackage ./tools/src/validate-json {};
155156
demoCluster = pkgs.callPackage ./scripts/launch/demo-cluster { inherit gitrev; };
156-
shellcheckTests = pkgs.callPackage ./scripts/test/shellcheck.nix { src = ./.; };
157-
swaggerSchemaValidation = pkgs.callPackage ./scripts/test/wallet/swaggerSchemaValidation.nix { inherit gitrev; };
158-
walletIntegrationTests = pkgs.callPackage ./scripts/test/wallet/integration { inherit gitrev; };
159-
buildWalletIntegrationTests = pkgs.callPackage ./scripts/test/wallet/integration/build-test.nix { inherit walletIntegrationTests pkgs; };
157+
tests = {
158+
shellcheck = pkgs.callPackage ./scripts/test/shellcheck.nix { src = ./.; };
159+
hlint = pkgs.callPackage ./scripts/test/hlint.nix { src = ./.; };
160+
stylishHaskell = pkgs.callPackage ./scripts/test/stylish.nix { src = ./.; stylish-haskell = cardanoPkgs.stylish-haskell; };
161+
buildWalletIntegration = pkgs.callPackage ./scripts/test/wallet/integration/build-test.nix { inherit walletIntegrationTests pkgs; };
162+
swaggerSchemaValidation = pkgs.callPackage ./scripts/test/wallet/swaggerSchemaValidation.nix { inherit gitrev; };
163+
};
164+
fixStylishHaskell = pkgs.callPackage ./scripts/haskell/stylish.nix { stylish-haskell = cardanoPkgs.stylish-haskell; };
160165
cardano-sl-explorer-frontend = (import ./explorer/frontend {
161166
inherit system config gitrev pkgs;
162167
cardano-sl-explorer = cardanoPkgs.cardano-sl-explorer-static;

release.nix

+2-4
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ let
6060
inherit (mapped'.connectScripts."${cluster}") wallet explorer;
6161
};
6262
nixosTests = import ./nixos-tests;
63-
shellcheckTests = iohkPkgs.shellcheckTests;
64-
swaggerSchemaValidation = iohkPkgs.swaggerSchemaValidation;
65-
walletIntegrationTests = iohkPkgs.buildWalletIntegrationTests;
63+
tests = iohkPkgs.tests;
6664
makeRelease = cluster: {
6765
name = cluster;
6866
value = {
@@ -71,7 +69,7 @@ let
7169
};
7270
};
7371
in mapped // {
74-
inherit walletIntegrationTests swaggerSchemaValidation shellcheckTests;
72+
inherit tests;
7573
nixpkgs = let
7674
wrapped = pkgs.runCommand "nixpkgs" {} ''
7775
ln -sv ${fixedNixpkgs} $out

scripts/check-stylish.sh

-19
This file was deleted.

scripts/haskell/shell-with-stylish.nix

-4
This file was deleted.

scripts/haskell/stylish-last-10.sh

-5
This file was deleted.

scripts/haskell/stylish.sh

-1
This file was deleted.

scripts/test/hlint.nix

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{ runCommand, hlint, src, lib }:
2+
3+
let
4+
cleanSourceFilter = with lib;
5+
name: type: let baseName = baseNameOf (toString name); in (
6+
(type == "regular" && hasSuffix ".hs" baseName) ||
7+
(type == "regular" && hasSuffix ".yaml" baseName) ||
8+
(type == "directory")
9+
);
10+
src' = builtins.filterSource cleanSourceFilter src;
11+
in
12+
runCommand "cardano-hlint-check" { buildInputs = [ hlint ]; } ''
13+
set +e
14+
# Networking is not in here, because it has a very different codestyle (doesn't use universum).
15+
# This is bad and should probably be fixed.
16+
projects=("util" "binary" "crypto" "core" "db" "lrc" "infra" "ssc" "txp" "update" "delegation" "node" "tools" "client" "generator" "auxx" "explorer" "wallet" "wallet-new")
17+
cd ${src'}
18+
hlint lib/src lib/test lib/bench "''${projects[@]}"
19+
EXIT_CODE=$?
20+
if [[ $EXIT_CODE != 0 ]]
21+
then
22+
echo '====================================================================='
23+
echo 'Note: to ignore a particular hint (e.g. "Reduce duplication"), write'
24+
echo 'this in the source file:'
25+
tput bold
26+
echo '{-# ANN module ("HLint: ignore Reduce duplication" :: Text) #-}'
27+
tput sgr0
28+
echo 'You can also apply it just to a particular function, which is better:'
29+
tput bold
30+
echo '{-# ANN funcName ("HLint: ignore Reduce duplication" :: Text) #-}'
31+
tput sgr0
32+
exit $EXIT_CODE
33+
else
34+
echo $EXIT_CODE > $out
35+
fi
36+
''

scripts/test/stylish.nix

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{ runCommand, stylish-haskell, src, lib, git }:
2+
3+
let
4+
cleanSourceFilter = with lib;
5+
name: type: let baseName = baseNameOf (toString name); in (
6+
(type == "regular" && hasSuffix ".hs" baseName) ||
7+
(type == "regular" && hasSuffix ".yaml" baseName) ||
8+
(type == "directory")
9+
);
10+
src' = builtins.filterSource cleanSourceFilter src;
11+
in
12+
runCommand "cardano-stylish-check" { succeedOnFailure = true; buildInputs = [ stylish-haskell git ]; } ''
13+
set +e
14+
cp -a ${src'} tmp-cardano
15+
chmod -R 0755 tmp-cardano
16+
cd tmp-cardano
17+
git init
18+
git add -A
19+
find . -type f -name "*hs" -not -path '.git' -not -path '*.stack-work*' -not -name 'HLint.hs' -exec stylish-haskell -i {} \;
20+
git diff --exit-code
21+
EXIT_CODE=$?
22+
if [[ $EXIT_CODE != 0 ]]
23+
then
24+
mkdir -p $out/nix-support
25+
git diff > $out/stylish.diff
26+
echo "file none $out/stylish.diff" > $out/nix-support/hydra-build-products
27+
echo "*** Stylish-haskell found changes that need addressed first"
28+
echo "*** Please run \`nix-shell -A fixStylishHaskell\` and commit changes"
29+
echo "*** or apply the diff generated by hydra if you don't have nix."
30+
exit $EXIT_CODE
31+
else
32+
echo $EXIT_CODE > $out
33+
fi
34+
''

shell.nix

+24-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ in
1616
with pkgs;
1717
let
1818
hsPkgs = haskell.packages.ghc822;
19-
in
20-
haskell.lib.buildStackProject {
19+
iohkPkgs = import ./. {inherit config system pkgs; };
20+
cardanoSL = haskell.lib.buildStackProject {
2121
name = "cardano-sl";
2222
ghc = hsPkgs.ghc;
2323
buildInputs = [
@@ -29,4 +29,25 @@ in
2929
# See https://github.com/NixOS/nixpkgs/issues/21200
3030
] ++ (lib.optionals stdenv.isLinux [ cabal-install stack ])
3131
++ (lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ Cocoa CoreServices libcxx libiconv ]));
32-
}
32+
};
33+
fixStylishHaskell = stdenv.mkDerivation {
34+
name = "fix-stylish-haskell";
35+
buildInputs = [ iohkPkgs.stylish-haskell git ];
36+
shellHook = ''
37+
git diff > pre-stylish.diff
38+
find . -type f -name "*hs" -not -path '.git' -not -path '*.stack-work*' -not -name 'HLint.hs' -exec stylish-haskell -i {} \;
39+
git diff > post-stylish.diff
40+
diff pre-stylish.diff post-stylish.diff > /dev/null
41+
if [ $? != 0 ]
42+
then
43+
echo "Changes by stylish have been made. Please commit them."
44+
else
45+
echo "No stylish changes were made."
46+
fi
47+
rm pre-stylish.diff post-stylish.diff
48+
exit
49+
'';
50+
};
51+
in cardanoSL // {
52+
inherit fixStylishHaskell;
53+
}

0 commit comments

Comments
 (0)