FeRD
I strongly suspect the workflow contexts can’t be used in script code, if you’re trying to use them that way — that is, I wouldn’t expect this to work:
jobs:
build:
steps:
- name: Something
run: if [ ${{ github.head_ref }} = “something” ]; then echo “Yep”; fi
However, you should be able to either create an envvar for use in the shell context, as Brian showed, or you can use one of Github’s built-in ones. github.event.number
doesn’t have an envvar, but $GITHUB_HEAD_REF
does. There’s a whole list of 'em. And, in fact, $GITHUB_EVENT_NAME
should be what you want, “the name of the webhook event that triggered the workflow”. So, for PRs:
jobs:
build:
steps:
- name: Something
run: if [ “x$GITHUB_EVENT_NAME” = “xpull_request” ]; then echo “I’m a PR.”; fi
ETA: (One caveat on the above, it may only run when the PR is initially opened. I’m not sure if updates to an open PR trigger as pull_request
events.)