Do not run cron workflows in forks #26684
-
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? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
In the workflow, you can use the property github.repository of github context, or the environment variable GITHUB_REPOSITORY, to view the repository where the current workflow is running on. 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 _:
This workflow will execute the job _ build _ only when meeting one of the following situations:
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. |
Beta Was this translation helpful? Give feedback.
-
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:
|
Beta Was this translation helpful? Give feedback.
-
Checking for the repository name on the job level is a bit cumbersome IMHO. |
Beta Was this translation helpful? Give feedback.
@jacobtomlinson ,
In the workflow, you can use the property github.repository of github context, or the environment variable GITHUB_REPOSITORY, to view the repository where the current workflow is running on.
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 _:
This workflow will execute the job _ build _ only when meeting one of the following situations:
The event is _ schedule and the repository is main_org/main_repo , if t…