Guide

Fix .env drift in CI with env-doctor

Goal

Make CI fail when .env drifts from .env.example, so a missing key never breaks a deploy again.

Prerequisites

  • env-doctor cloned (see quickstart)
  • A CI workflow file (GitHub Actions example below)

Steps

  1. Reproduce locally:
    python -m env_doctor check --env .env --example .env.example
  2. Fix: add missing keys to .env.example (empty placeholders) or remove dead keys. Add them by hand — do not rely on auto-fix (not implemented yet).
  3. Add to CI:
    - name: Audit .env drift
      run: python -m env_doctor check --env .env --example .env.example --format text
  4. If you have more than one env file pair, repeat the same check for each pair in CI.

Verify

Push a branch that deletes a key from .env.example — CI should fail with a missing-in-env error. Restore the key — CI passes.

Troubleshoot

  • CI fails: read the error lines — fix the missing/duplicate keys they name, then re-run. Warnings alone do not fail the run; triage them by hand (do not auto-fix).
  • False unused-var: --scan only sees the code you point it at — widen the scan path.
  • Secrets in CI logs: never print .env contents in CI. Redact before sharing logs.

Last updated: 2026-10-16. Edit on GitHub · Report an issue

← Previous guide · Next guide →

Still stuck? Get deployment help →