feat: 添加 CI/CD 流水线和代码质量检查 #6
Workflow file for this run
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
| name: Code Quality | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| pull_request: | |
| branches: [ main, develop ] | |
| env: | |
| BUILD_TYPE: Debug | |
| jobs: | |
| # Address Sanitizer | |
| asan: | |
| name: Address Sanitizer | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install system dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y \ | |
| cmake \ | |
| build-essential \ | |
| git \ | |
| pkg-config \ | |
| libgoogle-perftools-dev | |
| - name: Cache vcpkg | |
| id: cache-vcpkg | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.vcpkg/archives | |
| ~/.vcpkg/git | |
| key: ${{ runner.os }}-vcpkg-asan-${{ hashFiles('vcpkg.json') }} | |
| - name: Install vcpkg | |
| run: | | |
| # Remove existing empty vcpkg directory if it exists | |
| if [ -d "vcpkg" ] && [ -z "$(ls -A vcpkg)" ]; then | |
| rm -rf vcpkg | |
| fi | |
| # Clone vcpkg if it doesn't exist | |
| if [ ! -d "vcpkg" ]; then | |
| git clone https://github.com/Microsoft/vcpkg.git | |
| fi | |
| # Verify clone was successful | |
| if [ ! -f "vcpkg/bootstrap-vcpkg.sh" ]; then | |
| echo "ERROR: bootstrap-vcpkg.sh not found in vcpkg directory" | |
| echo "vcpkg directory contents:" | |
| ls -la vcpkg/ | |
| exit 1 | |
| fi | |
| cd vcpkg | |
| if [ ! -f "vcpkg" ]; then | |
| ./bootstrap-vcpkg.sh | |
| fi | |
| - name: Install vcpkg dependencies | |
| run: | | |
| cd vcpkg | |
| ./vcpkg install --triplet=x64-linux-release | |
| - name: Configure CMake with ASan | |
| run: | | |
| mkdir build | |
| cd build | |
| cmake .. \ | |
| -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} \ | |
| -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake \ | |
| -DVCPKG_TARGET_TRIPLET=x64-linux-release \ | |
| -DCMAKE_CXX_FLAGS="-fsanitize=address -fno-omit-frame-pointer -g" \ | |
| -DCMAKE_C_FLAGS="-fsanitize=address -fno-omit-frame-pointer -g" \ | |
| -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address" \ | |
| -DCMAKE_MODULE_LINKER_FLAGS="-fsanitize=address" | |
| - name: Build | |
| run: | | |
| cd build | |
| make -j$(nproc) | |
| - name: Run tests with ASan | |
| working-directory: build | |
| run: | | |
| ctest --output-on-failure --verbose | |
| env: | |
| ASAN_OPTIONS: detect_leaks=1:halt_on_error=0 | |
| # Undefined Behavior Sanitizer | |
| ubsan: | |
| name: Undefined Behavior Sanitizer | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install system dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y \ | |
| cmake \ | |
| build-essential \ | |
| git \ | |
| pkg-config \ | |
| libgoogle-perftools-dev | |
| - name: Cache vcpkg | |
| id: cache-vcpkg | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.vcpkg/archives | |
| ~/.vcpkg/git | |
| key: ${{ runner.os }}-vcpkg-ubsan-${{ hashFiles('vcpkg.json') }} | |
| - name: Install vcpkg | |
| run: | | |
| # Remove existing empty vcpkg directory if it exists | |
| if [ -d "vcpkg" ] && [ -z "$(ls -A vcpkg)" ]; then | |
| rm -rf vcpkg | |
| fi | |
| # Clone vcpkg if it doesn't exist | |
| if [ ! -d "vcpkg" ]; then | |
| git clone https://github.com/Microsoft/vcpkg.git | |
| fi | |
| # Verify clone was successful | |
| if [ ! -f "vcpkg/bootstrap-vcpkg.sh" ]; then | |
| echo "ERROR: bootstrap-vcpkg.sh not found in vcpkg directory" | |
| echo "vcpkg directory contents:" | |
| ls -la vcpkg/ | |
| exit 1 | |
| fi | |
| cd vcpkg | |
| if [ ! -f "vcpkg" ]; then | |
| ./bootstrap-vcpkg.sh | |
| fi | |
| - name: Install vcpkg dependencies | |
| run: | | |
| cd vcpkg | |
| ./vcpkg install --triplet=x64-linux-release | |
| - name: Configure CMake with UBSan | |
| run: | | |
| mkdir build | |
| cd build | |
| cmake .. \ | |
| -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} \ | |
| -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake \ | |
| -DVCPKG_TARGET_TRIPLET=x64-linux-release \ | |
| -DCMAKE_CXX_FLAGS="-fsanitize=undefined -g" \ | |
| -DCMAKE_C_FLAGS="-fsanitize=undefined -g" \ | |
| -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=undefined" \ | |
| -DCMAKE_MODULE_LINKER_FLAGS="-fsanitize=undefined" | |
| - name: Build | |
| run: | | |
| cd build | |
| make -j$(nproc) | |
| - name: Run tests with UBSan | |
| working-directory: build | |
| run: | | |
| ctest --output-on-failure --verbose | |
| env: | |
| UBSAN_OPTIONS: print_stacktrace=1:halt_on_error=0 | |
| # Thread Sanitizer | |
| tsan: | |
| name: Thread Sanitizer | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install system dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y \ | |
| cmake \ | |
| build-essential \ | |
| git \ | |
| pkg-config \ | |
| libgoogle-perftools-dev | |
| - name: Cache vcpkg | |
| id: cache-vcpkg | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.vcpkg/archives | |
| ~/.vcpkg/git | |
| key: ${{ runner.os }}-vcpkg-tsan-${{ hashFiles('vcpkg.json') }} | |
| - name: Install vcpkg | |
| run: | | |
| # Remove existing empty vcpkg directory if it exists | |
| if [ -d "vcpkg" ] && [ -z "$(ls -A vcpkg)" ]; then | |
| rm -rf vcpkg | |
| fi | |
| # Clone vcpkg if it doesn't exist | |
| if [ ! -d "vcpkg" ]; then | |
| git clone https://github.com/Microsoft/vcpkg.git | |
| fi | |
| # Verify clone was successful | |
| if [ ! -f "vcpkg/bootstrap-vcpkg.sh" ]; then | |
| echo "ERROR: bootstrap-vcpkg.sh not found in vcpkg directory" | |
| echo "vcpkg directory contents:" | |
| ls -la vcpkg/ | |
| exit 1 | |
| fi | |
| cd vcpkg | |
| if [ ! -f "vcpkg" ]; then | |
| ./bootstrap-vcpkg.sh | |
| fi | |
| - name: Install vcpkg dependencies | |
| run: | | |
| cd vcpkg | |
| ./vcpkg install --triplet=x64-linux-release | |
| - name: Configure CMake with TSan | |
| run: | | |
| mkdir build | |
| cd build | |
| cmake .. \ | |
| -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} \ | |
| -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake \ | |
| -DVCPKG_TARGET_TRIPLET=x64-linux-release \ | |
| -DCMAKE_CXX_FLAGS="-fsanitize=thread -g" \ | |
| -DCMAKE_C_FLAGS="-fsanitize=thread -g" \ | |
| -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=thread" \ | |
| -DCMAKE_MODULE_LINKER_FLAGS="-fsanitize=thread" | |
| - name: Build | |
| run: | | |
| cd build | |
| make -j$(nproc) | |
| - name: Run tests with TSan | |
| working-directory: build | |
| run: | | |
| ctest --output-on-failure --verbose | |
| env: | |
| TSAN_OPTIONS: halt_on_error=0 | |
| # Static Analysis with clang-tidy | |
| static-analysis: | |
| name: Static Analysis | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install system dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y \ | |
| cmake \ | |
| clang-tidy \ | |
| build-essential \ | |
| git \ | |
| pkg-config \ | |
| libgoogle-perftools-dev | |
| - name: Run clang-tidy | |
| run: | | |
| clang-tidy \ | |
| --warnings-as-errors='' \ | |
| src/*.cpp \ | |
| include/*.h \ | |
| -- \ | |
| -I./include \ | |
| -std=c++20 \ | |
| 2>&1 | tee clang-tidy-output.txt || true | |
| - name: Upload clang-tidy results | |
| if: always() | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: clang-tidy-results | |
| path: clang-tidy-output.txt | |
| # Build with all warnings as errors | |
| warnings-check: | |
| name: Warnings Check | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install system dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y \ | |
| cmake \ | |
| build-essential \ | |
| git \ | |
| pkg-config \ | |
| libgoogle-perftools-dev | |
| - name: Cache vcpkg | |
| id: cache-vcpkg | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.vcpkg/archives | |
| ~/.vcpkg/git | |
| key: ${{ runner.os }}-vcpkg-warnings-${{ hashFiles('vcpkg.json') }} | |
| - name: Install vcpkg | |
| run: | | |
| # Remove existing empty vcpkg directory if it exists | |
| if [ -d "vcpkg" ] && [ -z "$(ls -A vcpkg)" ]; then | |
| rm -rf vcpkg | |
| fi | |
| # Clone vcpkg if it doesn't exist | |
| if [ ! -d "vcpkg" ]; then | |
| git clone https://github.com/Microsoft/vcpkg.git | |
| fi | |
| # Verify clone was successful | |
| if [ ! -f "vcpkg/bootstrap-vcpkg.sh" ]; then | |
| echo "ERROR: bootstrap-vcpkg.sh not found in vcpkg directory" | |
| echo "vcpkg directory contents:" | |
| ls -la vcpkg/ | |
| exit 1 | |
| fi | |
| cd vcpkg | |
| if [ ! -f "vcpkg" ]; then | |
| ./bootstrap-vcpkg.sh | |
| fi | |
| - name: Install vcpkg dependencies | |
| run: | | |
| cd vcpkg | |
| ./vcpkg install --triplet=x64-linux-release | |
| - name: Configure with all warnings as errors | |
| run: | | |
| mkdir build | |
| cd build | |
| cmake .. \ | |
| -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} \ | |
| -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake \ | |
| -DVCPKG_TARGET_TRIPLET=x64-linux-release \ | |
| -DCMAKE_CXX_FLAGS="-Wall -Wextra -Werror" \ | |
| -DCMAKE_C_FLAGS="-Wall -Wextra -Werror" | |
| - name: Build | |
| run: | | |
| cd build | |
| make -j$(nproc) |