From 972402d6352e489ac5c99b0285a1fd40c2a97dbc Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sun, 10 Nov 2024 21:29:54 +0000 Subject: [PATCH] Improve check script to allow running just some checks. --- .github/workflows/ci.yml | 20 ++++++++- .taplo.toml | 17 ++++++++ Cargo.toml | 25 +++++------ tools/check.sh | 94 ++++++++++++++++++++++++++++++++-------- 4 files changed, 121 insertions(+), 35 deletions(-) create mode 100644 .taplo.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6fa85ed..7314cd0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,13 +28,16 @@ jobs: - name: Install cargo plugins run: | cargo install cargo-rdme + cargo install cargo-machete + cargo install taplo-cli cargo install cargo-deadlinks - name: Checkout repository uses: actions/checkout@v4 - name: Check everything - run: bash ./tools/check.sh + run: bash ./tools/check.sh basic doc_url_links unused_deps packaging fmt toml_fmt readme + msrv: runs-on: ubuntu-latest @@ -54,4 +57,17 @@ jobs: uses: actions/checkout@v4 - name: Check the minimum supported rust version - run: cargo msrv verify + run: bash ./tools/check.sh msrv + + clippy: + runs-on: ubuntu-latest + + steps: + - name: Install rust + uses: dtolnay/rust-toolchain@stable + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Run clippy + run: bash ./tools/check.sh clippy diff --git a/.taplo.toml b/.taplo.toml new file mode 100644 index 0000000..6ca9d28 --- /dev/null +++ b/.taplo.toml @@ -0,0 +1,17 @@ +include = ["**/*.toml"] +exclude = ["target/**"] + +[formatting] +column_width = 100 +indent_string = ' ' +allowed_blank_lines = 1 + +[[rule]] +formatting = { reorder_keys = true } +keys = [ + "workspace.dependencies", + "dependencies", + "dev-dependencies", + "build-dependencies", + "lints.clippy", +] diff --git a/Cargo.toml b/Cargo.toml index 2e4b0db..77adb2e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,15 +12,9 @@ repository = "https://github.com/orium/shrug" documentation = "https://docs.rs/shrug" readme = "README.md" -keywords = [ - "shortcut", - "strings", - "clipboard", -] +keywords = ["shortcut", "strings", "clipboard"] -categories = [ - "gui", -] +categories = ["gui"] license = "MPL-2.0" @@ -39,25 +33,28 @@ include = [ codecov = { repository = "orium/shrug", branch = "main", service = "github" } [dependencies] -gtk4 = { version = "0.9.1", features = ["v4_6"] } +async-channel = "2.3.1" +dirs = "5.0.1" gdk4 = { version = "0.9.0", features = ["v4_6"] } gio = { version = "0.20.1", features = ["v2_70"] } glib = "0.20.2" -toml = "0.8.19" -dirs = "5.0.1" +gtk4 = { version = "0.9.1", features = ["v4_6"] } +rayon = "1.10.0" serde = "1.0.209" serde_derive = "1.0.209" sublime_fuzzy = "0.7.0" -rayon = "1.10.0" -async-channel = "2.3.1" +toml = "0.8.19" [features] fatal-warnings = [] +[package.metadata.cargo-machete] +ignored = ["serde"] + [lints.clippy] all = { level = "warn", priority = -2 } -pedantic = { level = "warn", priority = -2 } correctness = { level = "deny", priority = -1 } +pedantic = { level = "warn", priority = -2 } match-bool = "allow" needless-for-each = "allow" diff --git a/tools/check.sh b/tools/check.sh index a20dd66..2b3444a 100755 --- a/tools/check.sh +++ b/tools/check.sh @@ -20,28 +20,84 @@ function on_failure { echo -e "${RED}Whoopsie-daisy: something failed!$NC" >&2 } -assert_installed "cargo-deadlinks" -assert_installed "cargo-fmt" -assert_installed "cargo-rdme" +assert_installed "cargo" trap on_failure ERR -echo 'Building:' -cargo build --features fatal-warnings --all-targets -echo 'Testing:' -cargo test --features fatal-warnings --all-targets -echo 'Checking documentation:' -cargo doc --features fatal-warnings --no-deps --document-private-items - -echo 'Checking links:' -cargo deadlinks - -echo 'Checking packaging:' -cargo package --allow-dirty -echo 'Checking code style:' -cargo fmt -- --check -echo 'Checking readme:' -cargo rdme --check +function check_basic { + echo 'Building:' + cargo build --features fatal-warnings --all-targets + echo 'Testing:' + cargo test --features fatal-warnings --all-targets + echo 'Checking the benchmarks:' + cargo bench --features fatal-warnings -- --test + echo 'Checking documentation:' + cargo doc --features fatal-warnings --no-deps --document-private-items +} + +function check_doc_url_links { + assert_installed "cargo-deadlinks" + + echo 'Checking doc url links:' + cargo deadlinks +} + +function check_unused_deps { + assert_installed "cargo-machete" + + echo 'Checking unused dependencies:' + cargo machete +} + +function check_packaging { + echo 'Checking packaging:' + cargo package --allow-dirty +} + +function check_fmt { + assert_installed "cargo-fmt" + + echo 'Checking code format:' + cargo fmt -- --check +} + +function check_toml_fmt { + assert_installed "taplo" + + echo 'Checking toml format:' + taplo fmt --check +} + +function check_readme { + assert_installed "cargo-rdme" + + echo 'Checking readme:' + cargo rdme --check +} + +function check_msrv { + assert_installed "cargo-msrv" + + echo 'Checking the minimum supported rust version:' + cargo msrv verify +} + +function check_clippy { + assert_installed "cargo-clippy" + + echo 'Checking with clippy:' + cargo clippy --all-targets -- -D warnings +} + +to_run=(basic doc_url_links unused_deps packaging fmt toml_fmt readme msrv clippy) + +if [ $# -ge 1 ]; then + to_run=("$@") +fi + +for check in "${to_run[@]}"; do + check_$check +done echo echo -e "${GREEN}Everything looks lovely!$NC"