Skip to content

Commit 4446d9c

Browse files
committed
Adapt which-branch action for pull request builds
as well as branch builds and tag builds.
1 parent 59f0518 commit 4446d9c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

which-branch/action.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ runs:
2323
id: which-branch
2424
shell: bash
2525
run: |
26-
branch="$(python '${{ github.action_path }}/which_branch.py' \
27-
-t "${{ inputs.token }}" -r "${{github.repository }}" "${{ github.sha }}")"
26+
set -x
27+
if [[ "$GITHUB_REF_TYPE" != "tag" ]]
28+
then
29+
# For a pull request, GITHUB_HEAD_REF is the branch name.
30+
# For a branch build, GITHUB_REF_NAME is the branch name.
31+
branch="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}"
32+
else
33+
# For a tag build, have to discover which branch corresponds.
34+
branch="$(python '${{ github.action_path }}/which_branch.py' \
35+
-t "${{ inputs.token }}" -r "${{github.repository }}" "${{ github.sha }}")"
36+
fi
2837
echo "branch=$branch" >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)