From 8c2b5a3043c036f4071dba9022cb23be25d5298b Mon Sep 17 00:00:00 2001 From: Sergey Gulin Date: Mon, 29 Jan 2024 02:22:13 +0300 Subject: [PATCH] [Chore] Add weeder check Problem: We want to be able to check our Haskell applications for dead code. This can be done using weeder. Solution: Use weeder check from serokell.nix. --- haskell.nix/README.md | 4 +++- haskell.nix/application/.github/workflows/check.yml | 4 ++++ haskell.nix/application/.gitlab-ci.yml | 5 +++++ haskell.nix/application/flake.nix | 8 ++++++++ haskell.nix/application/weeder.toml | 1 + 5 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 haskell.nix/application/weeder.toml diff --git a/haskell.nix/README.md b/haskell.nix/README.md index 2bb6cc5..6153220 100644 --- a/haskell.nix/README.md +++ b/haskell.nix/README.md @@ -21,7 +21,9 @@ Haskell application and library templates for Buildkite, Gitlab or GitHub CI usi 3. If you're using `hpack` or `stack2cabal` in your project, make sure to uncomment the related lines in both `flake.nix` and pipeline configuration files. To avoid version mismatches, use `nix develop .#ci -c hpack` or `nix develop .#ci -c stack2cabal`. - 4. Make sure to clean up your `flake.nix` and pipeline configuration files by removing any optional code that is left commented out. + 4. You might want to add a [`weeder`](https://github.com/ocharles/weeder/) check to check for dead code in your application. To do this uncomment the related lines in both `flake.nix` (do not forget to uncomment `writeHieFiles = true;`) and pipeline configuration files, then copy `weeder.toml` (for more advanced setup, please refer to the [corresponding section](https://github.com/ocharles/weeder/?tab=readme-ov-file#calling-weederUsually) of the `weeder` README) to your repository. For a library, code is usually considered dead unless it is exported; such cases are already detected by GHC warnings, so no `weeder` is required. + + 5. Make sure to clean up your `flake.nix` and pipeline configuration files by removing any optional code that is left commented out. - Enjoy working CI! diff --git a/haskell.nix/application/.github/workflows/check.yml b/haskell.nix/application/.github/workflows/check.yml index 9ee5b41..f1324f0 100644 --- a/haskell.nix/application/.github/workflows/check.yml +++ b/haskell.nix/application/.github/workflows/check.yml @@ -39,6 +39,10 @@ jobs: # run: nix build -L .#checks.x86_64-linux.hpack # if: success() || failure() + # - name: check-weeder + # run: nix build -L .#checks.x86_64-linux.weeder + # if: success() || failure() + build: runs-on: [self-hosted, nix] steps: diff --git a/haskell.nix/application/.gitlab-ci.yml b/haskell.nix/application/.gitlab-ci.yml index 29fa8fe..59da321 100644 --- a/haskell.nix/application/.gitlab-ci.yml +++ b/haskell.nix/application/.gitlab-ci.yml @@ -47,6 +47,11 @@ check-trailing-whitespace: # script: # - nix build -L .#checks.x86_64-linux.hpack +# check-weeder: +# stage: validate +# script: +# - nix build -L .#checks.x86_64-linux.weeder + # build haskell components build-all: stage: build diff --git a/haskell.nix/application/flake.nix b/haskell.nix/application/flake.nix index 52f7e0f..f00a5e5 100644 --- a/haskell.nix/application/flake.nix +++ b/haskell.nix/application/flake.nix @@ -18,6 +18,7 @@ stackage = { flake = false; }; + serokell-nix.inputs.haskell-nix.follows = "haskell-nix"; }; outputs = { self, nixpkgs, haskell-nix, hackage, stackage, serokell-nix, flake-compat, flake-utils, ... }: @@ -43,6 +44,8 @@ # haskell.nix configuration modules = [ (serokell-nix.lib.haskell.optionsLocalPackages { + # Uncomment if your project uses weeder check + # writeHieFiles = true; ghcOptions = [ # fail on warnings "-Werror" @@ -91,6 +94,11 @@ # cabal-check = pkgs.build.haskell.cabal-check ./.; # Uncomment if your project uses hpack to generate cabal files # hpack = pkgs.build.haskell.hpack ./.; + # Uncomment to check for dead code + # weeder = pkgs.build.haskell.weeder { + # weederToml = ./weeder.toml; + # inherit hs-pkgs; + # }; }; }); } diff --git a/haskell.nix/application/weeder.toml b/haskell.nix/application/weeder.toml new file mode 100644 index 0000000..ba93bd5 --- /dev/null +++ b/haskell.nix/application/weeder.toml @@ -0,0 +1 @@ +roots = [ "^Main.main$", "^Paths_.*" ]