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