Unexpected value for `github.event.pull_request.base.sha`
See original GitHub issueDescribe the bug
In a workflow run on pull_request
, the github.event.pull_request.base.sha
does not always seem to be the real pull request base. At the time of opening the pull request, it will have the SHA
of the latest commit in base.ref
. That seems unexpected because really it should have the SHA
of the commit since creating the branch, right?
To Reproduce Steps to reproduce the behavior:
- Create a workflow run on
pull_request
, logging thegithub
context. - On some branch
a
create a new branchb
. - Make commits on
a
. - Make commits on
b
. - Push the changes from
a
. - Push the changes from
b
and open a pull request.
Let’s assume the history looks like below:
a 0 --- 1 --- 2
b + 3 --- 4
Expected behavior
github.event.pull_request.base.sha
is 0
Actual behavior
github.event.pull_request.base.sha
is 2
Runner Version and Platform
Version of your runner?
2.287.1
OS of the machine running the runner?
GitHub-hosted ubuntu-latest
version 20.04.3
Job Log Output
I recreated the steps above and described the behavior once more. Here is the pull request:
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top GitHub Comments
Alright, I think I just realized that the
github.event
information is coming more or less straight from the GitHub REST API. https://docs.github.com/en/rest/reference/pulls#get-a-pull-request I do believe this is a bug but nothing related to the runner at least. Might start a discussion over at github/feedback.Anyways, closing this issue then. Thanks
@izaitsevfb Unfortunately, I did not follow up in any discussion after opening this. I remember finding other sources describing the same problem shortly after reporting here. For example, https://github.com/github/docs/issues/431 was one.
As for workarounds, it would require some manual git plumbing. For reference, here is what you could use to find the base and head commit of a pull request in the context of a GitHub Action.
It looks like there is now an open discussion about the topic on the Community forum: https://github.com/orgs/community/discussions/39880