Skip to content

Commit

Permalink
chore: check that imports are sorted in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ncfavier committed Nov 5, 2023
1 parent bc0e9cc commit 96f0122
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ jobs:
name: 1lab
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}

- name: Check that imports are sorted
if: github.event_name == 'pull_request'
run: |
nix run -f . sort-imports
if ! git diff --quiet; then
echo 'Imports are not sorted. Please run `support/sort-imports.hs`.'
exit 1
fi
- name: Build the Shakefile 🧰
run: |
hash=$(nix-build -A shakefile --no-out-link)
Expand Down
11 changes: 11 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,16 @@ in
inherit deps shakefile;
texlive = our-texlive;
ghc = our-ghc;

sort-imports = let
script = builtins.readFile support/sort-imports.hs;
# Extract the list of dependencies from the stack shebang comment.
deps = lib.concatLists (lib.filter (x: x != null)
(map (builtins.match ".*--package +([^[:space:]]*).*")
(lib.splitString "\n" script)));
in pkgs.writers.writeHaskellBin "sort-imports" {
ghc = pkgs.labHaskellPackages.ghc;
libraries = lib.attrVals deps pkgs.labHaskellPackages;
} script;
};
}

0 comments on commit 96f0122

Please sign in to comment.