Conditional skip of a scheduled run by branch in CI
Since a schedule always runs on the default branch, a branch-based if like github.ref == 'refs/heads/develop' will never match under cron. Skip scheduled runs using the event name, the repository, or a job-level guard instead.
What this error means
A step guarded by a branch condition never runs under the schedule, or a scheduled run executes in a fork you did not intend it to run in.
# This never runs on schedule because the ref is the default branch:
- if: github.ref == 'refs/heads/develop'
run: ./nightly.shCommon causes
Branch conditions do not match under schedule
The schedule ref is the default branch, so any non-default branch condition evaluates false and skips the step.
No guard against running in forks
Without a repository check, a scheduled job can run in forks you did not intend.
How to fix it
Guard on event name and repository
- Use
github.event_name == 'schedule'to detect cron runs. - Add
github.repository == 'owner/repo'to skip forks. - Avoid non-default-branch conditions for scheduled steps.
- if: github.event_name == 'schedule' && github.repository == 'acme/app'
run: ./nightly.shSkip with a job-level condition
Gate the whole job so it only runs on the intended repository and event.
jobs:
nightly:
if: github.event_name == 'schedule'
runs-on: ubuntu-latestHow to prevent it
- Never use non-default-branch conditions for scheduled steps.
- Guard forks with a repository check.
- Prefer event-name conditions for cron-specific logic.