veza/.husky/pre-commit
senke 4ee8c38536
Some checks failed
Veza CI / Backend (Go) (push) Failing after 0s
Veza CI / Frontend (Web) (push) Failing after 0s
Veza CI / Rust (Stream Server) (push) Failing after 0s
Frontend CI / test (push) Failing after 0s
Security Scan / Secret Scanning (gitleaks) (push) Failing after 0s
Veza CI / Notify on failure (push) Failing after 0s
feat(ci): enforce OpenAPI type sync — drift prevention (v1.0.8 P0)
Phase 0 of the OpenAPI typegen migration. Locks in the existing
check-types-sync.sh (which was committed but never wired) so we stop
accumulating drift between veza-backend-api/openapi.yaml and
apps/web/src/types/generated/ before we migrate to orval (Phase 1).

Three enforcement points:

1. Pre-commit hook (.husky/pre-commit)
   Replaces the naked generate-types.sh call with check-types-sync.sh,
   which regenerates and fails if the working tree differs. Skippable
   via SKIP_TYPES=1 (already documented in CLAUDE.md) for emergency
   commits and for environments without node_modules.

2. CI gate (.github/workflows/frontend-ci.yml)
   New "Check OpenAPI types in sync" step before lint/build. Catches
   PRs that touched openapi.yaml without regenerating types.
   Expanded the paths trigger to include veza-backend-api/openapi.yaml
   and docs/swagger.yaml so spec-only edits still run the check.

3. Makefile target (make openapi-check)
   Local convenience — same check as CI/hook, callable without staging
   anything. Pairs with existing `make openapi` (regenerate spec from
   swaggo annotations).

No spec or type file changes in this commit — pure plumbing.

Refs:
- AUDIT_REPORT.md §9 item #8 (OpenAPI typegen, deferred v1.0.8)
- Memory: project_next_priority_openapi_client.md
- /home/senke/.claude/plans/audit-fonctionnel-wild-hickey.md Item 2 Phase 0

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-23 20:33:13 +02:00

47 lines
2.1 KiB
Bash
Executable file

#!/usr/bin/env sh
# Each step runs in a subshell so the cd does not leak across steps.
# Pre-commit runs from the repo root; every cd below is relative to that.
# Drift guard: ensure apps/web/src/types/generated/ matches
# veza-backend-api/openapi.yaml. Regenerates locally then fails if the
# committed types don't match the freshly-regenerated output.
# Skip with SKIP_TYPES=1 for emergency commits (documented in CLAUDE.md).
if [ -z "$SKIP_TYPES" ]; then
(cd apps/web && bash scripts/check-types-sync.sh) || {
echo "❌ OpenAPI types are out of sync with veza-backend-api/openapi.yaml."
echo "💡 Run: make openapi && cd apps/web && bash scripts/generate-types.sh"
echo "💡 Then stage the updated src/types/generated/ and retry."
echo "💡 Tip: SKIP_TYPES=1 bypasses (not recommended)."
exit 1
}
fi
# Implicit 10.1: Type checking
# Prevent commits with TypeScript errors (warnings are allowed)
(cd apps/web && npm run typecheck 2>&1 | grep -q "error TS") && {
echo "❌ Type checking failed. Please fix TypeScript errors before committing."
echo "💡 Run 'npm run typecheck' to see all errors."
exit 1
} || true
# Implicit 10.2: Linting
# Prevent commits with linting errors (warnings are allowed).
# Pattern matches "(N error" with N>=1 in ESLint's summary line —
# avoids false positive on "(0 errors, K warnings)".
(cd apps/web && npm run lint 2>&1 | grep -qE "\([1-9][0-9]* error") && {
echo "❌ Linting failed. Please fix linting errors before committing."
echo "💡 Tip: Run 'npm run lint:fix' to automatically fix some issues."
exit 1
} || true
# Implicit 10.3: Test checking (optional, fast unit tests only)
# Skip if SKIP_TESTS environment variable is set (for quick commits)
# Only runs unit tests (not E2E) to keep it fast
if [ -z "$SKIP_TESTS" ]; then
(cd apps/web && npm test -- --run 2>&1 | grep -q "FAIL") && {
echo "❌ Tests failed. Please fix failing tests before committing."
echo "💡 Tip: Run 'npm test' to see all test failures."
echo "💡 Tip: Set SKIP_TESTS=1 to skip tests for this commit (not recommended)."
exit 1
} || true
fi