Skip to content

Commit 0b0c72e

Browse files
Merge pull request #11 from secondlife/pr-branch
Fix branch detection for pull request builds.
2 parents 59f0518 + e8d3c63 commit 0b0c72e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

which-branch/action.yaml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,20 @@ outputs:
1515
runs:
1616
using: composite
1717
steps:
18-
- name: Install Python dependencies
19-
shell: bash
20-
run: pip3 install PyGithub
21-
2218
- name: Determine which branch
2319
id: which-branch
2420
shell: bash
2521
run: |
26-
branch="$(python '${{ github.action_path }}/which_branch.py' \
27-
-t "${{ inputs.token }}" -r "${{github.repository }}" "${{ github.sha }}")"
22+
set -x
23+
if [[ "$GITHUB_REF_TYPE" != "tag" ]]
24+
then
25+
# For a pull request, GITHUB_HEAD_REF is the branch name.
26+
# For a branch build, GITHUB_REF_NAME is the branch name.
27+
branch="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}"
28+
else
29+
# For a tag build, have to discover which branch corresponds.
30+
pip3 install PyGithub
31+
branch="$(python '${{ github.action_path }}/which_branch.py' \
32+
-t "${{ inputs.token }}" -r "${{github.repository }}" "${{ github.sha }}")"
33+
fi
2834
echo "branch=$branch" >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)