question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unexpected value for `github.event.pull_request.base.sha`

See original GitHub issue

Describe 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:

  1. Create a workflow run on pull_request, logging the github context.
  2. On some branch a create a new branch b.
  3. Make commits on a.
  4. Make commits on b.
  5. Push the changes from a.
  6. 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
JensDllcommented, Feb 16, 2022

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

1reaction
JensDllcommented, Mar 28, 2023

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting base branch SHA on pull request in Github Action ...
In GitHub action on pull request, I need to run some code in the context of the "current master", and later re-run the...
Read more >
7 Github Actions Tricks I Wish I Knew Before I Started
#1: How to Use Github Action Triggers ... The above code is pretty much self explanatory. The workflow will trigger on every pull...
Read more >
GitHub Actions Security Best Practices [cheat sheet included]
Learn how to secure your GitHub Actions with these best practices! ... Actions are triggered by GitHub events (a pull request is submitted, ......
Read more >
The Many SHAs of a GitHub Pull Request - Ken Muse
A SHA for every occasion. The pull_request event exposes the values into the workflow as part of the github context. For downloading the...
Read more >
GitHub Actions: Best Practices | Exercism's Docs
This working document serves as a collection of best practices for making use of GitHub Actions. If you have any suggestions or additions,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found