Get source branch in Github Actions

Viewed 140

I have an artifact generated only in a pull request, and I am looking to then use that source branch name in my main branch on a PR merge.

- name: Download artifact
  uses: dawidd6/action-download-artifact@v2
  with:
    workflow: apply.yml
    name: artifact
    branch: '${{ github.event.pull_request.head.repo.default_branch }}'

The syntax for ${{ github.event.pull_request.head.repo.default_branch is null, however.

Is there any way to pull the PR branch name?

1 Answers

For anyone finding this question online, here's how I solved it:

- uses: tonynguyenit18/github-action-custom-vars@v1

- name: "merge branch"
  id: merge_branch
  run: echo "::set-output name=merge_branch::$RECENT_MERGED_BRANCH_NAME"

This sets the merged branch in a variable which you can call by using: ${{ steps.merge_branch.outputs.merge_branch }}

Related