Get branch name

For context, this is my Github Actions ci.yml - https://github.com/reikdas/cling/blob/e9e6d80e3f15568d05a869ab1e314f453a857b96/.github/workflows/ci.yml

I want to get the name of the branch that is creating a PR or the name of the branch a commit is pushed to (when Github Actions is triggered).

I found separate solutions for PR branch and commit branch.
For PR branch I found this - How to get PR branch name in GitHub Actions
and for commit branch I got this - https://stackoverflow.com/a/58035262 and several others which state the same thing.

Do I need to create separate steps for a pull request and a push? I don’t care about triggering both at the same time since I want push to be triggered only on master and pull request only on branches to master (as specified in the above linked ci.yml); so the two of them will never be triggered together.

I would really appreciate any help with this :slight_smile:

My answer is yes. As the two events push and pull_request have different event payload , I would recommend you add two steps to get PR branch and push commit branch. You could add if conditional to these two steps:

if: github.event_name == 'pull_request'

and

if: github.event_name == 'push'