aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/sonarcloud.yml
blob: 5c92e73ffd6b2fa43448a68544ec01ad5b83e694 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
on:
  push:
    branches:
      - main
      - tmp
  pull_request:
      types: [opened, synchronize, reopened]

name: Sonarcloud Scan
jobs:
  sonarcloud:
    runs-on: ubuntu-latest
    env:
      BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory
    steps:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 0
    - name: Set up Python 3.8 for gcovr
      uses: actions/setup-python@v4
      with:
        python-version: 3.8
    - name: install gcovr 5.0
      run: |
        pip install gcovr==5.0 # 5.1 is not supported
    - name: Install sonar-scanner and build-wrapper
      uses: SonarSource/sonarcloud-github-c-cpp@v3.2.0
    - name: Install Prerequisites
      run: |
        sudo apt-get update
        sudo apt-get install autoconf automake cmake lcov \
            libtool pkg-config gettext \
            libjson-c-dev flex bison \
            libcurl4-openssl-dev libpcap-dev zlib1g-dev
    - name: Run build-wrapper
      run: |
        build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} ./scripts/build-sonarcloud.sh
    - name: Run tests
      run: |
        for file in $(ls libnDPI/tests/cfgs/*/pcap/*.pcap libnDPI/tests/cfgs/*/pcap/*.pcapng libnDPI/tests/cfgs/*/pcap/*.cap); do \
            echo -n "${file} "; \
            cd ./build-sonarcloud; \
            ./nDPId-test "../${file}" >/dev/null 2>/dev/null; \
            cd ..; \
            echo "[ok]"; \
        done
        mkdir -p gcov_report
        cd gcov_report
        gcov ../build-sonarcloud/CMakeFiles/nDPId-test.dir/nDPId-test.c.o
        cd ..
    - name: Run sonar-scanner
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
      run: |
        sonar-scanner \
            --define sonar.projectName=nDPId \
            --define sonar.projectVersion=1.7 \
            --define sonar.sourceEncoding=UTF-8 \
            --define sonar.branch.name=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} \
            --define sonar.organization=lnslbrty \
            --define sonar.projectKey=lnslbrty_nDPId \
            --define sonar.python.version=3.8 \
            --define sonar.cfamily.compile-commands=${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json \
            --define sonar.cfamily.gcov.reportsPath=gcov_report \
            --define sonar.exclusions=build-sonarcloud/**,libnDPI/**,test/results/**,dependencies/jsmn/**,dependencies/uthash/**,examples/js-rt-analyzer-frontend/**,examples/js-rt-analyzer/**,examples/c-collectd/www/**,examples/py-flow-dashboard/assets/**