Skip to content

Commit

Permalink
Use pre-commit from Nix shell for CI style check
Browse files Browse the repository at this point in the history
  • Loading branch information
oxalica committed Dec 31, 2022
1 parent 4f8b44d commit 893ae1f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 30 deletions.
32 changes: 6 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,18 @@ env:
RUST_BACKTRACE: full

jobs:
format:
name: Format
style:
name: Code style check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: rustfmt
- name: Check format
run: cargo fmt --all -- --check

clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
# For builtins.
- name: Install Nix
uses: cachix/install-nix-action@v17
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: clippy
- name: Check clippy
run: cargo clippy --all -- -D warnings
- name: Prepare devShell
run: nix develop --command true
- name: Run pre-commit
run: nix develop --command pre-commit

test:
name: Test
Expand Down
16 changes: 12 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,22 @@
pkgs = nixpkgs.legacyPackages.${system};
rustPkgs = rust-overlay.packages.${system};

clippyFlags = lib.concatStringsSep " " [
"-D" "warnings"
"-D" "clippy::dbg_macro"
];

pre-commit = pkgs.writeShellScriptBin "pre-commit" ''
set -e
die() { echo "$*" >&2; exit 1; }
cd "$(git rev-parse --show-toplevel)"
rg --fixed-strings 'dbg!' --glob '*.rs' \
&& die 'Found dbg!()'
cargo fmt --quiet --check >/dev/null \
if git_dir="$(git rev-parse --show-toplevel)"; then
cd "$git_dir"
fi
cargo fmt --all --check \
|| die 'Format failed'
cargo clippy --all --all-targets -- ${clippyFlags} \
|| die 'Clippy failed'
'';

nil = pkgs.callPackage mkNil { };
Expand Down Expand Up @@ -79,6 +86,7 @@

RUST_BACKTRACE = "short";
NIXPKGS = nixpkgs;
CLIPPY_FLAGS = clippyFlags;

# bash
shellHook = ''
Expand Down

0 comments on commit 893ae1f

Please sign in to comment.