Add comprehensive C++ SDK implementation guidelines #4
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: C++ SDK CI | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| paths: | |
| - 'cpp_sdk/**' | |
| - '.github/workflows/cpp_sdk.yml' | |
| pull_request: | |
| branches: [ main, develop ] | |
| paths: | |
| - 'cpp_sdk/**' | |
| - '.github/workflows/cpp_sdk.yml' | |
| jobs: | |
| test: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, macos-latest, windows-latest] | |
| build-type: [Debug, Release] | |
| compiler: [gcc, clang, msvc] | |
| exclude: | |
| - os: windows-latest | |
| compiler: gcc | |
| - os: macos-latest | |
| compiler: gcc | |
| - os: ubuntu-latest | |
| compiler: msvc | |
| - os: macos-latest | |
| compiler: msvc | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install dependencies (Ubuntu) | |
| if: matrix.os == 'ubuntu-latest' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y cmake ninja-build libsodium-dev valgrind | |
| if [ "${{ matrix.compiler }}" = "clang" ]; then | |
| sudo apt-get install -y clang-15 | |
| echo "CC=clang-15" >> $GITHUB_ENV | |
| echo "CXX=clang++-15" >> $GITHUB_ENV | |
| fi | |
| - name: Install dependencies (macOS) | |
| if: matrix.os == 'macos-latest' | |
| run: | | |
| brew install cmake ninja libsodium | |
| if [ "${{ matrix.compiler }}" = "clang" ]; then | |
| echo "CC=clang" >> $GITHUB_ENV | |
| echo "CXX=clang++" >> $GITHUB_ENV | |
| fi | |
| - name: Install dependencies (Windows) | |
| if: matrix.os == 'windows-latest' | |
| run: | | |
| choco install cmake ninja | |
| vcpkg install libsodium:x64-windows | |
| echo "CMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake" >> $env:GITHUB_ENV | |
| if ("${{ matrix.compiler }}" -eq "msvc") { | |
| echo "Using MSVC compiler" | |
| } else { | |
| echo "Using Clang compiler" | |
| } | |
| - name: Install Google Test | |
| run: | | |
| git clone https://github.com/google/googletest.git | |
| cd googletest | |
| mkdir build && cd build | |
| cmake .. -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} | |
| cmake --build . --config ${{ matrix.build-type }} | |
| sudo cmake --install . --config ${{ matrix.build-type }} | |
| if: matrix.os != 'windows-latest' | |
| - name: Install Google Test (Windows) | |
| if: matrix.os == 'windows-latest' | |
| run: | | |
| git clone https://github.com/google/googletest.git | |
| cd googletest | |
| mkdir build && cd build | |
| cmake .. -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DCMAKE_TOOLCHAIN_FILE=$env:CMAKE_TOOLCHAIN_FILE | |
| cmake --build . --config ${{ matrix.build-type }} | |
| cmake --install . --config ${{ matrix.build-type }} | |
| - name: Configure CMake | |
| run: | | |
| cd cpp_sdk | |
| mkdir build && cd build | |
| if [[ "${{ matrix.compiler }}" == "msvc" ]]; then | |
| cmake .. -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DENABLE_SANITIZERS=ON -DCMAKE_TOOLCHAIN_FILE=${{ env.CMAKE_TOOLCHAIN_FILE }} | |
| else | |
| cmake .. -GNinja -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DENABLE_SANITIZERS=ON | |
| fi | |
| shell: bash | |
| env: | |
| CI: true | |
| - name: Build | |
| run: | | |
| cd cpp_sdk/build | |
| if [[ "${{ matrix.compiler }}" == "msvc" ]]; then | |
| cmake --build . --config ${{ matrix.build-type }} | |
| else | |
| ninja | |
| fi | |
| shell: bash | |
| - name: Run tests | |
| run: | | |
| cd cpp_sdk/build | |
| ctest --verbose --output-on-failure | |
| - name: Run tests with Valgrind (Ubuntu Debug only) | |
| if: matrix.os == 'ubuntu-latest' && matrix.build-type == 'Debug' | |
| run: | | |
| cd cpp_sdk/build | |
| ninja test-valgrind | |
| - name: Generate coverage report (Debug builds only) | |
| if: matrix.build-type == 'Debug' | |
| run: | | |
| cd cpp_sdk/build | |
| ninja coverage | |
| - name: Upload coverage to Codecov | |
| if: matrix.build-type == 'Debug' && matrix.os == 'ubuntu-latest' | |
| uses: codecov/codecov-action@v3 | |
| with: | |
| file: ./cpp_sdk/build/coverage.info | |
| flags: cpp_sdk | |
| name: cpp-sdk-coverage | |
| fail_ci_if_error: true | |
| memory-safety: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y cmake ninja-build libsodium-dev valgrind clang-15 | |
| echo "CC=clang-15" >> $GITHUB_ENV | |
| echo "CXX=clang++-15" >> $GITHUB_ENV | |
| - name: Install Google Test | |
| run: | | |
| git clone https://github.com/google/googletest.git | |
| cd googletest | |
| mkdir build && cd build | |
| cmake .. -DCMAKE_BUILD_TYPE=Debug | |
| cmake --build . --config Debug | |
| sudo cmake --install . --config Debug | |
| - name: Configure with AddressSanitizer | |
| run: | | |
| cd cpp_sdk | |
| mkdir build-asan && cd build-asan | |
| cmake .. -GNinja -DCMAKE_BUILD_TYPE=Debug -DENABLE_SANITIZERS=ON | |
| - name: Build with AddressSanitizer | |
| run: | | |
| cd cpp_sdk/build-asan | |
| ninja | |
| - name: Test with AddressSanitizer | |
| run: | | |
| cd cpp_sdk/build-asan | |
| ninja test-sanitizers | |
| - name: Configure with Valgrind | |
| run: | | |
| cd cpp_sdk | |
| mkdir build-valgrind && cd build-valgrind | |
| cmake .. -GNinja -DCMAKE_BUILD_TYPE=Debug -DENABLE_VALGRIND=ON | |
| - name: Build with Valgrind | |
| run: | | |
| cd cpp_sdk/build-valgrind | |
| ninja | |
| - name: Test with Valgrind | |
| run: | | |
| cd cpp_sdk/build-valgrind | |
| ninja test-valgrind | |
| static-analysis: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y cmake ninja-build libsodium-dev clang-15 clang-tidy-15 | |
| echo "CC=clang-15" >> $GITHUB_ENV | |
| echo "CXX=clang++-15" >> $GITHUB_ENV | |
| - name: Install Google Test | |
| run: | | |
| git clone https://github.com/google/googletest.git | |
| cd googletest | |
| mkdir build && cd build | |
| cmake .. -DCMAKE_BUILD_TYPE=Release | |
| cmake --build . --config Release | |
| sudo cmake --install . --config Release | |
| - name: Configure | |
| run: | | |
| cd cpp_sdk | |
| mkdir build && cd build | |
| cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON | |
| - name: Run clang-tidy | |
| run: | | |
| cd cpp_sdk | |
| clang-tidy-15 src/*.cpp -p build/ --warnings-as-errors=* | |
| - name: Run clang-format check | |
| run: | | |
| cd cpp_sdk | |
| find . -name "*.cpp" -o -name "*.hpp" | xargs clang-format-15 --dry-run --Werror | |
| documentation: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y doxygen graphviz | |
| - name: Generate documentation | |
| run: | | |
| cd cpp_sdk | |
| mkdir build && cd build | |
| cmake .. -GNinja | |
| ninja docs | |
| - name: Upload documentation | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: cpp-sdk-docs | |
| path: cpp_sdk/build/docs/html/ |