Skip to content

Commit 93dbfd7

Browse files
committed
Change how the base branch is determined for the ci-report workflow
Signed-off-by: marko-bekhta <[email protected]> # Conflicts: # .github/workflows/ci-report.yml
1 parent 80d271e commit 93dbfd7

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

.github/workflows/ci-report.yml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +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-
echo '${{ toJSON(github.event.workflow_run.pull_requests) }}'
33-
echo '${{ toJSON(github.event.workflow_run.event) }}'
34-
if [ -n "${{ github.event.workflow_run.pull_requests[0].base.ref }}" ]; then
35-
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"
3646
else
37-
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"
3849
fi
39-
echo "original_branch_ref=$BRANCH_REF" >> "$GITHUB_OUTPUT"
4050
# Checkout target branch which has trusted code
4151
- name: Check out target branch
4252
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
4353
with:
4454
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.
4558
ref: ${{ steps.determine_branch_ref.outputs.original_branch_ref }}
4659
- name: Set up Java 21
4760
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # 4.7.1

0 commit comments

Comments
 (0)