Skip to content
Latchkey

How to Fail CI on Stray console.log Statements in GitHub Actions

A forgotten console.log leaks into production and clutters logs; a tiny CI check stops it at the PR.

Grep the source tree for console.log (excluding tests and vendored code) and exit non-zero when any match is found.

Steps

  • Restrict the search to source directories so tests and node_modules are skipped.
  • Run grep -rn "console.log" src and invert the exit code so a match fails.
  • Prefer the ESLint no-console rule for a real codebase; grep is the zero-config fallback.

Workflow

.github/workflows/no-console.yml
name: No console.log
on: [pull_request]
jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Fail on console.log
        run: |
          if grep -rn --include='*.ts' --include='*.tsx' 'console\.log' src; then
            echo "::error::Remove console.log before merging"
            exit 1
          fi

Notes

  • The ::error:: workflow command marks the run with a clear message in the checks UI.
  • On Latchkey managed runners these guard checks run cheaper and self-heal if a runner drops.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →