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.
# 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
- Use the bare expression form: if: github.event_name == 'push'.
- Or wrap explicitly: if: \${{ github.event_name == 'push' && success() }}.
- Do not quote the whole condition string.
steps:
- name: Deploy
if: ${{ github.ref == 'refs/heads/main' && success() }}
run: ./deploy.shHow 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.