2323 pull-requests : write
2424 statuses : write
2525 steps :
26+ - name : Verify workflow run origin
27+ env :
28+ IS_FORK : ${{ github.event.workflow_run.head_repository.fork }}
29+ RUN_REPO : ${{ github.event.workflow_run.repository.full_name }}
30+ EXPECTED_REPO : ${{ github.repository }}
31+ run : |
32+ if [[ "$IS_FORK" != "true" ]]; then
33+ echo "❌ Expected a fork trigger — aborting"
34+ exit 1
35+ fi
36+ if [[ "$RUN_REPO" != "$EXPECTED_REPO" ]]; then
37+ echo "❌ Workflow did not run in the expected base repository"
38+ exit 1
39+ fi
40+
2641 - name : Download PR information
2742 uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
2843 with :
5570 console.log("PR information downloaded");
5671
5772 - name : Extract PR Information
73+ id : pr-info
5874 run : |
5975 mkdir -p ${{ runner.temp }}/pr-info-extracted
6076 unzip -q ${{ runner.temp }}/pr-info/pr-info.zip -d ${{ runner.temp }}/pr-info-extracted
@@ -63,19 +79,25 @@ jobs:
6379 HEAD_SHA=$(cat ${{ runner.temp }}/pr-info-extracted/head-sha)
6480 PR_NUMBER=$(cat ${{ runner.temp }}/pr-info-extracted/pr-number)
6581 BASE_REF=$(cat ${{ runner.temp }}/pr-info-extracted/base-ref)
66- echo "REPO_NAME=$REPO_NAME" >> $GITHUB_ENV
67- echo "HEAD_REF=$HEAD_REF" >> $GITHUB_ENV
68- echo "HEAD_SHA=$HEAD_SHA" >> $GITHUB_ENV
69- echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
70- echo "BASE_REF=$BASE_REF" >> $GITHUB_ENV
82+ [[ "$HEAD_SHA" =~ ^[0-9a-f]{40}$ ]] || { echo "❌ Invalid HEAD_SHA"; exit 1; }
83+ [[ "$PR_NUMBER" =~ ^[0-9]+$ ]] || { echo "❌ Invalid PR_NUMBER"; exit 1; }
84+ [[ "$HEAD_REF" =~ ^[a-zA-Z0-9/_.-]+$ ]] || { echo "❌ Invalid HEAD_REF"; exit 1; }
85+ [[ "$BASE_REF" =~ ^[a-zA-Z0-9/_.-]+$ ]] || { echo "❌ Invalid BASE_REF"; exit 1; }
86+ [[ "$REPO_NAME" =~ ^[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+$ ]] || { echo "❌ Invalid REPO_NAME"; exit 1; }
87+ echo "repo-name=$REPO_NAME" >> $GITHUB_OUTPUT
88+ echo "head-ref=$HEAD_REF" >> $GITHUB_OUTPUT
89+ echo "head-sha=$HEAD_SHA" >> $GITHUB_OUTPUT
90+ echo "pr-number=$PR_NUMBER" >> $GITHUB_OUTPUT
91+ echo "base-ref=$BASE_REF" >> $GITHUB_OUTPUT
7192 echo "PR information extracted: $REPO_NAME $HEAD_REF $HEAD_SHA $PR_NUMBER $BASE_REF"
7293
7394 - name : Checkout sources
7495 uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
7596 with :
76- ref : ${{ env.HEAD_REF }}
77- repository : ${{ env.REPO_NAME }}
97+ ref : ${{ steps.pr-info.outputs.head-sha }}
98+ repository : ${{ steps.pr-info.outputs.repo-name }}
7899 fetch-depth : 0
100+ persist-credentials : false
79101
80102 - uses : actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
81103 with :
@@ -125,12 +147,12 @@ jobs:
125147 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
126148 with :
127149 args : >
128- -Dsonar.pullrequest.key=${{ env.PR_NUMBER }}
129- -Dsonar.pullrequest.branch=${{ env.HEAD_REF }}
130- -Dsonar.pullrequest.base=${{ env.BASE_REF }}
150+ -Dsonar.pullrequest.key=${{ steps.pr-info.outputs.pr-number }}
151+ -Dsonar.pullrequest.branch=${{ steps.pr-info.outputs.head-ref }}
152+ -Dsonar.pullrequest.base=${{ steps.pr-info.outputs.base-ref }}
131153 -Dsonar.pullrequest.provider=github
132154 -Dsonar.pullrequest.github.repository=${{ github.repository }}
133- -Dsonar.scm.revision=${{ env.HEAD_SHA }}
155+ -Dsonar.scm.revision=${{ steps.pr-info.outputs.head-sha }}
134156 -Dsonar.qualitygate.wait=true
135157
136158 - name : Delete artifacts used in analysis
0 commit comments