|
2 | 2 | # |
3 | 3 | # SPDX-License-Identifier: Apache-2.0 |
4 | 4 |
|
5 | | -name: SonarCloud Analysis |
| 5 | +name: SonarCloud Build and Analysis |
6 | 6 |
|
7 | 7 | on: |
8 | | - workflow_run: |
9 | | - workflows: [SonarCloud Build] |
10 | | - types: [completed] |
| 8 | + push: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + pull_request: |
| 12 | + types: [opened, synchronize, reopened] |
11 | 13 |
|
12 | 14 | jobs: |
13 | | - sonar-check: |
| 15 | + sonarqube: |
| 16 | + name: Sonar build and analysis |
14 | 17 | runs-on: ubuntu-latest |
15 | | - if: github.event.workflow_run.conclusion == 'success' |
16 | | - timeout-minutes: 15 |
| 18 | + timeout-minutes: 30 |
17 | 19 | permissions: |
18 | 20 | contents: read |
19 | 21 | actions: read |
20 | 22 | pull-requests: read |
| 23 | + |
21 | 24 | steps: |
22 | | - - name: echo event |
23 | | - run: cat $GITHUB_EVENT_PATH |
24 | | - - name: Download PR number artifact |
25 | | - if: github.event.workflow_run.event == 'pull_request' |
26 | | - uses: dawidd6/action-download-artifact@b6e2e70617bc3265edd6dab6c906732b2f1ae151 # v21 |
27 | | - with: |
28 | | - workflow: SonarCloud Build |
29 | | - run_id: ${{ github.event.workflow_run.id }} |
30 | | - name: PR_NUMBER |
31 | | - - name: Read PR_NUMBER.txt |
32 | | - if: github.event.workflow_run.event == 'pull_request' |
33 | | - id: pr_number |
34 | | - uses: juliangruber/read-file-action@271ff311a4947af354c6abcd696a306553b9ec18 # v1 |
35 | | - with: |
36 | | - path: ./PR_NUMBER.txt |
37 | | - - name: Request GitHub API for PR data |
38 | | - if: github.event.workflow_run.event == 'pull_request' |
39 | | - uses: octokit/request-action@b91aabaa861c777dcdb14e2387e30eddf04619ae # v3.0.0 |
40 | | - id: get_pr_data |
41 | | - with: |
42 | | - route: GET /repos/{full_name}/pulls/{number} |
43 | | - number: ${{ steps.pr_number.outputs.content }} |
44 | | - full_name: ${{ github.event.repository.full_name }} |
45 | | - env: |
46 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
47 | | - - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 |
48 | | - with: |
49 | | - fetch-depth: 0 |
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 |
56 | | - - name: Cache SonarCloud packages |
57 | | - uses: actions/cache@2c8a9bd7457de244a408f35966fab2fb45fda9c8 # v6.0.0 |
58 | | - with: |
59 | | - path: ~/.sonar/cache |
60 | | - key: ${{ runner.os }}-sonar |
61 | | - restore-keys: ${{ runner.os }}-sonar |
| 25 | + - name: Checkout |
| 26 | + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 |
| 27 | + with: |
| 28 | + fetch-depth: 0 |
| 29 | + |
| 30 | + - name: Cache SonarCloud packages |
| 31 | + uses: actions/cache@2c8a9bd7457de244a408f35966fab2fb45fda9c8 # v6.0.0 |
| 32 | + with: |
| 33 | + path: ~/.sonar/cache |
| 34 | + key: ${{ runner.os }}-sonar |
| 35 | + restore-keys: ${{ runner.os }}-sonar |
| 36 | + |
| 37 | + - name: Set up JDK 17 |
| 38 | + uses: actions/setup-java@1bcf9fb12cf4aa7d266a90ae39939e61372fe520 # v5.4.0 |
| 39 | + with: |
| 40 | + distribution: 'zulu' |
| 41 | + java-version: '17' |
| 42 | + cache: 'maven' |
| 43 | + |
| 44 | + - name: Set Docker API version |
| 45 | + # Workaround for Docker 29.x incompatibility with Testcontainers/EmbeddedPostgres. |
| 46 | + # See: https://github.com/testcontainers/testcontainers-java/issues/11212 |
| 47 | + # This forces the Docker Java client to use API version 1.44, which is compatible with current Testcontainers/EmbeddedPostgres. |
| 48 | + run: | |
| 49 | + echo "api.version=1.44" > $HOME/.docker-java.properties |
| 50 | +
|
| 51 | + - name: Create custom Maven Settings.xml |
| 52 | + uses: whelk-io/maven-settings-xml-action@9dc09b23833fa9aa7f27b63db287951856f3433d # v22 |
| 53 | + with: |
| 54 | + output_file: custom_maven_settings.xml |
| 55 | + servers: '[{ "id": "github-packages-compas", "username": "OWNER", "password": "${{ secrets.GITHUB_TOKEN }}" }]' |
| 56 | + |
| 57 | + - name: Request GitHub API for PR data |
| 58 | + if: github.event.workflow_run.event == 'pull_request' |
| 59 | + uses: octokit/request-action@b91aabaa861c777dcdb14e2387e30eddf04619ae # v3.0.0 |
| 60 | + id: get_pr_data |
| 61 | + with: |
| 62 | + route: GET /repos/{full_name}/pulls/{number} |
| 63 | + number: ${{ github.event.pull_request.number }} |
| 64 | + full_name: ${{ github.event.repository.full_name }} |
| 65 | + env: |
| 66 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + |
| 68 | + - name: Set Common Sonar Variables |
| 69 | + id: sonar_env |
| 70 | + run: | |
| 71 | + echo "sonar_opts=-Dsonar.host.url=https://sonarcloud.io -Dsonar.projectKey=com-pas_compas-scl-data-service -Dsonar.organization=com-pas" >> "$GITHUB_OUTPUT" |
| 72 | +
|
| 73 | + - name: Build and analyze (Pull Request) |
| 74 | + if: ${{ github.event.workflow_run.event == 'pull_request' }} |
| 75 | + env: |
| 76 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 77 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 78 | + SONAR_OPTS: ${{ steps.sonar_env.outputs.sonar_opts }} |
| 79 | + HEAD_SHA: ${{ github.event.workflow_run.head_sha }} |
| 80 | + run: | |
| 81 | + mvn -B -s custom_maven_settings.xml -Psonar \ |
| 82 | + $SONAR_OPTS \ |
| 83 | + -Dsonar.pullrequest.branch=${{ fromJson(steps.get_pr_data.outputs.data).head.ref }} \ |
| 84 | + -Dsonar.pullrequest.key=${{ fromJson(steps.get_pr_data.outputs.data).number }} \ |
| 85 | + -Dsonar.pullrequest.base=${{ fromJson(steps.get_pr_data.outputs.data).base.ref }} \ |
| 86 | + -Dsonar.scm.revision="$HEAD_SHA" \ |
| 87 | + verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar |
62 | 88 |
|
63 | | - - name: Set up JDK 17 |
64 | | - uses: actions/setup-java@1bcf9fb12cf4aa7d266a90ae39939e61372fe520 # v5.4.0 |
65 | | - with: |
66 | | - distribution: 'zulu' |
67 | | - java-version: '17' |
68 | | - - name: Set Common Sonar Variables |
69 | | - id: sonar_env |
70 | | - run: | |
71 | | - echo "sonar_opts=-Dsonar.host.url=https://sonarcloud.io -Dsonar.projectKey=com-pas_compas-scl-data-service -Dsonar.organization=com-pas" >> "$GITHUB_OUTPUT" |
72 | | - - name: Create custom Maven Settings.xml |
73 | | - uses: whelk-io/maven-settings-xml-action@9dc09b23833fa9aa7f27b63db287951856f3433d # v22 |
74 | | - with: |
75 | | - output_file: custom_maven_settings.xml |
76 | | - servers: '[{ "id": "github-packages-compas", "username": "OWNER", "password": "${{ secrets.GITHUB_TOKEN }}" }]' |
77 | | - - name: Build and analyze (Pull Request) |
78 | | - if: ${{ github.event.workflow_run.event == 'pull_request' }} |
79 | | - env: |
80 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
81 | | - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
82 | | - SONAR_OPTS: ${{ steps.sonar_env.outputs.sonar_opts }} |
83 | | - HEAD_SHA: ${{ github.event.workflow_run.head_sha }} |
84 | | - run: | |
85 | | - ./mvnw -B -s custom_maven_settings.xml -Psonar \ |
86 | | - $SONAR_OPTS \ |
87 | | - -Dsonar.pullrequest.branch=${{ fromJson(steps.get_pr_data.outputs.data).head.ref }} \ |
88 | | - -Dsonar.pullrequest.key=${{ fromJson(steps.get_pr_data.outputs.data).number }} \ |
89 | | - -Dsonar.pullrequest.base=${{ fromJson(steps.get_pr_data.outputs.data).base.ref }} \ |
90 | | - -Dsonar.scm.revision="$HEAD_SHA" \ |
91 | | - clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar |
92 | | - - name: Build and analyze (Push) |
93 | | - if: ${{ github.event.workflow_run.event == 'push' }} |
94 | | - env: |
95 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
96 | | - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
97 | | - SONAR_OPTS: ${{ steps.sonar_env.outputs.sonar_opts }} |
98 | | - HEAD_SHA: ${{ github.event.workflow_run.head_sha }} |
99 | | - HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }} |
100 | | - run: | |
101 | | - ./mvnw -B -s custom_maven_settings.xml -Psonar \ |
102 | | - $SONAR_OPTS \ |
103 | | - -Dsonar.scm.revision="$HEAD_SHA" \ |
104 | | - -Dsonar.branch.name="$HEAD_BRANCH" \ |
105 | | - clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar |
| 89 | + - name: Build and analyze (Push) |
| 90 | + if: ${{ github.event.workflow_run.event == 'push' }} |
| 91 | + env: |
| 92 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 93 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 94 | + SONAR_OPTS: ${{ steps.sonar_env.outputs.sonar_opts }} |
| 95 | + HEAD_SHA: ${{ github.event.workflow_run.head_sha }} |
| 96 | + HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }} |
| 97 | + run: | |
| 98 | + mvn -B -s custom_maven_settings.xml -Psonar \ |
| 99 | + $SONAR_OPTS \ |
| 100 | + -Dsonar.scm.revision="$HEAD_SHA" \ |
| 101 | + -Dsonar.branch.name="$HEAD_BRANCH" \ |
| 102 | + verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar |
0 commit comments