Skip to content

Commit 3b62461

Browse files
committed
Change how the base branch is determined for the ci-report workflow
Signed-off-by: marko-bekhta <[email protected]>
1 parent 2cef49a commit 3b62461

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

.github/workflows/ci-report.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,33 @@ jobs:
2828
# that we publish with the one that we built the scan with in the first place:
2929
- name: Determine the Branch Reference for which the original action was triggered
3030
id: determine_branch_ref
31+
env:
32+
GH_TOKEN: ${{ github.token }}
3133
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"
3446
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"
3649
fi
37-
echo "original_branch_ref=$BRANCH_REF" >> "$GITHUB_OUTPUT"
3850
# Checkout target branch which has trusted code
3951
- name: Check out target branch
4052
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
4153
with:
4254
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.
4358
ref: ${{ steps.determine_branch_ref.outputs.original_branch_ref }}
4459
- name: Set up Java 21
4560
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # 4.7.1

0 commit comments

Comments
 (0)