github.sha isn't the value expected #25191
-
I’m trying to retrieve the SHA from the commit that triggers the action. So if I make a commit and then do a push, within that push action handler I want to get that commit SHA. My goal is to build a URL based around the SHA and then comment on the PR with the URL (using https://github.com/unsplash/comment-on-pr). I expected github.sha to work, but I have no idea where the values it’s giving me are coming from. They don’t match any of the commits in the repo. Here’s the code I tried:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
@anderspitman When a workflow is triggered by pull request event, the github.ref will be refs/pull/<id>/merge. And the github.sha will be the pre merge commit id. If you have a pull request from dev to master, github.sha is not the commit which you pushed to dev. You need to use github.event.pull_request.head.sha to get the commit id which you pushed to dev. And based on my test when the workflow is triggered by push to master, comment PR step will fail. So you could change your workflow file to
|
Beta Was this translation helpful? Give feedback.
-
Sorry for the late response. This does indeed do the trick. Thanks! |
Beta Was this translation helpful? Give feedback.
-
i recently encountered the same issue, but what worked was using |
Beta Was this translation helpful? Give feedback.
@anderspitman When a workflow is triggered by pull request event, the github.ref will be refs/pull/<id>/merge. And the github.sha will be the pre merge commit id. If you have a pull request from dev to master, github.sha is not the commit which you pushed to dev.
You need to use github.event.pull_request.head.sha to get the commit id which you pushed to dev.
And based on my test when the workflow is triggered by push to master, comment PR step will fail.
So you could change your workflow file to