Update sonarcloud.yml #101
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: SonarQube | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| jobs: | |
| build: | |
| name: Build and analyze | |
| runs-on: ubuntu-latest | |
| env: | |
| BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | |
| - name: Install Build Wrapper | |
| uses: SonarSource/sonarqube-scan-action/install-build-wrapper@v5 | |
| - name: Build backend tests with coverage | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libgtest-dev cmake | |
| cd /usr/src/gtest && sudo cmake . && sudo make && sudo cp lib/*.a /usr/lib | |
| cd $GITHUB_WORKSPACE | |
| build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} \ | |
| g++ -std=gnu++2a -O0 -g --coverage -fprofile-arcs -ftest-coverage \ | |
| backend/grammar.cpp \ | |
| backend/grammar_factory.cpp \ | |
| backend/ll1_parser.cpp \ | |
| backend/lr0_item.cpp \ | |
| backend/slr1_parser.cpp \ | |
| backend/symbol_table.cpp \ | |
| backend/tests.cpp \ | |
| -Ibackend/include \ | |
| -lgtest -lgtest_main \ | |
| -o test_runner | |
| - name: Run tests and dump XML | |
| run: ./test_runner | |
| - name: Install lcov & generate SonarQube XML coverage | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y lcov python3-pip | |
| lcov --capture \ | |
| --directory . \ | |
| --branch-coverage \ | |
| --rc branch_coverage=1 \ | |
| --filter branch \ | |
| --exclude '/usr/*' \ | |
| --exclude '*tests.cpp' \ | |
| --ignore-errors inconsistent,source \ | |
| --output-file coverage.info | |
| lcov --rc branch_coverage=1 --filter branch --remove coverage.info --output-file coverage.info | |
| - name: Install lcov-to-cobertura converter | |
| run: | | |
| pip3 install lcov_cobertura | |
| - name: Convert LCOV to Cobertura XML | |
| run: | | |
| lcov_cobertura coverage.info \ | |
| --base-dir . \ | |
| --excludes '.*tests.cpp' \ | |
| --output coverage.xml \ | |
| --demangle | |
| - name: SonarQube Scan | |
| uses: SonarSource/sonarqube-scan-action@v5 | |
| env: | |
| SONAR_TOKEN: ${{ secrets.SONAR_KEY }} | |
| with: | |
| args: > | |
| --define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json" | |
| --define sonar.cfamily.cobertura.reportPaths=coverage.xml | |
| --define sonar.qualitygate.breakBuild=false | |