Sonar build #1049
This file contains 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: Sonar build | |
on: | |
push: | |
branches: [ master ] | |
schedule: | |
- cron: '0 9 * * 1' | |
workflow_dispatch: | |
pull_request_target: | |
branches: [ master ] | |
types: [ labeled ] | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
if: ${{ (github.repository == 'savushkin-r-d/ptusa_main') && ( (github.event_name == 'push') || (github.event_name == 'schedule') || ((github.event_name == 'pull_request_target') && (contains( github.event.pull_request.labels.*.name, 'safe to test' )))) }} | |
env: | |
SONAR_SCANNER_VERSION: 4.7.0.2747 | |
SONAR_SERVER_URL: "https://sonarcloud.io" | |
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | |
submodules: 'recursive' | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v1 | |
with: | |
java-version: 11 | |
- name: Download and set up sonar-scanner | |
env: | |
SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip | |
run: | | |
mkdir -p $HOME/.sonar | |
curl -sSLo $HOME/.sonar/sonar-scanner.zip ${{ env.SONAR_SCANNER_DOWNLOAD_URL }} | |
unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/ | |
echo "$HOME/.sonar/sonar-scanner-${{ env.SONAR_SCANNER_VERSION }}-linux/bin" >> $GITHUB_PATH | |
- name: Download and set up build-wrapper | |
env: | |
BUILD_WRAPPER_DOWNLOAD_URL: ${{ env.SONAR_SERVER_URL }}/static/cpp/build-wrapper-linux-x86.zip | |
run: | | |
curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip ${{ env.BUILD_WRAPPER_DOWNLOAD_URL }} | |
unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/ | |
echo "$HOME/.sonar/build-wrapper-linux-x86" >> $GITHUB_PATH | |
- name: Run build-wrapper | |
run: | | |
mkdir build | |
cmake -S . -B build -DCODE_COVERAGE=ON -DSKIP_DEMO=ON | |
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build/ --config Release | |
- name: Run tests | |
shell: cmake -P {0} | |
run: | | |
include(ProcessorCount) | |
ProcessorCount(N) | |
set(ENV{CTEST_OUTPUT_ON_FAILURE} "ON") | |
execute_process( | |
COMMAND ctest -j ${N} | |
WORKING_DIRECTORY build | |
RESULT_VARIABLE result | |
OUTPUT_VARIABLE output | |
ERROR_VARIABLE output | |
ECHO_OUTPUT_VARIABLE ECHO_ERROR_VARIABLE | |
) | |
if (NOT result EQUAL 0) | |
string(REGEX MATCH "[0-9]+% tests.*[0-9.]+ sec.*$" test_results "${output}") | |
string(REPLACE "\n" "%0A" test_results "${test_results}") | |
message("::error::${test_results}") | |
message(FATAL_ERROR "Running tests failed!") | |
endif() | |
- name: Install gcovr | |
run: sudo apt-get install gcovr | |
- name: Generate test summary | |
run: | | |
gcovr -r . --sonarqube ./build/coverage.xml | |
cat ./build/coverage.xml | |
- name: Run sonar-scanner | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
run: | | |
sonar-scanner --define sonar.host.url="${{ env.SONAR_SERVER_URL }}" --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" --define sonar.pullrequest.key=${{ github.event.pull_request.number }} --define sonar.scm.revision=${{ github.event.pull_request.head.sha }} |