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

Commit

Permalink
[CDEC-383] Add stylish-haskell to nix and CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ruhatch committed Jun 26, 2018
1 parent 1a27109 commit 8392e34
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ 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
4 changes: 2 additions & 2 deletions .stylish-haskell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ steps:
# > (concat, foldl, foldr, head, init, last, length)
#
# Default: after_alias
list_align: after_alias
list_align: with_module_name

# Right-pad the module names to align imports in a group:
#
Expand Down Expand Up @@ -198,7 +198,7 @@ steps:
# Note: we tend to write code which fits into 80 characters, in some cases
# 100 is acceptable. For imports we always permit 100 characters because it
# decreases verbosity of diffs and makes merging easier.
columns: 100
columns: 80

# By default, line endings are converted according to the OS. You can override
# preferred format here.
Expand Down
69 changes: 69 additions & 0 deletions pkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -75842,6 +75842,75 @@ homepage = "http://github.com/ekmett/structs/";
description = "Strict GC'd imperative object-oriented programming with cheap pointers";
license = stdenv.lib.licenses.bsd3;

}) {};
"stylish-haskell" = callPackage
({
mkDerivation
, aeson
, base
, bytestring
, containers
, directory
, fetchgit
, file-embed
, filepath
, haskell-src-exts
, mtl
, optparse-applicative
, semigroups
, stdenv
, strict
, syb
, yaml
}:
mkDerivation {

pname = "stylish-haskell";
version = "0.9.2.0";
src = fetchgit {

url = "https://github.com/input-output-hk/stylish-haskell.git";
sha256 = "0d6ylb07gxv050fpzc6siwxj8c7j1pkcry5zyzimv0xwn1wf6rfy";
rev = "ecfd3b307d8d13a6d12aff03055f25a39a17e182";

};
isLibrary = true;
isExecutable = true;
libraryHaskellDepends = [
aeson
base
bytestring
containers
directory
file-embed
filepath
haskell-src-exts
mtl
semigroups
syb
yaml
];
executableHaskellDepends = [
aeson
base
bytestring
containers
directory
file-embed
filepath
haskell-src-exts
mtl
optparse-applicative
strict
syb
yaml
];
doHaddock = false;
doCheck = false;
homepage = "https://github.com/jaspervdj/stylish-haskell";
description = "Haskell code prettifier";
license = stdenv.lib.licenses.bsd3;

}) {};
"sum-type-boilerplate" = callPackage
({
Expand Down
26 changes: 26 additions & 0 deletions scripts/check-stylish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

# check and warn if commits don't conform to stylish-haskell

set -xe

fail_stylish_check() {
# The '-w' option for 'git diff' is used because in some builds
# (i.e. https://buildkite.com/input-output-hk/cardano-sl/builds/976#0fb162df-8f9b-42d7-9ca7-608a9ea06d4d)
# the patch to 'default.nix' only suggests that whitespaces be added
# (see https://gist.github.com/anonymous/f52dbb040db16034d303e27056a0a48e), without
# which the build fails in the 'stack2nix' step.
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/

# shellcheck source=/dev/null
source "${haskellScriptDir}stylish-last-10.sh"


git diff --text --exit-code || fail_stylish_check
4 changes: 4 additions & 0 deletions scripts/haskell/shell-with-stylish.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let
cardanoPkgs = import ../../. {};
pkgs = import ((import ../../lib.nix).fetchNixPkgs) { };
in pkgs.runCommand "name" { buildInputs = [ cardanoPkgs.stylish-haskell ]; } ""
5 changes: 5 additions & 0 deletions scripts/haskell/stylish-last-10.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
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"
6 changes: 6 additions & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ packages:
commit: e4e879abca99d0d56015765859fb37af59a81dbb
extra-dep: true

# Add custom stylish-haskell while waiting for PR upstream: https://github.com/jaspervdj/stylish-haskell/pull/214
- location:
git: https://github.com/input-output-hk/stylish-haskell.git
commit: ecfd3b307d8d13a6d12aff03055f25a39a17e182
extra-dep: true

nix:
shell-file: shell.nix

Expand Down

0 comments on commit 8392e34

Please sign in to comment.