|
| 1 | +name: cppcheck-differential |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + |
| 6 | +jobs: |
| 7 | + cppcheck-differential: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + |
| 10 | + steps: |
| 11 | + - name: Checkout code |
| 12 | + uses: actions/checkout@v2 |
| 13 | + |
| 14 | + - name: Install dependencies |
| 15 | + run: | |
| 16 | + sudo apt-get update |
| 17 | + sudo apt-get install -y build-essential cmake git libpcre3-dev wget |
| 18 | +
|
| 19 | + # cppcheck from apt does not yet support --check-level args, and thus install from source |
| 20 | + - name: Install Cppcheck from source |
| 21 | + run: | |
| 22 | + mkdir /tmp/cppcheck |
| 23 | + git clone https://github.com/danmar/cppcheck.git /tmp/cppcheck |
| 24 | + cd /tmp/cppcheck |
| 25 | + git checkout 2.14.1 |
| 26 | + mkdir build |
| 27 | + cd build |
| 28 | + cmake .. |
| 29 | + make -j $(nproc) |
| 30 | + sudo make install |
| 31 | +
|
| 32 | + # Download the cppcheck suppression file |
| 33 | + - name: Download cppcheck suppression file |
| 34 | + run: | |
| 35 | + wget https://raw.githubusercontent.com/autowarefoundation/autoware.universe/main/.cppcheck_suppressions -O .cppcheck_suppressions |
| 36 | +
|
| 37 | + - name: Get changed files |
| 38 | + id: changed-files |
| 39 | + run: | |
| 40 | + git fetch origin ${{ github.base_ref }} --depth=1 |
| 41 | + git diff --name-only FETCH_HEAD ${{ github.sha }} > changed_files.txt |
| 42 | + cat changed_files.txt |
| 43 | +
|
| 44 | + - name: Run Cppcheck on changed files |
| 45 | + continue-on-error: true |
| 46 | + id: cppcheck |
| 47 | + run: | |
| 48 | + files=$(cat changed_files.txt | grep -E '\.(cpp|hpp)$' || true) |
| 49 | + if [ -n "$files" ]; then |
| 50 | + echo "Running Cppcheck on changed files: $files" |
| 51 | + cppcheck --enable=all --inconclusive --check-level=exhaustive --error-exitcode=1 --suppressions-list=.cppcheck_suppressions $files 2> cppcheck-report.txt |
| 52 | + else |
| 53 | + echo "No C++ files changed." |
| 54 | + touch cppcheck-report.txt |
| 55 | + fi |
| 56 | + shell: bash |
| 57 | + |
| 58 | + - name: Show cppcheck-report result |
| 59 | + run: | |
| 60 | + cat cppcheck-report.txt |
| 61 | +
|
| 62 | + - name: Upload Cppcheck report |
| 63 | + uses: actions/upload-artifact@v4 |
| 64 | + with: |
| 65 | + name: cppcheck-report |
| 66 | + path: cppcheck-report.txt |
| 67 | + |
| 68 | + - name: Fail the job if Cppcheck failed |
| 69 | + if: steps.cppcheck.outcome == 'failure' |
| 70 | + run: exit 1 |
0 commit comments