How to Disable a Scheduled Workflow on Forks in GitHub Actions
Guard the scheduled job with an if that checks github.repository so forks never run your cron.
Forks inherit workflow files, so a scheduled job would fire in every fork. Add a job-level if comparing github.repository to the upstream slug to run it only there.
Steps
- Add a job-level
if: github.repository == 'owner/repo'. - Keep push and pull_request jobs unconditional so forks still get CI.
- Optionally check
github.event_name == 'schedule'to scope the guard.
Workflow
.github/workflows/ci.yml
on:
schedule:
- cron: '0 6 * * *'
jobs:
nightly:
if: github.repository == 'acme/widgets'
runs-on: ubuntu-latest
steps:
- run: ./nightly.shGotchas
- Fork owners can disable Actions entirely, but the
ifguard is more reliable. - Hardcode the exact
owner/repo; a rename requires updating the condition.
Related guides
How to Skip a Scheduled Run Conditionally in GitHub ActionsSkip a GitHub Actions cron run when a condition holds, such as a holiday or an unchanged repository, using an…
How to Run a Workflow on a Cron Schedule in GitHub ActionsTrigger a GitHub Actions workflow on a recurring timetable with on.schedule and a five-field POSIX cron expre…