From ab54d6e45044ebabcfb0d6e77173229b050ce5e7 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 bf80568..0c45d65 100644 --- a/haskell.nix/README.md +++ b/haskell.nix/README.md @@ -26,7 +26,9 @@ Haskell application and library templates for Buildkite, Gitlab or GitHub CI usi - For GitHub, copy `.github/workflows/check-outdated.yml` or `.github/workflows/check-nightly.yml` to your library repository. - For Gitlab, configure the schedule in the repository settings and uncomment `check-outdated` and `report-outdated` or `check-nightly` and `report-nightly-failure` in `.gitlab-ci.yml`. For nightly checks, you will also need to enable gitlab hosted runners in the repository settings. - 5. Make sure to clean up your `flake.nix` and pipeline configuration files by removing any optional code that is left commented out. + 5. 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. + + 6. 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 c5ba080..40f160b 100644 --- a/haskell.nix/application/.github/workflows/check.yml +++ b/haskell.nix/application/.github/workflows/check.yml @@ -44,6 +44,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_.*" ]