Client-side hooks (Husky): chạy trên máy developer.
- pre-commit: lint, format, type-check
- commit-msg: commitlint
- pre-push: unit tests
- Có thể bypass: git commit --no-verify, git push --no-verify
- Share được qua git (Husky v7+ lưu hook files trong .husky/ — committed vào repo, cài tự động qua npm prepare; .git/hooks/ vẫn là client-side và vẫn bypassable)
Server-side hooks (GitHub Actions/CI): chạy trên server, developer không thể bypass.
yaml
# .github/workflows/ci.yml
on: [pull_request]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm run lint
- run: npm run typecheck
- run: npm run test
- run: npx commitlint --from ${{ github.event.pull_request.base.sha }}Phân chia trách nhiệm:
| Task | Client Hook | Server Hook |
|---|---|---|
| Fast lint/format | pre-commit ✓ | không cần |
| Type check | pre-commit ✓ | CI backup ✓ |
| Unit tests | pre-push ✓ | CI ✓ |
| Integration tests | không | CI ✓ |
| Commit message | commit-msg ✓ | CI ✓ |
| Security scan | không | CI ✓ |
Nguyên tắc: client hooks = fast feedback loop cho developer, server hooks = enforcement không thể bypass. Không dùng client hooks thay thế server hooks — chỉ dùng bổ sung.