Pre-commit Integration

Use envcheck with pre-commit hooks to catch issues before you commit.

Basic Setup

Install pre-commit:

pip install pre-commit

Create .pre-commit-config.yaml:

repos:
  - repo: https://github.com/envcheck/envcheck
    rev: v0.1.0
    hooks:
      - id: envcheck
        files: '^\.env.*$'

      - id: envcheck-fix
        files: '^\.env.*$'

      - id: envcheck-k8s
        files: '^k8s/.*\.ya?ml$'

Hook IDs

Hook IDDescription
envcheckLint .env files
envcheck-fixAuto-fix .env files
envcheck-k8sCheck Kubernetes sync
envcheck-doctorRun full doctor check

Configuration Examples

Lint all .env files

repos:
  - repo: https://github.com/envcheck/envcheck
    rev: v0.1.0
    hooks:
      - id: envcheck
        args: ['lint', '.env.example', '.env']

Auto-fix on commit

repos:
  - repo: https://github.com/envcheck/envcheck
    rev: v0.1.0
    hooks:
      - id: envcheck-fix
        args: ['--commit']

Kubernetes validation

repos:
  - repo: https://github.com/envcheck/envcheck
    rev: v0.1.0
    hooks:
      - id: envcheck-k8s
        args: ['k8s/**/*.yaml', '--env', '.env.example']
        files: '^k8s/.*\.ya?ml$'

Multiple environments

repos:
  - repo: https://github.com/envcheck/envcheck
    rev: v0.1.0
    hooks:
      - id: envcheck
        name: envcheck (staging)
        args: ['lint', '.env.staging', '--format=github']
        files: '^\.env\.staging$'

      - id: envcheck
        name: envcheck (production)
        args: ['lint', '.env.prod', '--format=github']
        files: '^\.env\.prod$'

Complete .pre-commit-config.yaml

repos:
  # envcheck hooks
  - repo: https://github.com/envcheck/envcheck
    rev: v0.1.0
    hooks:
      - id: envcheck
        name: envcheck lint
        args: ['lint', '.env.example']
        files: '^\.env.*$'

      - id: envcheck-fix
        name: envcheck fix
        args: ['.env.example']

      - id: envcheck-k8s
        name: envcheck k8s sync
        args: ['k8s/**/*.yaml', '--env', '.env.example']
        files: '^k8s/.*\.ya?ml$'

  # Other hooks...
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.5.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer
      - id: check-yaml

Install Hooks

# Install hooks
pre-commit install

# Install hooks for all git hooks (including post-commit)
pre-commit install --hook-type pre-commit \
                  --hook-type pre-push \
                  --hook-type commit-msg

# Run on all files
pre-commit run --all-files

Stage-Specific Hooks

Pre-commit (before committing)

- id: envcheck
  args: ['lint', '.env.example']
  stages: [pre-commit]

Pre-push (before pushing)

- id: envcheck-doctor
  args: ['--all']
  stages: [pre-push]

Skip Hooks

Skip envcheck for a specific commit:

git commit -m "WIP" --no-verify

Or skip only envcheck:

SKIP=envcheck git commit -m "WIP"

See Also