From e273303900bd80a411f896cd222c92c00417c447 Mon Sep 17 00:00:00 2001 From: Samer Afach Date: Thu, 18 Apr 2024 12:40:16 +0400 Subject: [PATCH] Add code checks to CI and do_checks script --- .github/workflows/code_checks.yml | 82 +++++++++++++++++++++++++++++++ Cargo.lock | 12 ++--- deny.toml | 40 +++++++++++++++ do_checks.sh | 14 ++++++ 4 files changed, 142 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/code_checks.yml create mode 100644 deny.toml create mode 100755 do_checks.sh diff --git a/.github/workflows/code_checks.yml b/.github/workflows/code_checks.yml new file mode 100644 index 0000000..fbd081e --- /dev/null +++ b/.github/workflows/code_checks.yml @@ -0,0 +1,82 @@ +name: Static code checks + +on: + push: + branches: + - "**" # target all branches + pull_request: + branches: + - master + +env: + CARGO_TERM_COLOR: always + RUST_LOG: debug + RUST_BACKTRACE: full + +jobs: + static_checks_ubuntu: + runs-on: ubuntu-latest + steps: + - name: Checkout repository and submodules + uses: actions/checkout@v2 + with: + submodules: recursive + + - name: Update local dependency repositories + run: sudo apt-get update + - name: Install dependencies + run: sudo apt-get install -yqq --no-install-recommends build-essential python3 python3-toml + + - name: Install rust + run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $(python3 ./build-tools/rust-version-extractor/rust-version-extractor.py) + - name: Install rust clippy + run: rustup component add clippy + - name: Install cargo-deny + run: cargo install cargo-deny --locked + - name: Run checks + run: ./do_checks.sh + + static_checks_windows: + runs-on: windows-latest + steps: + # This prevents git from changing line-endings to crlf, which messes cargo fmt checks + - name: Set git to use LF + run: | + git config --global core.autocrlf false + git config --global core.eol lf + + - name: Checkout repository and submodules + uses: actions/checkout@v2 + with: + submodules: recursive + + - name: Install python toml package + run: python3 -m pip install toml + - name: Install rust + run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $(python3 ./build-tools/rust-version-extractor/rust-version-extractor.py) + - name: Install rust clippy + run: rustup component add clippy + - name: Install cargo-deny + run: cargo install cargo-deny --locked + - name: Run checks + shell: bash + run: ./do_checks.sh + + static_checks_macos: + runs-on: macos-latest + steps: + - name: Checkout repository and submodules + uses: actions/checkout@v2 + with: + submodules: recursive + + - name: Install python toml package + run: python3 -m pip install toml + - name: Install rust + run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $(python3 ./build-tools/rust-version-extractor/rust-version-extractor.py) + - name: Install rust clippy + run: rustup component add clippy + - name: Install cargo-deny + run: cargo install cargo-deny --locked + - name: Run checks + run: bash ./do_checks.sh diff --git a/Cargo.lock b/Cargo.lock index f7d5333..5b5af9f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -172,7 +172,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] @@ -436,7 +436,7 @@ dependencies = [ "regex", "relative-path", "rustc_version", - "syn 2.0.59", + "syn 2.0.60", "unicode-ident", ] @@ -478,7 +478,7 @@ checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] @@ -515,9 +515,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.59" +version = "2.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" dependencies = [ "proc-macro2", "quote", @@ -547,7 +547,7 @@ checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] diff --git a/deny.toml b/deny.toml new file mode 100644 index 0000000..980f980 --- /dev/null +++ b/deny.toml @@ -0,0 +1,40 @@ +[sources.allow-org] +github = [ + "mintlayer", # allow any code from mintlayer's github +] + +[licenses] +#we reject code without a license +confidence-threshold = 0.92 +allow = [ + "Apache-2.0", + "MIT", + "Unicode-DFS-2016", +] # deny a license not in this set of licenses + +[[licenses.clarify]] +name = "ring" +expression = "LicenseRef-ring" +license-files = [ + { path = "LICENSE", hash = 0xbd0eed23 }, +] + +[[licenses.clarify]] +name = "webpki" +expression = "LicenseRef-webpki" +license-files = [ + { path = "LICENSE", hash = 0x001c7e6c }, +] + +[[licenses.clarify]] +name = "rustls-webpki" +expression = "LicenseRef-webpki" +license-files = [ + { path = "LICENSE", hash = 0x001c7e6c }, +] + +[advisories] +db-path = "~/.cargo/advisory-dbs" +db-urls = [ "https://github.com/RustSec/advisory-db" ] +yanked = "warn" +ignore = [] diff --git a/do_checks.sh b/do_checks.sh new file mode 100755 index 0000000..07d3365 --- /dev/null +++ b/do_checks.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -e + +SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) +PYTHON=$(which python || which python3) + +cargo fmt --check -- --config newline_style=Unix + +# Install cargo deny first with: cargo install cargo-deny +cargo deny check --hide-inclusion-graph + +# Checks enabled everywhere, including tests, benchmarks +cargo clippy