@@ -14,24 +14,28 @@ jobs:
1414 runs-on : ubuntu-latest
1515 if : github.event.workflow_run.conclusion == 'success'
1616 timeout-minutes : 15
17+ permissions :
18+ contents : read
19+ actions : read
20+ pull-requests : read
1721 steps :
1822 - name : echo event
1923 run : cat $GITHUB_EVENT_PATH
2024 - name : Download PR number artifact
21- if : github.event.workflow_run.event == 'pull_request' || (github.event.workflow_run.actor == 'dependabot[bot]' && github.event.workflow_run.event == 'pull_request_target')
25+ if : github.event.workflow_run.event == 'pull_request'
2226 uses : dawidd6/action-download-artifact@b6e2e70617bc3265edd6dab6c906732b2f1ae151 # v21
2327 with :
2428 workflow : SonarCloud Build
2529 run_id : ${{ github.event.workflow_run.id }}
2630 name : PR_NUMBER
2731 - name : Read PR_NUMBER.txt
28- if : github.event.workflow_run.event == 'pull_request' || (github.event.workflow_run.actor == 'dependabot[bot]' && github.event.workflow_run.event == 'pull_request_target')
32+ if : github.event.workflow_run.event == 'pull_request'
2933 id : pr_number
3034 uses : juliangruber/read-file-action@271ff311a4947af354c6abcd696a306553b9ec18 # v1
3135 with :
3236 path : ./PR_NUMBER.txt
3337 - name : Request GitHub API for PR data
34- if : github.event.workflow_run.event == 'pull_request' || (github.event.workflow_run.actor == 'dependabot[bot]' && github.event.workflow_run.event == 'pull_request_target')
38+ if : github.event.workflow_run.event == 'pull_request'
3539 uses : octokit/request-action@b91aabaa861c777dcdb14e2387e30eddf04619ae # v3.0.0
3640 id : get_pr_data
3741 with :
@@ -40,34 +44,17 @@ jobs:
4044 full_name : ${{ github.event.repository.full_name }}
4145 env :
4246 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
43- - name : Extract PR data
44- if : github.event.workflow_run.event == 'pull_request' || (github.event.workflow_run.actor == 'dependabot[bot]' && github.event.workflow_run.event == 'pull_request_target')
45- id : pr_data
46- env :
47- DATA : ${{ steps.get_pr_data.outputs.data }}
48- run : |
49- echo "head_ref=$(echo "$DATA" | jq -r '.head.ref')" >> $GITHUB_OUTPUT
50- echo "number=$(echo "$DATA" | jq -r '.number')" >> $GITHUB_OUTPUT
51- echo "base_ref=$(echo "$DATA" | jq -r '.base.ref')" >> $GITHUB_OUTPUT
5247 - uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
5348 with :
54- repository : ${{ github.event.workflow_run.head_repository.full_name }}
55- ref : ${{ github.event.workflow_run.head_branch }}
5649 fetch-depth : 0
57- - name : Checkout base branch
58- if : github.event.workflow_run.event == 'pull_request' || (github.event.workflow_run.actor == 'dependabot[bot]' && github.event.workflow_run.event == 'pull_request_target')
59- env :
60- CLONE_URL : ${{ github.event.repository.clone_url }}
61- BASE_REF : ${{ steps.pr_data.outputs.base_ref }}
62- HEAD_BRANCH : ${{ github.event.workflow_run.head_branch }}
63- run : |
64- git remote add upstream "$CLONE_URL"
65- git fetch upstream
66- git checkout -B "$BASE_REF" "upstream/$BASE_REF"
67- git checkout "$HEAD_BRANCH"
68- git clean -ffdx && git reset --hard HEAD
50+ - name : Download build artifacts
51+ uses : dawidd6/action-download-artifact@b6e2e70617bc3265edd6dab6c906732b2f1ae151 # v21
52+ with :
53+ workflow : SonarCloud Build
54+ run_id : ${{ github.event.workflow_run.id }}
55+ name : build-artifacts
6956 - name : Cache SonarCloud packages
70- uses : actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
57+ uses : actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5
7158 with :
7259 path : ~/.sonar/cache
7360 key : ${{ runner.os }}-sonar
@@ -85,46 +72,39 @@ jobs:
8572 with :
8673 distribution : ' zulu'
8774 java-version : ' 17'
75+
8876 - name : Set Common Sonar Variables
8977 id : sonar_env
9078 run : |
91- echo "##[set-output name= sonar_opts;]$(echo -Dsonar.host.url=https://sonarcloud.io \
79+ echo "sonar_opts= -Dsonar.host.url=https://sonarcloud.io \
9280 -Dsonar.projectKey=com-pas_compas-scl-data-service \
93- -Dsonar.organization=com-pas )"
81+ -Dsonar.organization=com-pas" >> $GITHUB_OUTPUT
9482 - name : Create custom Maven Settings.xml
9583 uses : whelk-io/maven-settings-xml-action@9dc09b23833fa9aa7f27b63db287951856f3433d # v22
9684 with :
9785 output_file : custom_maven_settings.xml
9886 servers : ' [{ "id": "github-packages-compas", "username": "OWNER", "password": "${{ secrets.GITHUB_TOKEN }}" }]'
9987 - name : Build and analyze (Pull Request)
100- if : ${{ github.event.workflow_run.event == 'pull_request' || (github.event.workflow_run.actor == 'dependabot[bot]' && github.event.workflow_run.event == 'pull_request_target') }}
88+ if : ${{ github.event.workflow_run.event == 'pull_request' }}
10189 env :
10290 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
10391 SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
104- SONAR_OPTS : ${{ steps.sonar_env.outputs.sonar_opts }}
105- PR_HEAD_REF : ${{ steps.pr_data.outputs.head_ref }}
106- PR_NUMBER : ${{ steps.pr_data.outputs.number }}
107- PR_BASE_REF : ${{ steps.pr_data.outputs.base_ref }}
108- HEAD_SHA : ${{ github.event.workflow_run.head_sha }}
10992 run : |
110- ./mvnw -B -s custom_maven_settings.xml -Psonar \
111- $SONAR_OPTS \
112- -Dsonar.pullrequest.branch="$PR_HEAD_REF" \
113- -Dsonar.pullrequest.key="$PR_NUMBER" \
114- -Dsonar.pullrequest.base="$PR_BASE_REF" \
115- -Dsonar.scm.revision="$HEAD_SHA" \
116- clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
93+ mvn -B -s custom_maven_settings.xml -Psonar \
94+ ${{ steps.sonar_env.outputs.sonar_opts }} \
95+ -Dsonar.pullrequest.branch=${{ fromJson(steps.get_pr_data.outputs.data).head.ref }} \
96+ -Dsonar.pullrequest.key=${{ fromJson(steps.get_pr_data.outputs.data).number }} \
97+ -Dsonar.pullrequest.base=${{ fromJson(steps.get_pr_data.outputs.data).base.ref }} \
98+ -Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }} \
99+ org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
117100 - name : Build and analyze (Push)
118101 if : ${{ github.event.workflow_run.event == 'push' }}
119102 env :
120103 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
121104 SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
122- SONAR_OPTS : ${{ steps.sonar_env.outputs.sonar_opts }}
123- HEAD_SHA : ${{ github.event.workflow_run.head_sha }}
124- HEAD_BRANCH : ${{ github.event.workflow_run.head_branch }}
125105 run : |
126- ./mvnw -B -s custom_maven_settings.xml -Psonar \
127- $SONAR_OPTS \
128- -Dsonar.scm.revision="$HEAD_SHA" \
129- -Dsonar.branch.name="$HEAD_BRANCH" \
130- clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
106+ mvn -B -s custom_maven_settings.xml -Psonar \
107+ ${{ steps.sonar_env.outputs.sonar_opts }} \
108+ -Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }} \
109+ -Dsonar.branch.name=${{ github.event.workflow_run.head_branch }} \
110+ org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
0 commit comments