|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +name: Cppcheck |
| 19 | + |
| 20 | +on: |
| 21 | + push: |
| 22 | + branches: |
| 23 | + - develop |
| 24 | + - iotdb |
| 25 | + - rc/* |
| 26 | + paths: |
| 27 | + - '.github/workflows/cppcheck.yml' |
| 28 | + - '.mvn/**' |
| 29 | + - 'cpp/**' |
| 30 | + - 'mvnw' |
| 31 | + - 'pom.xml' |
| 32 | + pull_request: |
| 33 | + branches: |
| 34 | + - develop |
| 35 | + - dev/* |
| 36 | + - iotdb |
| 37 | + - rc/* |
| 38 | + paths: |
| 39 | + - '.github/workflows/cppcheck.yml' |
| 40 | + - '.mvn/**' |
| 41 | + - 'cpp/**' |
| 42 | + - 'mvnw' |
| 43 | + - 'pom.xml' |
| 44 | + workflow_dispatch: |
| 45 | + |
| 46 | +concurrency: |
| 47 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 48 | + cancel-in-progress: true |
| 49 | + |
| 50 | +permissions: |
| 51 | + contents: read |
| 52 | + |
| 53 | +env: |
| 54 | + CPPCHECK_VERSION: 2.17.1 |
| 55 | + CPPCHECK_SOURCE_SHA256: bfd681868248ec03855ca7c2aea7bcb1f39b8b18860d76aec805a92a967b966c |
| 56 | + MAVEN_OPTS: -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.http.retryHandler.class=standard -Dmaven.wagon.http.retryHandler.count=3 |
| 57 | + DEVELOCITY_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }} |
| 58 | + |
| 59 | +jobs: |
| 60 | + cppcheck: |
| 61 | + runs-on: ubuntu-24.04 |
| 62 | + timeout-minutes: 30 |
| 63 | + |
| 64 | + steps: |
| 65 | + - name: Checkout repository |
| 66 | + uses: actions/checkout@v7 |
| 67 | + |
| 68 | + - name: Set up JDK 17 |
| 69 | + uses: actions/setup-java@v5.6.0 |
| 70 | + with: |
| 71 | + distribution: corretto |
| 72 | + java-version: 17 |
| 73 | + |
| 74 | + - name: Cache Maven packages |
| 75 | + uses: actions/cache@v6 |
| 76 | + with: |
| 77 | + path: ~/.m2 |
| 78 | + key: ${{ runner.os }}-m2-cppcheck-${{ hashFiles('**/pom.xml') }} |
| 79 | + restore-keys: ${{ runner.os }}-m2- |
| 80 | + |
| 81 | + - name: Cache Cppcheck |
| 82 | + uses: actions/cache@v6 |
| 83 | + with: |
| 84 | + path: ~/.cache/cppcheck/${{ env.CPPCHECK_VERSION }} |
| 85 | + key: cppcheck-${{ runner.os }}-${{ runner.arch }}-${{ env.CPPCHECK_VERSION }}-${{ env.CPPCHECK_SOURCE_SHA256 }} |
| 86 | + |
| 87 | + - name: Install dependencies |
| 88 | + run: | |
| 89 | + sudo apt-get update |
| 90 | + sudo apt-get install -y uuid-dev |
| 91 | +
|
| 92 | + - name: Install Cppcheck |
| 93 | + shell: bash |
| 94 | + run: | |
| 95 | + set -euo pipefail |
| 96 | +
|
| 97 | + cppcheck_home="${HOME}/.cache/cppcheck/${CPPCHECK_VERSION}" |
| 98 | + if [[ ! -x "${cppcheck_home}/bin/cppcheck" ]]; then |
| 99 | + build_root="$(mktemp -d)" |
| 100 | + archive="${build_root}/cppcheck.tar.gz" |
| 101 | + source_dir="${build_root}/source" |
| 102 | + build_dir="${build_root}/build" |
| 103 | +
|
| 104 | + mkdir -p "${source_dir}" "${build_dir}" "${cppcheck_home}" |
| 105 | + curl --fail --location --retry 3 \ |
| 106 | + "https://github.com/cppcheck-opensource/cppcheck/archive/refs/tags/${CPPCHECK_VERSION}.tar.gz" \ |
| 107 | + --output "${archive}" |
| 108 | + echo "${CPPCHECK_SOURCE_SHA256} ${archive}" | sha256sum --check - |
| 109 | + tar -xzf "${archive}" --strip-components=1 -C "${source_dir}" |
| 110 | +
|
| 111 | + cmake -S "${source_dir}" -B "${build_dir}" \ |
| 112 | + -DCMAKE_BUILD_TYPE=Release \ |
| 113 | + -DUSE_MATCHCOMPILER=ON \ |
| 114 | + -DBUILD_GUI=OFF \ |
| 115 | + -DBUILD_TESTS=OFF \ |
| 116 | + -DCMAKE_INSTALL_PREFIX="${cppcheck_home}" |
| 117 | + cmake --build "${build_dir}" --parallel "$(nproc)" |
| 118 | + cmake --install "${build_dir}" |
| 119 | + fi |
| 120 | +
|
| 121 | + echo "${cppcheck_home}/bin" >> "${GITHUB_PATH}" |
| 122 | + "${cppcheck_home}/bin/cppcheck" --version |
| 123 | +
|
| 124 | + - name: Generate compilation database with Maven |
| 125 | + run: | |
| 126 | + ./mvnw -P with-cpp,with-cppcheck -pl cpp \ |
| 127 | + -Dbuild.test=OFF \ |
| 128 | + cmake:generate@cmake-generate-test-compile |
| 129 | + test -s cpp/target/build/compile_commands.json |
| 130 | +
|
| 131 | + - name: Run Cppcheck |
| 132 | + shell: bash |
| 133 | + run: | |
| 134 | + mkdir -p cpp/target/cppcheck |
| 135 | +
|
| 136 | + set +e |
| 137 | + cppcheck \ |
| 138 | + --project=cpp/target/build/compile_commands.json \ |
| 139 | + --file-filter='*cpp/src/*' \ |
| 140 | + --file-filter='*cpp/tools/*' \ |
| 141 | + --file-filter='*cpp/examples/*' \ |
| 142 | + --enable=warning,performance,portability \ |
| 143 | + --check-level=exhaustive \ |
| 144 | + --inline-suppr \ |
| 145 | + --suppress=missingIncludeSystem \ |
| 146 | + --suppress=unusedFunction \ |
| 147 | + --suppress='*:*/third_party/*' \ |
| 148 | + --suppress='*:*/target/*' \ |
| 149 | + --suppress='*:*/parser/generated/*' \ |
| 150 | + --exitcode-suppressions=cpp/cppcheck-baseline.txt \ |
| 151 | + --error-exitcode=2 \ |
| 152 | + --template=gcc \ |
| 153 | + --output-file=cpp/target/cppcheck/cppcheck.txt \ |
| 154 | + --quiet \ |
| 155 | + -j "$(nproc)" |
| 156 | + cppcheck_status=$? |
| 157 | + set -e |
| 158 | +
|
| 159 | + cat cpp/target/cppcheck/cppcheck.txt |
| 160 | + exit "${cppcheck_status}" |
| 161 | +
|
| 162 | + - name: Upload Cppcheck report |
| 163 | + if: always() |
| 164 | + uses: actions/upload-artifact@v7 |
| 165 | + with: |
| 166 | + name: cppcheck-report |
| 167 | + path: cpp/target/cppcheck/cppcheck.txt |
| 168 | + if-no-files-found: ignore |
0 commit comments