cleanup and Test pre-push hook
This commit is contained in:
78
.githooks/README.md
Normal file
78
.githooks/README.md
Normal file
@@ -0,0 +1,78 @@
|
||||
# Git Hooks
|
||||
|
||||
This directory contains Git hooks for the Portfolio project.
|
||||
|
||||
## Pre-Push Hook
|
||||
|
||||
The pre-push hook runs automatically before every `git push` and performs the following checks:
|
||||
|
||||
### Checks Performed:
|
||||
1. **Node.js Version Check** - Ensures Node.js 20+ is installed
|
||||
2. **Dependency Installation** - Installs npm dependencies if needed
|
||||
3. **Linting** - Runs ESLint to check code quality
|
||||
4. **Tests** - Runs Jest test suite
|
||||
5. **Build** - Builds the Next.js application
|
||||
6. **Security Audit** - Runs npm audit for vulnerabilities
|
||||
7. **Secret Detection** - Checks for accidentally committed secrets
|
||||
8. **Docker Configuration** - Validates Dockerfile and docker-compose.yml
|
||||
9. **Production Checks** - Additional checks when pushing to production branch
|
||||
|
||||
### Production Branch Special Checks:
|
||||
- Environment file validation
|
||||
- Docker build test
|
||||
- Deployment readiness check
|
||||
|
||||
### Usage:
|
||||
|
||||
The hook runs automatically on every push. To manually test it:
|
||||
|
||||
```bash
|
||||
# Test the hook manually
|
||||
.githooks/pre-push
|
||||
|
||||
# Or push to trigger it
|
||||
git push origin main
|
||||
```
|
||||
|
||||
### Bypassing the Hook:
|
||||
|
||||
If you need to bypass the hook in an emergency:
|
||||
|
||||
```bash
|
||||
git push --no-verify origin main
|
||||
```
|
||||
|
||||
**Note**: Only bypass in emergencies. The hook prevents broken code from being pushed.
|
||||
|
||||
### Troubleshooting:
|
||||
|
||||
If the hook fails:
|
||||
|
||||
1. **Fix the reported issues** (linting errors, test failures, etc.)
|
||||
2. **Run the checks manually** to debug:
|
||||
```bash
|
||||
npm run lint
|
||||
npm run test
|
||||
npm run build
|
||||
npm audit
|
||||
```
|
||||
3. **Check Node.js version**: `node --version` (should be 20+)
|
||||
4. **Reinstall dependencies**: `rm -rf node_modules && npm ci`
|
||||
|
||||
### Configuration:
|
||||
|
||||
The hook is configured in `.git/config`:
|
||||
```
|
||||
[core]
|
||||
hooksPath = .githooks
|
||||
```
|
||||
|
||||
To disable hooks temporarily:
|
||||
```bash
|
||||
git config core.hooksPath ""
|
||||
```
|
||||
|
||||
To re-enable:
|
||||
```bash
|
||||
git config core.hooksPath .githooks
|
||||
```
|
||||
Reference in New Issue
Block a user