Interview Prep/GitHub Actions/Triggers & Events

How do you prevent a workflow from running on forks of your repository (for example, scheduled jobs)?

BeginnerConceptTriggers & Events
Answer

Forks copy workflows, and scheduled or push workflows may run in the fork owner's account. Guard jobs with the repository name:

jobs:
  nightly:
    if: github.repository == 'devopsshack/shack-api'

Forks of public repos have Actions disabled until the owner enables them, but the guard keeps forks that enable Actions from attempting deploys that will fail anyway.

All GitHub Actions questions Roadmap: GitHub Actions

More on Triggers & Events