continuous-integrationgithub-actions

How to only run a step if the workflow is running in the main repository in Github Actions?


How can I only run a step if the workflow is running in the main repository, and not within a fork?

I would have thought that if: github.repository == 'octo-org/octo-repo-prod' would do it, but it does not - and while if: ${{ github.event.pull_request.head.repo.full_name == 'octo-org/octo-repo-prod' }} does work for PRs, it does not work for merges or scheduled builds.


Solution

  • Looks like this works on a step:

    if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository