Opposite from this topic: GITHUB_REF is inconsistent
I need the name of the branch from within my GitHub actions.
- On pull_request event → expected outcome, I can use the environment variable github.head_ref to get the name of the branch since github.ref is a pull request
- On pull_request_review event → github.head_ref is empty, but github.ref still reflects the pull request, leaving me without the branch name in this case.
There are branch protection rules in place on master to prevent anyone (including the GitHub action as we can’t exclude it) from pushing to master. So the file that gets changed within the action needs to be pushed to the pull request incoming branch. We also require pull requests be approved by a reviewer before they can be merged. So we do not want this to fire on a pull_request, but only on the pull_request_review (since no pull_request_approved event exists)
I verified this behavior by echoing both github.head_ref and github.ref for a pull_request event, and in a separate pull request for the event pull_request_review.
Any help is appreciated