I’m trying to make an action workflow that operates on the git diff
from the branch point.
The current SHA is easy:
github.sha
When I have a pull-request event, I can also use github.head_ref
to get the source branch of the pull request.
But when I push to that branch (e.g. fixing something), then github.head_ref
is empty.
Is there a way to continue to access github.head_ref
on push events already part of a pull request? I’d accept some git methods, something like:
git merge-base --fork-point origin/master
But I see that there’s no .git/refs/heads/master when I check out…
Hi @ghutchis ,
‘github.head_ref’ is not supported for push event, since it’s not in the push event github context, you can use below command to check all of the context values:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
Hope it helps!
I think this is a fairly common use case, judging from some of the searching I did. I think push events made to a pull request should be able to fetch their branch point.
This doesn’t work robustly, but is close enough for now:
# I didn't use ${{ github.repository }} because that points to the fork
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/openchemistry/avogadrolibs
git fetch origin master:master
export MASTER_SHA=`cat .git/refs/heads/master`
git diff ${MASTER_SHA} --name-only
# whatever else you want to do