|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +name: Sonar Quality Check (Reusable) |
| 19 | + |
| 20 | +on: |
| 21 | + workflow_call: |
| 22 | + inputs: |
| 23 | + is_pr: |
| 24 | + description: 'true when called from a pull_request trigger' |
| 25 | + type: boolean |
| 26 | + required: true |
| 27 | + secrets: |
| 28 | + GITHUB_TOKEN: |
| 29 | + required: true |
| 30 | + SONAR_TOKEN: |
| 31 | + required: false |
| 32 | + |
| 33 | +permissions: |
| 34 | + contents: read |
| 35 | + pull-requests: write |
| 36 | + |
| 37 | +jobs: |
| 38 | + build: |
| 39 | + name: Sonar JaCoCo Coverage |
| 40 | + runs-on: ubuntu-22.04 |
| 41 | + steps: |
| 42 | + # PR callers check out the merge commit; branch callers use the pushed SHA. |
| 43 | + - uses: actions/checkout@v6 |
| 44 | + with: |
| 45 | + ref: ${{ inputs.is_pr && format('refs/pull/{0}/merge', github.event.number) || github.sha }} |
| 46 | + fetch-depth: 0 |
| 47 | + |
| 48 | + - name: Set up JDK17 |
| 49 | + uses: actions/setup-java@v5 |
| 50 | + with: |
| 51 | + distribution: 'temurin' |
| 52 | + java-version: '17' |
| 53 | + cache: 'maven' |
| 54 | + |
| 55 | + - name: Cache SonarCloud packages |
| 56 | + uses: actions/cache@v5 |
| 57 | + with: |
| 58 | + path: ~/.sonar/cache |
| 59 | + key: ${{ runner.os }}-sonar |
| 60 | + restore-keys: ${{ runner.os }}-sonar |
| 61 | + |
| 62 | + - name: Cache local Maven repository |
| 63 | + uses: actions/cache@v5 |
| 64 | + with: |
| 65 | + path: ~/.m2/repository |
| 66 | + key: ${{ runner.os }}-m2-${{ hashFiles('pom.xml', '*/pom.xml', '*/*/pom.xml', '*/*/*/pom.xml') }} |
| 67 | + restore-keys: | |
| 68 | + ${{ runner.os }}-m2 |
| 69 | +
|
| 70 | + - name: Install Non-OSS |
| 71 | + run: | |
| 72 | + git clone https://github.com/shapeblue/cloudstack-nonoss.git nonoss |
| 73 | + cd nonoss && bash -x install-non-oss.sh && cd .. |
| 74 | +
|
| 75 | + - name: Run Build and Tests with Coverage (PR) |
| 76 | + if: inputs.is_pr |
| 77 | + env: |
| 78 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 79 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 80 | + PR_ID: ${{ github.event.pull_request.number }} |
| 81 | + HEADREF: ${{ github.event.pull_request.head.ref }} |
| 82 | + run: > |
| 83 | + mvn -T$(nproc) -P quality -Dsimulator -Dnoredist clean install |
| 84 | + org.sonarsource.scanner.maven:sonar-maven-plugin:sonar |
| 85 | + -Dsonar.projectKey=apache_cloudstack |
| 86 | + -Dsonar.pullrequest.key="$PR_ID" |
| 87 | + -Dsonar.pullrequest.branch="$HEADREF" |
| 88 | + -Dsonar.pullrequest.github.repository=apache/cloudstack |
| 89 | + -Dsonar.pullrequest.provider=GitHub |
| 90 | + -Dsonar.pullrequest.github.summary_comment=true |
| 91 | +
|
| 92 | + - name: Run Tests with Coverage (Main) |
| 93 | + if: "!inputs.is_pr" |
| 94 | + env: |
| 95 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 96 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 97 | + run: > |
| 98 | + mvn -T$(nproc) -P quality -Dsimulator -Dnoredist clean install |
| 99 | + org.sonarsource.scanner.maven:sonar-maven-plugin:sonar |
| 100 | + -Dsonar.projectKey=apache_cloudstack |
0 commit comments