fix: CI - nproc macOS + clang install #3
This file contains hidden or 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
| # ============================================================================= | |
| # Shellcode Executor - CI/CD 构建与测试流水线 | |
| # Shellcode Executor - CI/CD Build & Test Pipeline | |
| # ============================================================================= | |
| name: Build & Test | |
| on: | |
| push: | |
| branches: [main, master] | |
| paths-ignore: | |
| - "docs/**" | |
| - "**.md" | |
| - "**.txt" | |
| pull_request: | |
| branches: [main, master] | |
| # 取消重复的正在运行的构建 / Cancel duplicate in-progress builds | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| env: | |
| BUILD_TYPE: Release | |
| jobs: | |
| # ───────────────────────────────────────────────────────── | |
| # 代码质量检查 / Code Quality | |
| # ───────────────────────────────────────────────────────── | |
| code-quality: | |
| name: Code Quality | |
| runs-on: ubuntu-latest | |
| continue-on-error: true # 不阻塞 PR / Don't block PR | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Tools | |
| run: | | |
| sudo apt-get update -qq | |
| sudo apt-get install -y -qq cppcheck clang-format 2>/dev/null || true | |
| - name: Static Analysis (cppcheck) | |
| continue-on-error: true | |
| run: | | |
| if command -v cppcheck &>/dev/null; then | |
| cppcheck --version | |
| cppcheck --enable=warning,style,performance,portability \ | |
| --suppress=missingIncludeSystem \ | |
| --suppress=unmatchedSuppression \ | |
| --error-exitcode=0 \ | |
| src/ tests/ examples/ 2>&1 || true | |
| fi | |
| echo "cppcheck check completed (non-fatal)" | |
| - name: Formatting Check (clang-format) | |
| continue-on-error: true | |
| run: | | |
| if command -v clang-format &>/dev/null; then | |
| find src/ tests/ examples/ -name "*.c" -o -name "*.h" | \ | |
| xargs clang-format --dry-run -Werror 2>&1 || \ | |
| echo "clang-format: formatting suggestions available (non-fatal)" | |
| else | |
| echo "clang-format not available, skipping" | |
| fi | |
| # ───────────────────────────────────────────────────────── | |
| # 多平台编译矩阵 / Multi-platform Build Matrix | |
| # ───────────────────────────────────────────────────────── | |
| build: | |
| name: ${{ matrix.os }} (${{ matrix.cc }}, ${{ matrix.build_type }}) | |
| needs: [code-quality] | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false # 一个失败不取消其他 / Don't cancel other jobs | |
| matrix: | |
| os: [ubuntu-latest, macos-latest] | |
| cc: [gcc, clang] | |
| build_type: [Debug, Release] | |
| exclude: | |
| # macOS 默认是 clang,跳过 gcc 以节省资源 | |
| - os: macos-latest | |
| cc: gcc | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Dependencies (Linux) | |
| if: runner.os == 'Linux' | |
| run: | | |
| sudo apt-get update -qq | |
| sudo apt-get install -y -qq cmake build-essential clang 2>/dev/null || true | |
| - name: Install Dependencies (macOS) | |
| if: runner.os == 'macOS' | |
| run: | | |
| # macOS runner 自带 cmake/clang,无需安装 | |
| echo "macOS tools pre-installed" | |
| - name: Configure CMake | |
| run: | | |
| cmake -B build \ | |
| -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ | |
| -DCMAKE_C_COMPILER=${{ matrix.cc }} \ | |
| -DENABLE_TESTS=ON \ | |
| -DENABLE_EXAMPLES=ON \ | |
| -DENABLE_ASAN=${{ matrix.build_type == 'Debug' && matrix.cc == 'gcc' && 'ON' || 'OFF' }} \ | |
| -Wno-dev | |
| - name: Build | |
| run: | | |
| JOBS=$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 2) | |
| cmake --build build -j${JOBS} 2>&1 | head -100 | |
| - name: Run Tests | |
| run: | | |
| cd build | |
| ctest --output-on-failure --timeout 30 2>&1 |