mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
chore: better pre-hooks
This commit is contained in:
@@ -1,24 +1,39 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
echo "[pre-commit] Running lint-staged for JS/TS files..."
|
ROOT_DIR="$(git rev-parse --show-toplevel)"
|
||||||
# Auto-fix staged JS/TS files, print warnings but don't fail commit
|
cd "$ROOT_DIR"
|
||||||
npx lint-staged || true
|
|
||||||
|
|
||||||
# Check staged Rust files
|
if ! command -v pnpm >/dev/null 2>&1; then
|
||||||
RUST_FILES=$(git diff --cached --name-only | grep -E '^src-tauri/.*\.rs$' || true)
|
echo "❌ pnpm is required for pre-commit checks."
|
||||||
if [ -n "$RUST_FILES" ]; then
|
exit 1
|
||||||
echo "[pre-commit] Running rustfmt and clippy on staged Rust files..."
|
|
||||||
cd src-tauri || exit
|
|
||||||
|
|
||||||
# Auto-format Rust code
|
|
||||||
cargo fmt
|
|
||||||
|
|
||||||
# Lint with clippy, print warnings but don't fail commit
|
|
||||||
cargo clippy-all || echo "⚠️ clippy found issues, but commit will continue."
|
|
||||||
|
|
||||||
cd ..
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "[pre-commit] Checks completed. Some warnings may exist, please review."
|
echo "[pre-commit] Running lint-staged for JS/TS files..."
|
||||||
exit 0
|
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..."
|
||||||
|
(
|
||||||
|
cd src-tauri
|
||||||
|
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..."
|
||||||
|
(
|
||||||
|
cd src-tauri
|
||||||
|
cargo clippy-all
|
||||||
|
)
|
||||||
|
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,32 +1,42 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
remote_name="$1"
|
remote_name="${1:-origin}"
|
||||||
|
remote_url="${2:-unknown}"
|
||||||
|
|
||||||
# --- Rust clippy for staged files in src-tauri ---
|
ROOT_DIR="$(git rev-parse --show-toplevel)"
|
||||||
if git diff --cached --name-only | grep -q '^src-tauri/'; then
|
cd "$ROOT_DIR"
|
||||||
echo "[pre-push] Running clippy on src-tauri..."
|
|
||||||
cargo clippy --manifest-path ./src-tauri/Cargo.toml -- -D warnings || {
|
|
||||||
echo "❌ Clippy found issues in src-tauri. Please fix them before pushing."
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
# --- JS/TS format check only for main repo ---
|
if ! command -v pnpm >/dev/null 2>&1; then
|
||||||
if git remote get-url "$remote_name" >/dev/null 2>&1; then
|
echo "❌ pnpm is required for pre-push checks."
|
||||||
remote_url=$(git remote get-url "$remote_name")
|
|
||||||
if [[ "$remote_url" =~ github\.com[:/]+clash-verge-rev/clash-verge-rev(\.git)?$ ]]; then
|
|
||||||
echo "[pre-push] Detected push to clash-verge-rev/clash-verge-rev ($remote_url)"
|
|
||||||
echo "[pre-push] Running pnpm format:check..."
|
|
||||||
if ! pnpm format:check; then
|
|
||||||
echo "❌ Code format check failed. Please fix formatting before pushing."
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "[pre-push] Preparing to push to '$remote_name' ($remote_url). Running full validation..."
|
||||||
|
|
||||||
|
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..."
|
||||||
|
(
|
||||||
|
cd src-tauri
|
||||||
|
cargo fmt --check
|
||||||
|
)
|
||||||
|
|
||||||
|
echo "[pre-push] Running cargo clippy..."
|
||||||
|
(
|
||||||
|
cd src-tauri
|
||||||
|
cargo clippy-all
|
||||||
|
)
|
||||||
else
|
else
|
||||||
echo "[pre-push] Not pushing to target repo. Skipping format check."
|
echo "[pre-push] ⚠️ cargo not found; skipping Rust checks."
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "[pre-push] Remote '$remote_name' does not exist. Skipping format check."
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "[pre-push] All checks passed."
|
echo "[pre-push] All checks passed."
|
||||||
|
|||||||
Reference in New Issue
Block a user