GitHub CI - Get branch name from pull request


I have a very simple scenario where I want to execute specific action (Just write a comment in the PR itself) when branch name starts with specific characters.

In the GH documentation it says that github.ref holds that information. But it does not. My PR is ave-123-add-links but output of gihub.ref is refs/pull/202/merge. This has nothing to do with my branch name and I do not understand what am I doing wrong.

Here is the full example:

name: Add links

on: pull_request

    runs-on: ubuntu-latest
    if: startsWith(github.ref, 'refs/heads/ave-') # This will fail always, it has no ave-, it is set to refs/pull/202/merge
      - run: ehco ${{ github.ref }} # refs/pull/202/merge ?

you can easily use

      - 'first_part_of_branch_name*'
      - 'first_part_of_branch_name_2*'

@DavideC03, I think that would only work for request to pull into those branches, rather than from them. Or am I missing something?

The reason github.ref looks odd is that for a pull request it points at a temporary merge (see GITHUB_REF in the pull_request event description). @stanislavromanov, I think github.head_ref in the github context should be what you want: