|
| 1 | +name: JSON Strict CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, master, dev] |
| 6 | + paths: |
| 7 | + - ".github/workflows/json-strict-ci.yml" |
| 8 | + - "CMakeLists.txt" |
| 9 | + - "include/**" |
| 10 | + - "examples/**" |
| 11 | + - "scripts/**" |
| 12 | + - "README.md" |
| 13 | + - "CHANGELOG.md" |
| 14 | + - "CONTRIBUTING.md" |
| 15 | + - "vix.json" |
| 16 | + pull_request: |
| 17 | + branches: [main, master, dev] |
| 18 | + paths: |
| 19 | + - ".github/workflows/json-strict-ci.yml" |
| 20 | + - "CMakeLists.txt" |
| 21 | + - "include/**" |
| 22 | + - "examples/**" |
| 23 | + - "scripts/**" |
| 24 | + - "README.md" |
| 25 | + - "CHANGELOG.md" |
| 26 | + - "CONTRIBUTING.md" |
| 27 | + - "vix.json" |
| 28 | + workflow_dispatch: |
| 29 | + |
| 30 | +permissions: |
| 31 | + contents: read |
| 32 | + |
| 33 | +env: |
| 34 | + DEPS: > |
| 35 | + build-essential |
| 36 | + cmake |
| 37 | + ninja-build |
| 38 | + clang |
| 39 | + llvm |
| 40 | + lld |
| 41 | + g++ |
| 42 | + cppcheck |
| 43 | + clang-tidy |
| 44 | + valgrind |
| 45 | + pkg-config |
| 46 | + git |
| 47 | + nlohmann-json3-dev |
| 48 | + BUILD_JOBS: 2 |
| 49 | + |
| 50 | +jobs: |
| 51 | + build: |
| 52 | + name: Build (${{ matrix.compiler }}, examples=${{ matrix.examples }}, provider=${{ matrix.provider }}) |
| 53 | + runs-on: ubuntu-latest |
| 54 | + strategy: |
| 55 | + fail-fast: false |
| 56 | + matrix: |
| 57 | + compiler: [clang, gcc] |
| 58 | + examples: [ON, OFF] |
| 59 | + provider: [system, fallback] |
| 60 | + |
| 61 | + steps: |
| 62 | + - name: Checkout json repository |
| 63 | + uses: actions/checkout@v4 |
| 64 | + with: |
| 65 | + fetch-depth: 0 |
| 66 | + |
| 67 | + - name: Install dependencies |
| 68 | + run: | |
| 69 | + sudo apt-get update -y |
| 70 | + sudo apt-get install -y $DEPS |
| 71 | +
|
| 72 | + - name: Remove system nlohmann_json for fallback mode |
| 73 | + if: matrix.provider == 'fallback' |
| 74 | + run: | |
| 75 | + sudo apt-get remove -y nlohmann-json3-dev || true |
| 76 | + dpkg -l | grep nlohmann || true |
| 77 | +
|
| 78 | + - name: Select compiler |
| 79 | + run: | |
| 80 | + if [ "${{ matrix.compiler }}" = "clang" ]; then |
| 81 | + echo "CC=clang" >> "$GITHUB_ENV" |
| 82 | + echo "CXX=clang++" >> "$GITHUB_ENV" |
| 83 | + else |
| 84 | + echo "CC=gcc" >> "$GITHUB_ENV" |
| 85 | + echo "CXX=g++" >> "$GITHUB_ENV" |
| 86 | + fi |
| 87 | +
|
| 88 | + - name: Configure |
| 89 | + run: | |
| 90 | + cmake -G Ninja -S . -B build \ |
| 91 | + -DCMAKE_BUILD_TYPE=Debug \ |
| 92 | + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ |
| 93 | + -DVIX_JSON_BUILD_EXAMPLES=${{ matrix.examples }} |
| 94 | +
|
| 95 | + - name: Build |
| 96 | + run: | |
| 97 | + cmake --build build -j"${BUILD_JOBS}" |
| 98 | +
|
| 99 | + - name: Print executables |
| 100 | + run: | |
| 101 | + echo "---- executables ----" |
| 102 | + find build -type f -executable | sort || true |
| 103 | +
|
| 104 | + runtime-smoke: |
| 105 | + name: Runtime Smoke Checks |
| 106 | + runs-on: ubuntu-latest |
| 107 | + |
| 108 | + steps: |
| 109 | + - name: Checkout json repository |
| 110 | + uses: actions/checkout@v4 |
| 111 | + with: |
| 112 | + fetch-depth: 0 |
| 113 | + |
| 114 | + - name: Install dependencies |
| 115 | + run: | |
| 116 | + sudo apt-get update -y |
| 117 | + sudo apt-get install -y $DEPS |
| 118 | +
|
| 119 | + - name: Configure runtime build |
| 120 | + run: | |
| 121 | + cmake -G Ninja -S . -B build-runtime \ |
| 122 | + -DCMAKE_BUILD_TYPE=Debug \ |
| 123 | + -DVIX_JSON_BUILD_EXAMPLES=ON |
| 124 | +
|
| 125 | + - name: Build runtime artifacts |
| 126 | + run: | |
| 127 | + cmake --build build-runtime -j"${BUILD_JOBS}" |
| 128 | +
|
| 129 | + - name: List candidate executables |
| 130 | + run: | |
| 131 | + echo "---- runtime candidates ----" |
| 132 | + find build-runtime -type f -executable | sort || true |
| 133 | +
|
| 134 | + - name: Run smoke tests on executables |
| 135 | + shell: bash |
| 136 | + run: | |
| 137 | + set +e |
| 138 | + FAIL=0 |
| 139 | +
|
| 140 | + mapfile -t CANDIDATES < <( |
| 141 | + find build-runtime -type f -executable | while read -r exe; do |
| 142 | + base="$(basename "$exe")" |
| 143 | + if [[ ! "$exe" =~ /CMakeFiles/ ]] && [[ ! "$base" =~ (cmake|ctest) ]]; then |
| 144 | + echo "$exe" |
| 145 | + fi |
| 146 | + done | sort -u |
| 147 | + ) |
| 148 | +
|
| 149 | + if [ ${#CANDIDATES[@]} -eq 0 ]; then |
| 150 | + echo "No executable candidates found." |
| 151 | + exit 0 |
| 152 | + fi |
| 153 | +
|
| 154 | + for exe in "${CANDIDATES[@]}"; do |
| 155 | + echo "==> Smoke run: $exe" |
| 156 | + timeout 5s "$exe" >/tmp/json_smoke.log 2>&1 |
| 157 | + STATUS=$? |
| 158 | + cat /tmp/json_smoke.log || true |
| 159 | +
|
| 160 | + if [ $STATUS -ne 0 ] && [ $STATUS -ne 124 ]; then |
| 161 | + echo "::warning::Non-zero exit status from $exe (status=$STATUS)" |
| 162 | + FAIL=1 |
| 163 | + fi |
| 164 | + done |
| 165 | +
|
| 166 | + if [ $FAIL -ne 0 ]; then |
| 167 | + echo "::warning::Some smoke runs reported issues." |
| 168 | + else |
| 169 | + echo "Smoke runs completed." |
| 170 | + fi |
| 171 | + exit 0 |
| 172 | +
|
| 173 | + static-analysis: |
| 174 | + name: Static Analysis |
| 175 | + runs-on: ubuntu-latest |
| 176 | + |
| 177 | + steps: |
| 178 | + - name: Checkout json repository |
| 179 | + uses: actions/checkout@v4 |
| 180 | + with: |
| 181 | + fetch-depth: 0 |
| 182 | + |
| 183 | + - name: Install dependencies |
| 184 | + run: | |
| 185 | + sudo apt-get update -y |
| 186 | + sudo apt-get install -y $DEPS |
| 187 | +
|
| 188 | + - name: Configure for analysis |
| 189 | + run: | |
| 190 | + cmake -G Ninja -S . -B build-analyze \ |
| 191 | + -DCMAKE_BUILD_TYPE=Debug \ |
| 192 | + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ |
| 193 | + -DVIX_JSON_BUILD_EXAMPLES=ON |
| 194 | +
|
| 195 | + - name: Run clang-tidy on example files |
| 196 | + run: | |
| 197 | + set +e |
| 198 | + find examples -name '*.cpp' -print0 | xargs -0 -n1 -P2 clang-tidy -p build-analyze |
| 199 | + STATUS=$? |
| 200 | + if [ $STATUS -ne 0 ]; then |
| 201 | + echo "::warning::clang-tidy reported issues." |
| 202 | + else |
| 203 | + echo "clang-tidy completed successfully." |
| 204 | + fi |
| 205 | + exit 0 |
| 206 | +
|
| 207 | + - name: Run cppcheck on headers and examples |
| 208 | + run: | |
| 209 | + set +e |
| 210 | + cppcheck \ |
| 211 | + --enable=all \ |
| 212 | + --std=c++20 \ |
| 213 | + --inconclusive \ |
| 214 | + --quiet \ |
| 215 | + --suppress=missingIncludeSystem \ |
| 216 | + include/ examples/ |
| 217 | + STATUS=$? |
| 218 | + if [ $STATUS -ne 0 ]; then |
| 219 | + echo "::warning::cppcheck reported issues." |
| 220 | + else |
| 221 | + echo "cppcheck completed successfully." |
| 222 | + fi |
| 223 | + exit 0 |
| 224 | +
|
| 225 | + valgrind: |
| 226 | + name: Valgrind Checks |
| 227 | + runs-on: ubuntu-latest |
| 228 | + timeout-minutes: 30 |
| 229 | + |
| 230 | + steps: |
| 231 | + - name: Checkout json repository |
| 232 | + uses: actions/checkout@v4 |
| 233 | + with: |
| 234 | + fetch-depth: 0 |
| 235 | + |
| 236 | + - name: Install dependencies |
| 237 | + run: | |
| 238 | + sudo apt-get update -y |
| 239 | + sudo apt-get install -y $DEPS |
| 240 | +
|
| 241 | + - name: Configure valgrind build |
| 242 | + run: | |
| 243 | + cmake -G Ninja -S . -B build-valgrind \ |
| 244 | + -DCMAKE_BUILD_TYPE=Debug \ |
| 245 | + -DVIX_JSON_BUILD_EXAMPLES=ON |
| 246 | +
|
| 247 | + - name: Build |
| 248 | + run: | |
| 249 | + cmake --build build-valgrind -j"${BUILD_JOBS}" |
| 250 | +
|
| 251 | + - name: Run valgrind on executables |
| 252 | + shell: bash |
| 253 | + run: | |
| 254 | + set +e |
| 255 | + FAIL=0 |
| 256 | +
|
| 257 | + mapfile -t BINS < <( |
| 258 | + find build-valgrind -type f -executable | while read -r exe; do |
| 259 | + base="$(basename "$exe")" |
| 260 | + if [[ ! "$exe" =~ /CMakeFiles/ ]] && [[ ! "$base" =~ (cmake|ctest) ]]; then |
| 261 | + echo "$exe" |
| 262 | + fi |
| 263 | + done | sort -u |
| 264 | + ) |
| 265 | +
|
| 266 | + if [ ${#BINS[@]} -eq 0 ]; then |
| 267 | + echo "No candidate executables found for valgrind." |
| 268 | + exit 0 |
| 269 | + fi |
| 270 | +
|
| 271 | + for exe in "${BINS[@]}"; do |
| 272 | + echo "==> Valgrind: $exe" |
| 273 | + timeout 20s valgrind \ |
| 274 | + --leak-check=full \ |
| 275 | + --show-leak-kinds=all \ |
| 276 | + --track-origins=yes \ |
| 277 | + "$exe" |
| 278 | + STATUS=$? |
| 279 | +
|
| 280 | + if [ $STATUS -ne 0 ] && [ $STATUS -ne 124 ]; then |
| 281 | + echo "::warning::Valgrind reported issues for $exe" |
| 282 | + FAIL=1 |
| 283 | + fi |
| 284 | + done |
| 285 | +
|
| 286 | + if [ $FAIL -ne 0 ]; then |
| 287 | + echo "::warning::Valgrind detected potential issues." |
| 288 | + else |
| 289 | + echo "Valgrind checks completed." |
| 290 | + fi |
| 291 | + exit 0 |
| 292 | +
|
| 293 | + standalone-package-check: |
| 294 | + name: Standalone Package Export Check |
| 295 | + runs-on: ubuntu-latest |
| 296 | + |
| 297 | + steps: |
| 298 | + - name: Checkout json repository |
| 299 | + uses: actions/checkout@v4 |
| 300 | + with: |
| 301 | + fetch-depth: 0 |
| 302 | + |
| 303 | + - name: Install dependencies |
| 304 | + run: | |
| 305 | + sudo apt-get update -y |
| 306 | + sudo apt-get install -y $DEPS |
| 307 | +
|
| 308 | + - name: Configure installable standalone build |
| 309 | + run: | |
| 310 | + cmake -G Ninja -S . -B build-install \ |
| 311 | + -DCMAKE_BUILD_TYPE=Release \ |
| 312 | + -DVIX_JSON_BUILD_EXAMPLES=OFF \ |
| 313 | + -DCMAKE_INSTALL_PREFIX="${PWD}/.ci-install" |
| 314 | +
|
| 315 | + - name: Build standalone package |
| 316 | + run: | |
| 317 | + cmake --build build-install -j"${BUILD_JOBS}" |
| 318 | +
|
| 319 | + - name: Install standalone package |
| 320 | + run: | |
| 321 | + cmake --install build-install |
| 322 | +
|
| 323 | + - name: Verify installed package files |
| 324 | + run: | |
| 325 | + echo "---- install tree ----" |
| 326 | + find .ci-install -maxdepth 6 -type f | sort || true |
| 327 | + test -f .ci-install/include/vix/json/json.hpp || (echo "::error::json headers not found"; exit 1) |
| 328 | +
|
| 329 | + config-coverage: |
| 330 | + name: Configuration Coverage |
| 331 | + runs-on: ubuntu-latest |
| 332 | + |
| 333 | + steps: |
| 334 | + - name: Checkout json repository |
| 335 | + uses: actions/checkout@v4 |
| 336 | + with: |
| 337 | + fetch-depth: 0 |
| 338 | + |
| 339 | + - name: Install dependencies |
| 340 | + run: | |
| 341 | + sudo apt-get update -y |
| 342 | + sudo apt-get install -y $DEPS |
| 343 | +
|
| 344 | + - name: Configure release mode without examples |
| 345 | + run: | |
| 346 | + cmake -G Ninja -S . -B build-release-min \ |
| 347 | + -DCMAKE_BUILD_TYPE=Release \ |
| 348 | + -DVIX_JSON_BUILD_EXAMPLES=OFF |
| 349 | +
|
| 350 | + - name: Build release mode without examples |
| 351 | + run: | |
| 352 | + cmake --build build-release-min -j"${BUILD_JOBS}" |
| 353 | +
|
| 354 | + - name: Configure release mode with examples |
| 355 | + run: | |
| 356 | + cmake -G Ninja -S . -B build-release-examples \ |
| 357 | + -DCMAKE_BUILD_TYPE=Release \ |
| 358 | + -DVIX_JSON_BUILD_EXAMPLES=ON |
| 359 | +
|
| 360 | + - name: Build release mode with examples |
| 361 | + run: | |
| 362 | + cmake --build build-release-examples -j"${BUILD_JOBS}" |
| 363 | +
|
| 364 | + summary: |
| 365 | + name: JSON Strict CI Summary |
| 366 | + needs: |
| 367 | + [ |
| 368 | + build, |
| 369 | + runtime-smoke, |
| 370 | + static-analysis, |
| 371 | + valgrind, |
| 372 | + standalone-package-check, |
| 373 | + config-coverage, |
| 374 | + ] |
| 375 | + runs-on: ubuntu-latest |
| 376 | + |
| 377 | + steps: |
| 378 | + - name: Print summary |
| 379 | + run: | |
| 380 | + echo "JSON strict CI completed." |
| 381 | + echo "This workflow validates:" |
| 382 | + echo "- header-only build" |
| 383 | + echo "- system provider mode" |
| 384 | + echo "- fallback provider mode" |
| 385 | + echo "- examples build" |
| 386 | + echo "- runtime smoke checks" |
| 387 | + echo "- static analysis" |
| 388 | + echo "- valgrind" |
| 389 | + echo "- standalone package export" |
0 commit comments