From 936764e6ce7436a848e4764776690318d898bb64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9D=A4=E6=98=AF=E7=BA=B1=E9=9B=BE=E9=85=B1=E5=93=9F?= =?UTF-8?q?=EF=BD=9E?= <49941141+Dragon1573@users.noreply.github.com> Date: Thu, 9 Oct 2025 05:10:03 +0800 Subject: [PATCH] feat: Enable git hooks with husky (#4984) * build(deps): Adds husky for Git hooks - Integrates the husky package as a development dependency. - Enables the configuration and enforcement of pre-commit and pre-push Git hooks. - Improves code quality and consistency by automating checks before commits. Signed-off-by: Dragon1573 <49941141+Dragon1573@users.noreply.github.com> * feat: Add Husky prepare hook - Automatically installs Git hooks for developers - Ensures consistent code quality checks before commits or pushes - Streamlines the developer setup process Signed-off-by: Dragon1573 <49941141+Dragon1573@users.noreply.github.com> * ci: Avoid installing Git Hooks on GitHub Workflows - Adds `HUSKY: 0` environment variable to all workflow definitions. - Prevents local development hooks from executing in CI, which can cause unnecessary failures or overhead. - See https://typicode.github.io/husky/how-to.html#ci-server-and-docker Signed-off-by: Dragon1573 <49941141+Dragon1573@users.noreply.github.com> --------- Signed-off-by: Dragon1573 <49941141+Dragon1573@users.noreply.github.com> --- .github/workflows/alpha.yml | 1 + .github/workflows/autobuild.yml | 1 + .github/workflows/cross_check.yaml | 3 +++ .github/workflows/dev.yml | 1 + .github/workflows/fmt.yml | 3 +++ .github/workflows/lint-clippy.yml | 2 ++ .github/workflows/release.yml | 1 + .github/workflows/updater.yml | 3 +++ package.json | 2 ++ pnpm-lock.yaml | 10 ++++++++++ 10 files changed, 27 insertions(+) diff --git a/.github/workflows/alpha.yml b/.github/workflows/alpha.yml index 41dcec4d..8f983698 100644 --- a/.github/workflows/alpha.yml +++ b/.github/workflows/alpha.yml @@ -25,6 +25,7 @@ env: TAG_CHANNEL: Alpha CARGO_INCREMENTAL: 0 RUST_BACKTRACE: short + HUSKY: 0 concurrency: group: "${{ github.workflow }} - ${{ github.head_ref || github.ref }}" diff --git a/.github/workflows/autobuild.yml b/.github/workflows/autobuild.yml index f35eda2f..f48788c5 100644 --- a/.github/workflows/autobuild.yml +++ b/.github/workflows/autobuild.yml @@ -11,6 +11,7 @@ env: TAG_CHANNEL: AutoBuild CARGO_INCREMENTAL: 0 RUST_BACKTRACE: short + HUSKY: 0 concurrency: group: "${{ github.workflow }} - ${{ github.head_ref || github.ref }}" cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} diff --git a/.github/workflows/cross_check.yaml b/.github/workflows/cross_check.yaml index e00099c4..03a65bf1 100644 --- a/.github/workflows/cross_check.yaml +++ b/.github/workflows/cross_check.yaml @@ -9,6 +9,9 @@ on: permissions: contents: read +env: + HUSKY: 0 + jobs: cargo-check: # Treat all Rust compiler warnings as errors diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index b078aa0d..336c5e42 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -30,6 +30,7 @@ env: TAG_CHANNEL: DeployTest CARGO_INCREMENTAL: 0 RUST_BACKTRACE: short + HUSKY: 0 concurrency: group: "${{ github.workflow }} - ${{ github.head_ref || github.ref }}" cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} diff --git a/.github/workflows/fmt.yml b/.github/workflows/fmt.yml index 5ec2ca9a..58efc98b 100644 --- a/.github/workflows/fmt.yml +++ b/.github/workflows/fmt.yml @@ -7,6 +7,9 @@ name: Check Formatting on: pull_request: +env: + HUSKY: 0 + jobs: rustfmt: runs-on: ubuntu-latest diff --git a/.github/workflows/lint-clippy.yml b/.github/workflows/lint-clippy.yml index 6bc0bf33..e987a37e 100644 --- a/.github/workflows/lint-clippy.yml +++ b/.github/workflows/lint-clippy.yml @@ -3,6 +3,8 @@ name: Clippy Lint on: pull_request: workflow_dispatch: +env: + HUSKY: 0 jobs: clippy: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index da80b04d..7f74de0d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,6 +11,7 @@ permissions: write-all env: CARGO_INCREMENTAL: 0 RUST_BACKTRACE: short + HUSKY: 0 concurrency: # only allow per workflow per commit (and not pr) to run at a time group: "${{ github.workflow }} - ${{ github.head_ref || github.ref }}" diff --git a/.github/workflows/updater.yml b/.github/workflows/updater.yml index 813b8fa6..d482bc60 100644 --- a/.github/workflows/updater.yml +++ b/.github/workflows/updater.yml @@ -2,6 +2,9 @@ name: Updater CI on: workflow_dispatch permissions: write-all +env: + HUSKY: 0 + jobs: release-update: runs-on: ubuntu-latest diff --git a/package.json b/package.json index bc15e2cb..76ac3504 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "2.4.3", "license": "GPL-3.0-only", "scripts": { + "prepare": "husky || true", "dev": "cross-env RUST_BACKTRACE=full tauri dev -f verge-dev", "dev:diff": "cross-env RUST_BACKTRACE=full tauri dev -f verge-dev", "dev:trace": "cross-env RUST_BACKTRACE=full RUSTFLAGS=\"--cfg tokio_unstable\" tauri dev -f verge-dev tokio-trace", @@ -105,6 +106,7 @@ "glob": "^11.0.3", "globals": "^16.4.0", "https-proxy-agent": "^7.0.6", + "husky": "^9.1.7", "jiti": "^2.6.1", "lint-staged": "^16.2.3", "meta-json-schema": "^1.19.14", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index da01e942..5b1a521d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -213,6 +213,9 @@ importers: https-proxy-agent: specifier: ^7.0.6 version: 7.0.6 + husky: + specifier: ^9.1.7 + version: 9.1.7 jiti: specifier: ^2.6.1 version: 2.6.1 @@ -2832,6 +2835,11 @@ packages: resolution: {integrity: sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw==} engines: {node: '>= 14'} + husky@9.1.7: + resolution: {integrity: sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==} + engines: {node: '>=18'} + hasBin: true + i18next@25.5.3: resolution: {integrity: sha512-joFqorDeQ6YpIXni944upwnuHBf5IoPMuqAchGVeQLdWC2JOjxgM9V8UGLhNIIH/Q8QleRxIi0BSRQehSrDLcg==} peerDependencies: @@ -7163,6 +7171,8 @@ snapshots: transitivePeerDependencies: - supports-color + husky@9.1.7: {} + i18next@25.5.3(typescript@5.9.3): dependencies: '@babel/runtime': 7.28.4