From ab9cc41caf44d1f1d465d8028e4bc0096fd73238 Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Fri, 24 Jul 2020 13:06:32 +0200 Subject: [PATCH] Add CI check for formatting --- default.nix | 18 ++++++++++++++++++ script/fmt | 8 +++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/default.nix b/default.nix index 245ffd9..77584e4 100644 --- a/default.nix +++ b/default.nix @@ -198,6 +198,24 @@ rec tests-github = pkgs.callPackage ./tests/github { inherit niv; }; tests-git = pkgs.callPackage ./tests/git { inherit niv; }; + fmt-check = + pkgs.stdenv.mkDerivation + { + name = "fmt-check"; + buildInputs = [ pkgs.ormolu pkgs.glibcLocales ]; + src = niv-source; + phases = [ "unpackPhase" "checkPhase" ]; + LANG = "en_US.UTF-8"; + checkPhase = '' + cp ${./script/fmt} ./fmt + patchShebangs ./fmt + chmod +x fmt + bash fmt -c + touch $out + ''; + doCheck = true; + }; + readme = pkgs.runCommand "README.md" { nativeBuildInputs = [ niv ]; } '' cp ${./README.tpl.md} $out diff --git a/script/fmt b/script/fmt index 16116a3..651ee5a 100755 --- a/script/fmt +++ b/script/fmt @@ -1,4 +1,9 @@ -#!/usr/bin/env bash +#!/usr/bin/env nix-shell +#!nix-shell -i bash +#!nix-shell -I nixpkgs=./nix +#!nix-shell -p ormolu +#!nix-shell -p glibcLocales +#!nix-shell --keep GITHUB_TOKEN ### ### fmt - Format Haskell files with Ormolu ### @@ -40,6 +45,7 @@ fmt() { if [ "$mode" == "check" ]; then exit 1 fi + echo "Please run ./script/fmt" fi }