I am modifying a workflow file so that a job doesn't run when a pull request originates from another repo.
So, I am looking for something like this:
build_and_deploy_job:
if: github.repository == github.pullrequest.repo
github.pullrequest.repo
is just something I made up, but the idea would be that it would return the (full) name of the repo where the pull request came from.
I've tried outputting the environment variables to see if they are somehow different if a PR comes from a different branch in the same repo, or from a different repo. Nothing stood out to me as being useful.
Is something like that possible?
Background: I am trying to avoid a build job failure because it can't access a repo secret during a pull_request
event when the pull request comes from another repo.
Use the following to check if the PR is coming from the same repo. This only works when the workflow is triggered by a pull request.
on: [pull_request]
jobs:
build_and_deploy_job:
if: github.event.pull_request.head.repo.name == github.repository
Bonus: Use this to check if the repo is a fork.
on: [pull_request]
jobs:
build_and_deploy_job:
if: github.event.pull_request.head.repo.fork == true
Source: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#webhook-payload-object-34
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With