Re-running a workflow sets incorrect GITHUB_REF

Hi folks,

I just wanted to share this finding with you.

When a workflow is triggered via “pull_request” event, the “GITHUB_REF” contains some info about the PR (e.g. “refs/pull/676/merge”), but when the same workflow is restarted manually (“Re-run all jobs”), then the “GITHUB_REF” contains some other information: “refs/heads/<branch name>”. All the other GITHUB_ env variables have the same values, so it feels like a bug to me.

I used “GITHUB_REF” to extract the PR number:

echo $GITHUB_REF | awk -F/ ' { print $3 } '

but it turned to be unreliable, so a better way would be to extract this info from the even.json, e.g.:

grep -Eo "\"number\": [0-9]+" $GITHUB_EVENT_PATH | awk ' { print $2; exit } '

I hope it helps.

1 Like

@alexdenisov ,

As I mentioned in this ticket which also reported the same issue, you can directly use the existing property  github.event.number  of github **context **to get the PR number, instead of extracting the number from the GITHUB_REF. The value of github.event.number  will not be changed after you re-run the workflow.

1 Like