From 4eb78e209204dd89f5384a277a15c861872b2654 Mon Sep 17 00:00:00 2001 From: ulic-youthlic <121918198+ulic-youthlic@users.noreply.github.com> Date: Thu, 20 Feb 2025 20:05:34 +0800 Subject: [PATCH] ci: add more fmt check for ci (#24) Co-authored-by: pk5ls20 --- .cargo/config.toml | 2 +- .justfile | 74 +++++++++++++++++++++++++++++++++ .rustfmt.toml | 1 + README.MD | 19 +++++---- flake.nix | 64 +++++++++++++++++++++++++--- mania/src/core/protos/README.MD | 4 +- rust-toolchain.toml | 2 +- scripts/pre-commit | 22 +--------- scripts/pre-push | 34 +-------------- 9 files changed, 152 insertions(+), 70 deletions(-) create mode 100644 .justfile diff --git a/.cargo/config.toml b/.cargo/config.toml index 2a60493..57747f7 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,2 @@ [target.x86_64-pc-windows-msvc] -linker = "rust-lld" \ No newline at end of file +linker = "rust-lld" diff --git a/.justfile b/.justfile new file mode 100644 index 0000000..9cae063 --- /dev/null +++ b/.justfile @@ -0,0 +1,74 @@ +default: + @just --list + +info: + @echo JUST PATH: {{ just_executable() }} + @echo GIT PATH: {{ require('git') }} + @echo CARGO PATH: {{ require('cargo') }} + @echo GREP PATH: {{ require('grep') }} + @echo XARGS PATH: {{ require('xargs') }} + @echo TYPOS PATH: {{ require('typos') }} + @echo DENO PATH: {{ require('deno') }} + @echo TAPLO PATH: {{ require('taplo') }} + @echo SHFMT PATH: {{ require('shfmt') }} + +check: info typoCheck fmtCheck clippyCheck buildCheck docCheck testCheck + +typoCheck: + typos -c ./typos.toml + +fmtCheck: rustFmtCheck justFmtCheck mdFmtCheck tomlFmtCheck ymlFmtCheck shFmtCheck + +fmt: rustFmt justFmt mdFmt tomlFmt ymlFmt shFmt + +buildCheck: + cargo build --locked + +clippyCheck: + cargo clippy --locked --all-targets -- --deny warnings + +docCheck: + cargo doc --no-deps --locked + +testCheck: + cargo test --locked + +rustFmtCheck: + cargo fmt --check + +rustFmt: + cargo fmt + +justFmtCheck: + just --unstable --fmt --check + +justFmt: + just --unstable --fmt + +mdFmtCheck: + git ls-files | grep -E '^.*\.(md|MD)$' | xargs deno fmt --check --ext md + +mdFmt: + git ls-files | grep -E '^.*\.(md|MD)$' | xargs deno fmt --ext md + +ymlFmtCheck: + git ls-files | grep -E '^.*\.yml$' | xargs deno fmt --check --ext yml + +ymlFmt: + git ls-files | grep -E '^.*\.yml$' | xargs deno fmt --ext yml + +tomlFmtCheck: + git ls-files | grep -E '^.*\.toml$' | xargs taplo format --check + +tomlFmt: + git ls-files | grep -E '^.*\.toml$' | xargs taplo format + +shFmt: + git ls-files | grep -E '^scripts/.*$' | xargs shfmt -p -s -i 2 -ci -sr -kp -fn -w + +shFmtCheck: + git ls-files | grep -E '^scripts/.*$' | xargs shfmt -p -s -i 2 -ci -sr -kp -fn -d + +alias c := check +alias i := info +alias f := fmt diff --git a/.rustfmt.toml b/.rustfmt.toml index e69de29..8b13789 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -0,0 +1 @@ + diff --git a/README.MD b/README.MD index 65d8086..6952b06 100644 --- a/README.MD +++ b/README.MD @@ -8,20 +8,21 @@ > [!NOTE]\ -> This project is originally frozen in [radicle](https://app.radicle.xyz/nodes/seed.radicle.garden/rad:z4QZVPDxLbGgd1oHFsjtJLQYtZ8ma) - - -> [!WARNING] -> This project is still in active development. The internal and external interfaces are still unstable +> This project is originally frozen in +> [radicle](https://app.radicle.xyz/nodes/seed.radicle.garden/rad:z4QZVPDxLbGgd1oHFsjtJLQYtZ8ma) +> [!WARNING]\ +> This project is still in active development. The internal and external +> interfaces are still unstable ## Disclaimer + [See Lagrange.Core](https://github.com/LagrangeDev/Lagrange.Core#disclaimer) ## Features List | Protocol | Support | Login | Support | Messages | Support | Operations | Support | Events | Support | -|----------|:-------:|--------------------------------|:-------:|:--------------|:-------:|:------------------|:-------:|:--------------------|:-------:| +| -------- | :-----: | ------------------------------ | :-----: | :------------ | :-----: | :---------------- | :-----: | :------------------ | :-----: | | Windows | 🔴 | QrCode | 🟢 | BounceFace | 🔴 | Poke | 🔴 | ~~Captcha~~ | 🔴 | | macOS | 🔴 | ~~Password~~ | 🔴 | Face | 🟡 [^1] | Recall | 🔴 | BotOnline | 🟢 | | Linux | 🟢 | EasyLogin | 🟡 | File | 🟡[^1] | Leave Group | 🔴 | BotOffline | 🟢 | @@ -47,6 +48,8 @@ [^1]: Only implemented event parsing ## References -- All projects in [LagrangeDev](https://github.com/lagrangeDev) (and their twin projects) + +- All projects in [LagrangeDev](https://github.com/lagrangeDev) (and their twin + projects) - [lz1998/ricq](https://github.com/lz1998/ricq) -- [inmes-dev/qqbot.rs](https://github.com/inmes-dev/qqbot.rs) \ No newline at end of file +- [inmes-dev/qqbot.rs](https://github.com/inmes-dev/qqbot.rs) diff --git a/flake.nix b/flake.nix index 3976319..6adc42b 100644 --- a/flake.nix +++ b/flake.nix @@ -102,17 +102,65 @@ }; }; cargoArtifacts = craneLib.buildDepsOnly commonArgs; - checkTypo = + typoCheck = pkgs.runCommandNoCCLocal "check-typo" { src = ./.; - nativeBuildInputs = with pkgs; [ typos ]; + nativeBuildInputs = with pkgs; [ + typos + ]; } '' mkdir -p $out - cd $src && typos -c $src/typos.toml + cd $src + typos --config ./typos.toml ''; + fmtCheck = + let + restFmtCheck = + pkgs.runCommandNoCCLocal "check-fmt" + { + src = ./.; + nativeBuildInputs = with pkgs; [ + taplo + nixfmt-rfc-style + deno + just + shfmt + ]; + } + '' + mkdir -p $out + + cd $src + # just + echo '==> just format check' + just --unstable --fmt --check + # markdown + echo '==> markdown format check' + find . -type f -regextype egrep -regex '^.*\.(md|MD)$' -exec deno fmt --check --ext md {} + + # toml + echo '==> toml format check' + find . -type f -regextype egrep -regex '^.*\.toml$' -exec taplo format --check {} + + # yaml + echo '==> yaml format check' + find . -type f -regextype egrep -regex '^.*\.yml$' -exec deno fmt --check --ext yml {} + + # nix + echo '==> nix format check' + find . -type f -regextype egrep -regex '^.*\.nix$' -exec nixfmt --check {} + + # sh + echo '==> sh format check' + cd ./scripts && find . -type f -executable -exec shfmt -p -s -d -i 2 -ci -sr -kp -fn '{}' + + ''; + in + pkgs.symlinkJoin { + name = "fmtCheck"; + paths = [ + restFmtCheck + (craneLib.cargoFmt commonArgs) + ]; + }; in { packages = { @@ -134,7 +182,7 @@ }; checks = { inherit (self.packages."${system}") mania; - typo = checkTypo; + typo = typoCheck; audit = craneLib.cargoAudit ( commonArgs // { @@ -148,7 +196,7 @@ cargoClippyExtraArgs = "--all-targets -- --deny warnings"; } ); - fmt = craneLib.cargoFmt commonArgs; + fmt = fmtCheck; doc = craneLib.cargoDoc ( commonArgs // { @@ -169,6 +217,12 @@ cargo-flamegraph cargo-tarpaulin lldb + + taplo + nixfmt-rfc-style + deno + just + shfmt ]; shellHook = ''''; }; diff --git a/mania/src/core/protos/README.MD b/mania/src/core/protos/README.MD index 918e89f..94ee472 100644 --- a/mania/src/core/protos/README.MD +++ b/mania/src/core/protos/README.MD @@ -1,2 +1,4 @@ ## Protos -The vast majority of the proto files originate from [LagrangeDev/LagrangeProto](https://github.com/LagrangeDev/LagrangeProto). \ No newline at end of file + +The vast majority of the proto files originate from +[LagrangeDev/LagrangeProto](https://github.com/LagrangeDev/LagrangeProto). diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 271800c..5d56faf 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "nightly" \ No newline at end of file +channel = "nightly" diff --git a/scripts/pre-commit b/scripts/pre-commit index d6f2bd3..6afab2e 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -2,24 +2,4 @@ set -o errexit set -o nounset -BLUE="\033[0;34m" -RED="\033[0;31m" -NC="\033[0m" -log() { - printf "%b==>%b %s\n" "$1" "$2" "$3" -} -raise_error() { - log "$RED" "$NC" "$1" 1>&2 - exit 1 -} -info() { - log "$BLUE" "$NC" "$1" -} - -info "Running typos..." -typos -c typos.toml || raise_error "Typos check failed!" - -info "Checking code formatting..." -cargo fmt --check || raise_error "Code formatting issues found. Please run 'cargo fmt' to format your code." - -info "Pre-commit checks passed!" +just info typoCheck fmtCheck diff --git a/scripts/pre-push b/scripts/pre-push index 6b0b341..52b5184 100755 --- a/scripts/pre-push +++ b/scripts/pre-push @@ -2,36 +2,4 @@ set -o errexit set -o nounset -BLUE="\033[0;34m" -RED="\033[0;31m" -NC="\033[0m" -log() { - printf "%b==>%b %s\n" "$1" "$2" "$3" -} -raise_error() { - log "$RED" "$NC" "$1" 1>&2 - exit 1 -} -info() { - log "$BLUE" "$NC" "$1" -} - -info "Running typos..." -typos -c typos.toml || raise_error "Typos check failed!" - -info "Checking code formatting..." -cargo fmt --check || raise_error "Code formatting issues found. Please run 'cargo fmt' to format your code." - -info "Building project..." -cargo build --locked || raise_error "Build failed!" - -info "Running cargo clippy..." -cargo clippy --locked --all-targets -- --deny warnings || raise_error "Clippy check failed!" - -info "Building documentation..." -cargo doc --no-deps --locked || raise_error "Documentation build failed!" - -info "Running tests..." -cargo test --locked || raise_error "Tests failed!" - -info "Pre-push checks passed!" +just check