From f9933798b3d42123a401cc188db0dc8f7dbe2674 Mon Sep 17 00:00:00 2001 From: willcl-ark Date: Fri, 1 Nov 2024 16:50:17 +0000 Subject: [PATCH] add lint ci job --- .github/workflows/ci.yml | 14 ++++++++++++ justfile | 8 +++++++ requirements.txt | 7 ++++++ shell.nix | 49 ++++++++++++++++++++++++---------------- 4 files changed, 58 insertions(+), 20 deletions(-) create mode 100644 requirements.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0eb68ef44511fb..5c0ecd71e7957c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,20 @@ on: tags-ignore: - '**' jobs: + lint: + runs-on: [self-hosted, linux, x64] + timeout-minutes: 5 + steps: + - name: Checkout repo + uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v27 + with: + nix_path: nixpkgs=channel:nixos-unstable + - name: Build & test release + env: + NIX_PATH: nixpkgs=channel:nixos-unstable + run: | + nix-shell --command "just lint" build-and-test: runs-on: [self-hosted, linux, x64] timeout-minutes: 20 diff --git a/justfile b/justfile index 0feef8a4223712..5155c04c4d1913 100644 --- a/justfile +++ b/justfile @@ -62,6 +62,14 @@ test-unit1 suite: bench: build/src/bench/bench_bitcoin +# Run the lint job +lint: + #!/usr/bin/env bash + cd test/lint/test_runner/ + cargo fmt + cargo clippy + COMMIT_RANGE="$( git rev-list --max-count=1 --merges HEAD )..HEAD" cargo run + # Run the CI workflow [group('ci')] run-ci: build-ci bench test diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000000000..d91481dd5d8131 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +codespell==2.2.6 +lief==0.13.2 +mypy==1.4.1 +pyzmq==25.1.0 +ruff==0.5.5 +vulture==2.6 +pyperf diff --git a/shell.nix b/shell.nix index 6cf45818c220a5..b0c53ad1f8bdf4 100644 --- a/shell.nix +++ b/shell.nix @@ -9,6 +9,20 @@ }: let inherit (pkgs.lib) optionals strings; + + # Add mlc binary fetching + mlcBinary = pkgs.fetchurl { + url = "https://github.com/becheran/mlc/releases/download/v0.18.0/mlc-x86_64-linux"; + sha256 = "sha256-jbdp+UlFybBE+o567L398hbcWHsG8aQGqYYf5h9JRkw="; + }; + + # Create a derivation for mlc + mlc = pkgs.runCommand "mlc" {} '' + mkdir -p $out/bin + cp ${mlcBinary} $out/bin/mlc + chmod +x $out/bin/mlc + ''; + binDirs = [ "\$PWD/src" ] ++ optionals withGui [ "\$PWD/src/qt" ]; @@ -46,30 +60,12 @@ in pkgs.mkShell { # https://github.com/bitcoin/bitcoin/blob/master/doc/productivity.md#cache-compilations-with-ccache ccache - # generating compile_commands.json for clang-format, clang-tidy, LSPs etc - # https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md#running-clang-tidy - # $ a && c && m clean && bear --config src/.bear-tidy-config -- make -j6 - clang-tools_18 - bear - # for newer cmake building cmake # depends byacc - # functional tests & linting - python3 - python3Packages.flake8 - python3Packages.lief - python3Packages.autopep8 - python3Packages.mypy - python3Packages.requests - python3Packages.pyzmq - - # benchmarking - python3Packages.pyperf - # debugging gdb @@ -94,9 +90,16 @@ in pkgs.mkShell { buildInputs = with pkgs; [ just bash - ]; - + # lint requirements + cargo + gitMinimal + mlc + ruff + rustc + shellcheck + uv + ]; # Modifies the Nix clang++ wrapper to avoid warning: # "_FORTIFY_SOURCE requires compiling with optimization (-O)" @@ -108,6 +111,11 @@ in pkgs.mkShell { shellHook = '' echo "Bitcoin Core build nix-shell" echo "" + echo "Setting up python venv" + + uv venv --python 3.10 + source .venv/bin/activate + uv pip install -r requirements.txt BCC_EGG=${pkgs.linuxPackages.bcc}/${pkgs.python3.sitePackages}/bcc-${pkgs.linuxPackages.bcc.version}-py3.${pkgs.python3.sourceVersion.minor}.egg @@ -121,5 +129,6 @@ in pkgs.mkShell { echo "adding ${builtins.concatStringsSep ":" binDirs} to \$PATH to make running built binaries more natural" export PATH=$PATH:${builtins.concatStringsSep ":" binDirs}; + ''; }