I want to access the Pull Request number in a Github Actions workflow. I can access the GITHUB_REF
environment variable that is available. Although on a Pull Request action it has the value: refs/pull/125/merge
. I need to extract just the 125
.
I have found a similar post here that shows how to get the current branch using this variable. Although in this case, what I am parsing is different and I have been unable to isolate the Pull Request number.
{GITHUB_REF##\*/}
which resolves to merge
{GITHUB_REF#\*/}
which resolves to pull/125/merge
I only need the Pull Request number (which in my example is 125)
Although it is already answered, the easiest way I found is using the github context. The following example shows how to set it to an environment variable.
env:
PR_NUMBER: ${{ github.event.number }}