Skip to content
Latchkey

GitHub Actions if condition always runs (string vs expression)

GitHub Actions treats a non-empty if value as a truthy string unless it is a real expression. Writing if: github.ref == 'refs/heads/main' without \${{ }} can still evaluate, but a malformed or quoted condition silently becomes "always run".

What this error means

A step or job that should be conditional runs on every event. There is no error; the condition is just always true because it is parsed as a constant string.

github-actions
# This ALWAYS runs - the whole thing is a literal string, not evaluated
if: "github.event_name == 'push' && success()"

Common causes

Condition wrapped so it reads as a literal

Quoting the entire condition or omitting expression syntax can turn it into a constant truthy string.

Non-empty string is truthy

Any non-empty if value that is not a false expression evaluates as true.

How to fix it

Write a proper expression condition

  1. Use the bare expression form: if: github.event_name == 'push'.
  2. Or wrap explicitly: if: \${{ github.event_name == 'push' && success() }}.
  3. Do not quote the whole condition string.
.github/workflows/ci.yml
steps:
  - name: Deploy
    if: ${{ github.ref == 'refs/heads/main' && success() }}
    run: ./deploy.sh

How to prevent it

  • Prefer the \${{ }} form for non-trivial conditions to make intent explicit.
  • Test conditions on a branch and confirm the step skips when expected.

Frequently asked questions

What causes "if condition always runs"?
Quoting the entire condition or omitting expression syntax can turn it into a constant truthy string.
How do I fix if condition always runs?
Write a proper expression condition

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card