mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-28 07:14:40 +08:00
feat: implement git-hook using cargo make and add Makefile.toml (#5498)
* feat: implement pre-push checks using cargo make and add Makefile.toml for task management * feat: enhance Makefile.toml with condition checks for tasks and improve clippy args * fix: update file patterns for format-check task in Makefile.toml * feat: update file patterns for eslint and typecheck tasks in Makefile.toml * feat: refactor Makefile.toml to consolidate Rust tasks and update pre-commit checks * feat: update Makefile.toml to add i18n-check and lint-staged tasks; modify pre-commit script * feat: update Makefile.toml to add i18n-check and lint-staged tasks; modify pre-commit script * refactor: simplify Makefile.toml by removing unused conditions and consolidating dependencies * feat: update Makefile.toml to define Rust and frontend tasks for pre-commit and pre-push checks * chore: remove unnecessary tasks * chore: add windows override * chore: remove format and format-check --------- Co-authored-by: Slinetrac <realakayuki@gmail.com>
This commit is contained in:
@@ -1,51 +1,14 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
ROOT_DIR="$(git rev-parse --show-toplevel)"
|
if ! command -v "cargo-make" >/dev/null 2>&1; then
|
||||||
cd "$ROOT_DIR"
|
echo "❌ cargo-make is required for pre-commit checks."
|
||||||
|
cargo install --force cargo-make
|
||||||
|
fi
|
||||||
|
|
||||||
if ! command -v pnpm >/dev/null 2>&1; then
|
if ! command -v pnpm >/dev/null 2>&1; then
|
||||||
echo "❌ pnpm is required for pre-commit checks."
|
echo "❌ pnpm is required for pre-commit checks."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
LOCALE_DIFF="$(git diff --cached --name-only --diff-filter=ACMR | grep -E '^src/locales/' || true)"
|
cargo make pre-commit
|
||||||
if [ -n "$LOCALE_DIFF" ]; then
|
|
||||||
echo "[pre-commit] Locale changes detected. Regenerating i18n types..."
|
|
||||||
pnpm i18n:types
|
|
||||||
if [ -d src/types/generated ]; then
|
|
||||||
echo "[pre-commit] Staging regenerated i18n type artifacts..."
|
|
||||||
git add src/types/generated
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "[pre-commit] Running pnpm format before lint..."
|
|
||||||
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
|
|
||||||
|
|
||||||
TS_FILES="$(git diff --cached --name-only --diff-filter=ACMR | grep -E '\.(ts|tsx)$' || true)"
|
|
||||||
if [ -n "$TS_FILES" ]; then
|
|
||||||
echo "[pre-commit] Running TypeScript type check..."
|
|
||||||
pnpm typecheck
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "[pre-commit] All checks completed successfully."
|
|
||||||
|
|||||||
@@ -1,36 +1,9 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
remote_name="${1:-origin}"
|
if ! command -v "cargo-make" >/dev/null 2>&1; then
|
||||||
remote_url="${2:-unknown}"
|
echo "❌ cargo-make is required for pre-push checks."
|
||||||
|
cargo install --force cargo-make
|
||||||
ROOT_DIR="$(git rev-parse --show-toplevel)"
|
|
||||||
cd "$ROOT_DIR"
|
|
||||||
|
|
||||||
if ! command -v pnpm >/dev/null 2>&1; then
|
|
||||||
echo "❌ pnpm is required for pre-push checks."
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "[pre-push] Preparing to push to '$remote_name' ($remote_url). Running full validation..."
|
cargo make pre-push
|
||||||
|
|
||||||
echo "[pre-push] Checking Prettier formatting..."
|
|
||||||
pnpm format:check
|
|
||||||
|
|
||||||
echo "[pre-push] Running ESLint..."
|
|
||||||
pnpm lint
|
|
||||||
|
|
||||||
echo "[pre-push] Running TypeScript type checking..."
|
|
||||||
pnpm typecheck
|
|
||||||
|
|
||||||
if command -v cargo >/dev/null 2>&1; then
|
|
||||||
echo "[pre-push] Verifying Rust formatting..."
|
|
||||||
cargo fmt --check
|
|
||||||
|
|
||||||
echo "[pre-push] Running cargo clippy..."
|
|
||||||
cargo clippy-all
|
|
||||||
else
|
|
||||||
echo "[pre-push] ⚠️ cargo not found; skipping Rust checks."
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "[pre-push] All checks passed."
|
|
||||||
|
|||||||
86
Makefile.toml
Normal file
86
Makefile.toml
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
[config]
|
||||||
|
skip_core_tasks = true
|
||||||
|
skip_git_env_info = true
|
||||||
|
skip_rust_env_info = true
|
||||||
|
skip_crate_env_info = true
|
||||||
|
|
||||||
|
# --- Backend ---
|
||||||
|
|
||||||
|
[tasks.rust-format]
|
||||||
|
install_crate = "rustfmt"
|
||||||
|
command = "cargo"
|
||||||
|
args = ["fmt", "--", "--emit=files"]
|
||||||
|
|
||||||
|
[tasks.rust-clippy]
|
||||||
|
description = "Run cargo clippy to lint the code"
|
||||||
|
command = "cargo"
|
||||||
|
args = ["clippy", "--all-targets", "--all-features", "--", "-D", "warnings"]
|
||||||
|
|
||||||
|
# --- Frontend ---
|
||||||
|
|
||||||
|
[tasks.eslint]
|
||||||
|
description = "Run ESLint to lint the code"
|
||||||
|
command = "pnpm"
|
||||||
|
args = ["lint"]
|
||||||
|
[tasks.eslint.windows]
|
||||||
|
command = "pnpm.cmd"
|
||||||
|
|
||||||
|
[tasks.typecheck]
|
||||||
|
description = "Run type checks"
|
||||||
|
command = "pnpm"
|
||||||
|
args = ["typecheck"]
|
||||||
|
[tasks.typecheck.windows]
|
||||||
|
command = "pnpm.cmd"
|
||||||
|
|
||||||
|
[tasks.lint-staged]
|
||||||
|
description = "Run lint-staged for staged files"
|
||||||
|
command = "pnpm"
|
||||||
|
args = ["exec", "lint-staged"]
|
||||||
|
[tasks.lint-staged.windows]
|
||||||
|
command = "pnpm.cmd"
|
||||||
|
|
||||||
|
# --- Jobs ---
|
||||||
|
|
||||||
|
# Rust format (for pre-commit)
|
||||||
|
[tasks.rust-format-check]
|
||||||
|
description = "Check Rust code formatting"
|
||||||
|
dependencies = ["rust-format"]
|
||||||
|
[tasks.rust-format-check.condition]
|
||||||
|
files_modified.input = [
|
||||||
|
"./src-tauri/**/*.rs",
|
||||||
|
"./crates/**/*.rs",
|
||||||
|
"**/Cargo.toml",
|
||||||
|
]
|
||||||
|
files_modified.output = ["./target/debug/*", "./target/release/*"]
|
||||||
|
|
||||||
|
# Rust lint (for pre-push)
|
||||||
|
[tasks.rust-lint]
|
||||||
|
description = "Run Rust linting"
|
||||||
|
dependencies = ["rust-clippy"]
|
||||||
|
[tasks.rust-lint.condition]
|
||||||
|
files_modified.input = [
|
||||||
|
"./src-tauri/**/*.rs",
|
||||||
|
"./crates/**/*.rs",
|
||||||
|
"**/Cargo.toml",
|
||||||
|
]
|
||||||
|
files_modified.output = ["./target/debug/*", "./target/release/*"]
|
||||||
|
|
||||||
|
# Frontend format (for pre-commit)
|
||||||
|
[tasks.frontend-format]
|
||||||
|
description = "Frontend format checks"
|
||||||
|
dependencies = ["lint-staged"]
|
||||||
|
|
||||||
|
# Frontend lint (for pre-push)
|
||||||
|
[tasks.frontend-lint]
|
||||||
|
description = "Frontend linting and type checking"
|
||||||
|
dependencies = ["eslint", "typecheck"]
|
||||||
|
|
||||||
|
# --- Git Hooks ---
|
||||||
|
|
||||||
|
[tasks.pre-commit]
|
||||||
|
description = "Pre-commit checks: format only"
|
||||||
|
dependencies = ["rust-format-check", "frontend-format"]
|
||||||
|
|
||||||
|
[tasks.pre-push]
|
||||||
|
description = "Pre-push checks: lint and typecheck"
|
||||||
|
dependencies = ["rust-lint", "frontend-lint"]
|
||||||
Reference in New Issue
Block a user