Debian GCC持续集成实践
一 环境与工具链
二 流水线设计
三 示例配置
name: CI
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
jobs:
build-matrix:
runs-on: ubuntu-latest
strategy:
matrix:
compiler: [gcc-12, gcc-13]
build_type: [Debug, Release]
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Install deps
run: sudo apt-get update && sudo apt-get install -y build-essential cmake cppcheck clang-tidy clang-format lcov valgrind
- name: Cache toolchain and ccache
uses: actions/cache@v3
with:
path: |
/usr/lib/ccache
~/.ccache
key: ${{ runner.os }}-${{ matrix.compiler }}-${{ matrix.build_type }}-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: |
${{ runner.os }}-${{ matrix.compiler }}-${{ matrix.build_type }}-
- name: Configure
env:
CC: ${{ matrix.compiler }}
CXX: ${{ matrix.compiler == 'gcc-12' && 'g++-12' || 'g++-13' }}
run: |
mkdir -p build && cd build
cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_CXX_FLAGS="--coverage" ..
- name: Build
working-directory: build
run: make -j$(nproc)
- name: Static checks
run: |
cppcheck --enable=all --inconclusive --std=c++17 src/ || true
clang-tidy -p build src/**/*.cpp -- -std=c++17 || true
git diff --exit-code || (echo "Style issues found"; exit 1)
- name: Test and coverage
working-directory: build
run: |
ctest --output-on-failure
lcov --capture --directory . --output-file coverage.info
lcov --remove coverage.info '/usr/*' '*/tests/*' --output-file coverage.filtered.info
genhtml coverage.filtered.info --output-directory coverage-report
- name: Upload coverage
uses: codecov/codecov-action@v3
with:
files: build/coverage.filtered.info
pipeline {
agent any
tools { gcc 'gcc-12' }
options { timeout(time: 60, unit: 'MINUTES') }
stages {
stage('Install') {
steps { sh 'sudo apt-get update && sudo apt-get install -y build-essential cmake cppcheck clang-tidy clang-format lcov valgrind' }
}
stage('Build') {
steps {
sh 'mkdir -p build && cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && make -j$(nproc)'
}
}
stage('Static Checks') {
steps {
sh 'cppcheck --enable=all --inconclusive src/ || true'
sh 'clang-tidy -p build src/**/*.cpp -- -std=c++17 || true'
}
}
stage('Test and Coverage') {
steps {
sh 'cd build && ctest --output-on-failure'
sh 'lcov --capture --directory . --output-file coverage.info'
sh 'lcov --remove coverage.info "/usr/*" "*/tests/*" --output-file coverage.filtered.info'
sh 'genhtml coverage.filtered.info --output-directory coverage-report'
}
post { always { publishHTML(target: [reportDir: 'build/coverage-report', reportFiles: 'index.html', reportName: 'Coverage']) } }
}
}
post { always { junit 'build/Testing/**/*.xml' } }
}
上述示例展示了在GitHub Actions与Jenkins中如何组织矩阵构建、静态检查、覆盖率与报告归档,便于在Debian环境下快速落地CI。
四 质量门禁与度量
五 性能优化与故障排查