Commit 7b1eeefaeec320464cf80fede64f76fe6d18e3c7
1 parent
49cd81e2
feat(actions): code-analyze the project with SonarCloud
Showing
1 changed file
with
86 additions
and
0 deletions
.github/workflows/sonarcloud.yaml
0 → 100644
| 1 | +name: Build | |
| 2 | + | |
| 3 | +on: | |
| 4 | + push: | |
| 5 | + branches: | |
| 6 | + - main | |
| 7 | + pull_request: | |
| 8 | + branches: | |
| 9 | + - main | |
| 10 | + | |
| 11 | +jobs: | |
| 12 | + build: | |
| 13 | + name: Build | |
| 14 | + runs-on: ubuntu-latest | |
| 15 | + | |
| 16 | + env: | |
| 17 | + SONAR_SCANNER_VERSION: 4.7.0.2747 | |
| 18 | + | |
| 19 | + steps: | |
| 20 | + - name: Checkout | |
| 21 | + uses: actions/checkout@v3 | |
| 22 | + | |
| 23 | + - name: Set up JDK 11 | |
| 24 | + uses: actions/setup-java@v3 | |
| 25 | + with: | |
| 26 | + distribution: temurin | |
| 27 | + java-version: 11 | |
| 28 | + | |
| 29 | + - name: Cache SonarCloud | |
| 30 | + id: cache-sonarcloud | |
| 31 | + uses: actions/cache@v3 | |
| 32 | + with: | |
| 33 | + path: .sonar | |
| 34 | + key: sonar-${{ runner.os }}-${{ env.SONAR_SCANNER_VERSION }} | |
| 35 | + | |
| 36 | + - name: Cache SonarCloud-Cache | |
| 37 | + uses: actions/cache@v3 | |
| 38 | + with: | |
| 39 | + path: .sonar-cache | |
| 40 | + key: sonar-cache-${{ runner.os }}-${{ env.SONAR_SCANNER_VERSION }}-${{ hashFiles('src/**') }} | |
| 41 | + restore-keys: | | |
| 42 | + sonar-cache-${{ runner.os }}-${{ env.SONAR_SCANNER_VERSION }}- | |
| 43 | + sonar-cache-${{ runner.os }}- | |
| 44 | + sonar-cache- | |
| 45 | + | |
| 46 | + - name: Download SonarCloud | |
| 47 | + if: steps.cache-sonarcloud.outputs.cache-hit != 'true' | |
| 48 | + run: | | |
| 49 | + mkdir .sonar | |
| 50 | + | |
| 51 | + curl -sSLo .sonar/sonar-scanner.zip ${{ env.SONAR_SCANNER_DOWNLOAD_URL }} | |
| 52 | + unzip -o .sonar/sonar-scanner.zip -d .sonar/ | |
| 53 | + | |
| 54 | + curl -sSLo .sonar/build-wrapper-linux-x86.zip ${{ env.BUILD_WRAPPER_DOWNLOAD_URL }} | |
| 55 | + unzip -o .sonar/build-wrapper-linux-x86.zip -d .sonar/ | |
| 56 | + env: | |
| 57 | + SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip | |
| 58 | + BUILD_WRAPPER_DOWNLOAD_URL: https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip | |
| 59 | + | |
| 60 | + - name: Setup SonarCloud | |
| 61 | + run: | | |
| 62 | + echo "$(pwd)/.sonar/sonar-scanner-${{ env.SONAR_SCANNER_VERSION }}-linux/bin" >> $GITHUB_PATH | |
| 63 | + echo "$(pwd)/.sonar/build-wrapper-linux-x86" >> $GITHUB_PATH | |
| 64 | + | |
| 65 | + - name: Compile | |
| 66 | + run: | | |
| 67 | + mkdir build | |
| 68 | + cd build | |
| 69 | + build-wrapper-linux-x86-64 --out-dir ../.build-wrapper-out cmake .. -DMIN_LOGGER_LEVEL=TRACE | |
| 70 | + build-wrapper-linux-x86-64 --out-dir ../.build-wrapper-out make -j$(nproc) | |
| 71 | + | |
| 72 | + - name: Run SonarCloud | |
| 73 | + run: | | |
| 74 | + sonar-scanner \ | |
| 75 | + --define sonar.host.url="https://sonarcloud.io/" \ | |
| 76 | + --define sonar.cfamily.build-wrapper-output=".build-wrapper-out" \ | |
| 77 | + --define sonar.projectKey=TrueBrain_TrueMQTT-cpp \ | |
| 78 | + --define sonar.organization=truebrain \ | |
| 79 | + --define sonar.projectName=TrueMQTT-cpp \ | |
| 80 | + --define sonar.sources=src \ | |
| 81 | + --define sonar.sourceEncoding=UTF-8 \ | |
| 82 | + --define sonar.cfamily.cache.enabled=true \ | |
| 83 | + --define sonar.cfamily.cache.path=.sonar-cache | |
| 84 | + env: | |
| 85 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| 86 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ... | ... |