@@ -62,20 +62,33 @@ jobs:
6262 env :
6363 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
6464
65- # Use SHA for checkout — immune to branch-name injection
65+ - name : Extract PR metadata
66+ if : github.event.workflow_run.event == 'pull_request'
67+ id : pr_meta
68+ env :
69+ PR_DATA : ${{ steps.get_pr_data.outputs.data }}
70+ run : |
71+ echo "number=$(echo "$PR_DATA" | jq -r '.number')" >> "$GITHUB_OUTPUT"
72+ echo "head_ref=$(echo "$PR_DATA" | jq -r '.head.ref')" >> "$GITHUB_OUTPUT"
73+ echo "base_ref=$(echo "$PR_DATA" | jq -r '.base.ref')" >> "$GITHUB_OUTPUT"
74+
75+ # Use SHA for checkout — immune to branch-name injection.
76+ # allow-unsafe-pr-checkout is safe here: we only scan (no script execution
77+ # from fork code) and persist-credentials is false.
6678 - name : Checkout PR head
6779 uses : actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
6880 with :
6981 repository : ${{ github.event.workflow_run.head_repository.full_name }}
7082 ref : ${{ github.event.workflow_run.head_sha }}
7183 fetch-depth : 0
7284 persist-credentials : false
85+ allow-unsafe-pr-checkout : true
7386
7487 # Branch names passed via env (not expression interpolation in run:)
7588 - name : Checkout base branch
7689 if : github.event.workflow_run.event == 'pull_request'
7790 env :
78- BASE_REF : ${{ fromJson( steps.get_pr_data .outputs.data).base.ref }}
91+ BASE_REF : ${{ steps.pr_meta .outputs.base_ref }}
7992 HEAD_SHA : ${{ github.event.workflow_run.head_sha }}
8093 CLONE_URL : ${{ github.event.repository.clone_url }}
8194 run : |
@@ -107,9 +120,9 @@ jobs:
107120 -Dsonar.projectKey=kptdev_porch
108121 -Dsonar.organization=kptdev
109122 -Dproject.settings=sonar-project.properties
110- -Dsonar.pullrequest.key=${{ fromJson( steps.get_pr_data .outputs.data) .number }}
111- -Dsonar.pullrequest.branch=${{ fromJson( steps.get_pr_data .outputs.data).head.ref }}
112- -Dsonar.pullrequest.base=${{ fromJson( steps.get_pr_data .outputs.data).base.ref }}
123+ -Dsonar.pullrequest.key=${{ steps.pr_meta .outputs.number }}
124+ -Dsonar.pullrequest.branch=${{ steps.pr_meta .outputs.head_ref }}
125+ -Dsonar.pullrequest.base=${{ steps.pr_meta .outputs.base_ref }}
113126
114127 - name : SonarCloud Scan on push
115128 if : >-
0 commit comments