@@ -28,18 +28,33 @@ jobs:
28
28
# that we publish with the one that we built the scan with in the first place:
29
29
- name : Determine the Branch Reference for which the original action was triggered
30
30
id : determine_branch_ref
31
+ env :
32
+ GH_TOKEN : ${{ github.token }}
31
33
run : |
32
- if [ -n "${{ github.event.workflow_run.pull_requests[0].base.ref }}" ]; then
33
- BRANCH_REF="${{ github.event.workflow_run.pull_requests[0].base.ref }}"
34
+ if [ "${{ github.event.workflow_run.event }}" == "pull_request" ]; then
35
+ echo "::notice::Triggering workflow was executed for a pull request"
36
+
37
+ FORK_OWNER="${{ github.event.workflow_run.head_repository.owner.login }}"
38
+ BRANCH_NAME="${{ github.event.workflow_run.head_branch }}"
39
+ if [ "${{ github.event.workflow_run.head_repository.owner.login }}" != "${{ github.event.workflow_run.repository.owner.login }}" ]; then
40
+ BRANCH_NAME="$FORK_OWNER:$BRANCH_NAME"
41
+ fi
42
+ TARGET_BRANCH=$(gh pr view "$BRANCH_NAME" --repo ${{ github.event.workflow_run.repository.full_name }} --json baseRefName -q .baseRefName)
43
+
44
+ echo "::notice::PR found. Target branch is: $TARGET_BRANCH"
45
+ echo "original_branch_ref=$TARGET_BRANCH" >> "$GITHUB_OUTPUT"
34
46
else
35
- BRANCH_REF="${{ github.event.workflow_run.head_branch }}"
47
+ echo "::notice::Triggering workflow was executed for a push event? Using the head_branch value."
48
+ echo "original_branch_ref=${{ github.event.workflow_run.head_branch }}" >> "$GITHUB_OUTPUT"
36
49
fi
37
- echo "original_branch_ref=$BRANCH_REF" >> "$GITHUB_OUTPUT"
38
50
# Checkout target branch which has trusted code
39
51
- name : Check out target branch
40
52
uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
41
53
with :
42
54
persist-credentials : false
55
+ # By default, a workflow that is triggered with on workflow_run would run on the main (default) branch.
56
+ # Different branches might have different versions of Develocity, and we want to make sure
57
+ # that we publish with the one that we built the scan with in the first place.
43
58
ref : ${{ steps.determine_branch_ref.outputs.original_branch_ref }}
44
59
- name : Set up Java 21
45
60
uses : actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # 4.7.1
0 commit comments