mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-28 07:14:40 +08:00
feat: refactor Makefile.toml to consolidate Rust tasks and update pre-commit checks
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
if ! command -v "cargo-make" >/dev/null 2>&1; then
|
||||
echo "❌ cargo-make is required for pre-push checks."
|
||||
cargo install --force cargo-make
|
||||
fi
|
||||
|
||||
ROOT_DIR="$(git rev-parse --show-toplevel)"
|
||||
cd "$ROOT_DIR"
|
||||
|
||||
@@ -25,22 +30,8 @@ pnpm format
|
||||
echo "[pre-commit] Running lint-staged for JS/TS files..."
|
||||
pnpm exec lint-staged
|
||||
|
||||
RUST_FILES="$(git diff --cached --name-only --diff-filter=ACMR | grep -E '^src-tauri/.*\.rs$' || true)"
|
||||
if [ -n "$RUST_FILES" ]; then
|
||||
echo "[pre-commit] Formatting Rust changes with cargo fmt..."
|
||||
cargo fmt
|
||||
while IFS= read -r file; do
|
||||
[ -n "$file" ] && git add "$file"
|
||||
done <<< "$RUST_FILES"
|
||||
|
||||
echo "[pre-commit] Linting Rust changes with cargo clippy..."
|
||||
cargo clippy-all
|
||||
if ! command -v clash-verge-logging-check >/dev/null 2>&1; then
|
||||
echo "[pre-commit] Installing clash-verge-logging-check..."
|
||||
cargo install --git https://github.com/clash-verge-rev/clash-verge-logging-check.git
|
||||
fi
|
||||
clash-verge-logging-check
|
||||
fi
|
||||
cargo make pre-commit
|
||||
|
||||
TS_FILES="$(git diff --cached --name-only --diff-filter=ACMR | grep -E '\.(ts|tsx)$' || true)"
|
||||
if [ -n "$TS_FILES" ]; then
|
||||
|
||||
@@ -10,27 +10,11 @@ skip_crate_env_info = true
|
||||
install_crate = "rustfmt"
|
||||
command = "cargo"
|
||||
args = ["fmt", "--", "--emit=files"]
|
||||
[tasks.rust-format.condition]
|
||||
files_modified = { input = [
|
||||
"./src-tauri/**/*.rs",
|
||||
"./crates/**/*.rs",
|
||||
"**/Cargo.toml",
|
||||
], output = [
|
||||
"./target/**/clash-verge",
|
||||
] }
|
||||
|
||||
[tasks.rust-clippy]
|
||||
description = "Run cargo clippy to lint the code"
|
||||
command = "cargo"
|
||||
args = ["clippy", "--all-targets", "--all-features", "--", "-D", "warnings"]
|
||||
[tasks.rust-clippy.condition]
|
||||
files_modified = { input = [
|
||||
"./src-tauri/**/*.rs",
|
||||
"./crates/**/*.rs",
|
||||
"**/Cargo.toml",
|
||||
], output = [
|
||||
"./target/**/clash-verge",
|
||||
] }
|
||||
|
||||
# --- Frontend ---
|
||||
|
||||
@@ -72,14 +56,23 @@ files_modified = { input = [
|
||||
"./node_modules/.last_typecheck",
|
||||
] }
|
||||
|
||||
# --- Hook ---
|
||||
# --- Jobs ---
|
||||
[tasks.rust]
|
||||
dependencies = ["rust-format", "rust-clippy"]
|
||||
[tasks.rust.condition]
|
||||
files_modified = { input = [
|
||||
"./src-tauri/**/*.rs",
|
||||
"./crates/**/*.rs",
|
||||
"**/Cargo.toml",
|
||||
], output = [
|
||||
"./target/**/clash-verge",
|
||||
] }
|
||||
# TODO add frontend jobs conditions
|
||||
|
||||
|
||||
[tasks.pre-push]
|
||||
description = "Pre-push checks"
|
||||
dependencies = [
|
||||
"rust-format",
|
||||
"rust-clippy",
|
||||
"format-check",
|
||||
"eslint",
|
||||
"typecheck",
|
||||
]
|
||||
dependencies = ["rust", "format-check", "eslint", "typecheck"]
|
||||
|
||||
[tasks.pre-commit]
|
||||
dependencies = ["rust"]
|
||||
|
||||
Reference in New Issue
Block a user