From 2481d0d4cbf72b960361de5d06dc213f0723b4ac Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Mon, 15 Aug 2022 17:46:32 -0700 Subject: ci(pre-commit): add a few more checks Add a mechanism to run checks for go (fmt/mod tidy) and one for terraform. Fix the configuration for shellcheck (it was not checking the files). Change-Id: I1d250b96bd22838eddf624fda6b4d78d5da3e39f Reviewed-on: https://cl.fcuny.net/c/world/+/715 Tested-by: CI Reviewed-by: Franck Cuny --- flake.nix | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 76e6369..d10c736 100644 --- a/flake.nix +++ b/flake.nix @@ -52,7 +52,37 @@ let pkgs = import inputs.nixpkgs { inherit system; }; home-manager = inputs.home-manager.defaultPackage."${system}"; - ci = import ./ops/ci { inherit pkgs; }; + pre-commit-golang = pkgs.callPackage + ({ stdenv, fetchFromGitHub }: + stdenv.mkDerivation rec { + pname = "pre-commit-golang"; + version = "0.5.0-96221dc"; + src = fetchFromGitHub { + owner = "dnephin"; + repo = pname; + rev = "96221dc741cb30cc0136999083dc6bd0e2113000"; + sha256 = "sha256-lIQBoT+UIlVGnFaaGBgXag0Lm1UhGj/pIGlCCz91L4I="; + }; + dontBuild = true; + dontConfigure = true; + installPhase = '' + runHook preInstall + install -d $out + find . -type f -name 'run-*.sh' \ + | sed -E 's:^\./run-(.*)\.sh:\1:' \ + | xargs -I {} install ./run-{}.sh $out/{} + runHook postInstall + ''; + }) + { }; + pre-commit-golang-hook = name: { + "${name}" = { + inherit name; + enable = true; + entry = "${pre-commit-golang}/${name}"; + files = "\\.go$"; + }; + }; in rec { @@ -85,10 +115,18 @@ enable = true; }; + terraform-format = { + enable = true; + }; + shellcheck = { enable = true; + files = "\\.sh$"; + types_or = [ "file" ]; }; - }; + } + // (pre-commit-golang-hook "go-fmt") + // (pre-commit-golang-hook "go-mod-tidy"); }; }; -- cgit 1.4.1