I have an action which runs on a cron schedule. However I only want it to run on the main repo, not in forks. Currently it runs in all forks too.
Is there a way to limit the workflow to a specific repo name, similar to how you can filter on modified files?
Solved! Solved! Go to Solution.
You can use the if conditional to skip all the jobs of the scheduled workflow according to the repository.
For example, the main repository is main_org/main_repo:
Jobs: build: if: (github.event_name == 'schedule' && github.repository == 'main_org/main_repo') || (github.event_name != 'schedule') . . .
This workflow will execute the job build only when meeting one of the following situations:
1) The event is schedule and the repository is main_org/main_repo, if the repository is not main_org/main_repo the job build will be skipped.
2) The event is not schedule and the repository can be anyone.
You just need to setup this configuration once on the main repository, and every time you create a new fork from the main repository, this configuration will be copy to the fork repository.
Of course, you also can try to remove the schedule event and only retain the needed events in the YAML file from the fork repository. However, if you need to create multiple fork repositories, this may become more troublesome.
Perfect thanks @BrightRan! The workflow raises a PR automatically to update dependencies. So raising this PR on forks was just noise for anyone who contributes to the project.
Adding the following resolved it for me:
jobs: job-name: if: github.repository == 'org_name/repo_name'