diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b672eef..2f88358 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,63 +2,86 @@ name: C++ CI on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] + branches: [main] + +env: + VCPKG_ROOT: ${{ github.workspace }}/vcpkg + CMAKE_BUILD_TYPE: Release + BUILD_DIR: build + VCPKG_TRIPLET: x64-linux jobs: build-and-test: + name: Build and Test runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + # 1. Checkout the repository + - name: Checkout Repository + uses: actions/checkout@v3 - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get install -y cmake g++ make + # 2. Install latest CMake and Ninja + - name: Install CMake and Ninja + uses: lukka/get-cmake@latest - - name: Build - run: | - mkdir build && cd build - cmake .. - make + # 3. Set up vcpkg using lukka/get-vcpkg action + - name: Setup vcpkg + uses: lukka/run-vcpkg@v11 - - name: Run tests - run: | - cd build - ctest --output-on-failure + # 7. Configure, Build, and Test using CMake Presets + - name: Configure, Build, and Test with CMake Presets + uses: lukka/run-cmake@v10 + with: + configurePreset: "ninja-multi-vcpkg" + buildPreset: "build-ninja-multi-vcpkg" + testPreset: "test-ninja-multi-vcpkg" + buildPresetAdditionalArgs: "['--parallel 6']" - lint: + format: + name: Code Formatting runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + # 1. Checkout the repository + - name: Checkout Repository + uses: actions/checkout@v3 - - name: Install clang-format - run: sudo apt-get install -y clang-format + # 2. Install clang-format + - name: Install clang-format + run: sudo apt-get update && sudo apt-get install -y clang-format - - name: Run clang-format - run: | - find src tests -name '*.cpp' -o -name '*.h' | xargs clang-format -i --style=file - git diff --exit-code + # 3. Run clang-format on source and header files + - name: Run clang-format + run: | + find src tests -type f \( -name '*.cpp' -o -name '*.h' \) -print0 | xargs -0 clang-format -i --style=file + # Check for formatting changes + git diff --exit-code - clang-tidy: + lint: + name: Lint Code runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get install -y cmake g++ make clang-tidy + # 1. Checkout the repository + - name: Checkout Repository + uses: actions/checkout@v3 + # Install latest CMake and Ninja. + - uses: lukka/get-cmake@latest + # 2. Set up vcpkg using lukka/get-vcpkg action + - name: Setup vcpkg + uses: lukka/run-vcpkg@v11 - - name: Generate compile_commands.json - run: | - mkdir build && cd build - cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. + - name: Configure, Build, and Test with CMake Presets + uses: lukka/run-cmake@v10 + with: + configurePreset: "ninja-multi-vcpkg" + # 5. Install clang-tidy + - name: Install clang-tidy + run: sudo apt-get update && sudo apt-get install -y clang-tidy - - name: Run clang-tidy - run: | - find src tests -name '*.cpp' -o -name '*.h' | xargs clang-tidy -p build \ No newline at end of file + # 7. Run clang-tidy on all source and header files + - name: Run clang-tidy + run: | + find src tests -type f \( -name '*.cpp' -o -name '*.h' \) -print0 | xargs -0 clang-tidy -p build diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..feb2940 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,115 @@ +{ + "version": 3, + "cmakeMinimumRequired": { + "major": 3, + "minor": 19, + "patch": 0 + }, + "configurePresets": [ + { + "name": "release", + "displayName": "Release Configuration", + "description": "Configure the project with Release build type, travel tracking disabled, and tests disabled.", + "generator": "Unix Makefiles", + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release", + "ENABLE_TRAVEL_TRACKING": "OFF", + "BUILD_TESTS": "OFF", + "CMAKE_TOOLCHAIN_FILE": "${env.VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" + } + }, + { + "name": "debug", + "displayName": "Debug Configuration", + "description": "Configure the project with Debug build type, travel tracking enabled, and tests enabled.", + "generator": "Unix Makefiles", + "binaryDir": "${sourceDir}/build-debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "ENABLE_TRAVEL_TRACKING": "ON", + "BUILD_TESTS": "ON", + "CMAKE_TOOLCHAIN_FILE": "${env.VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" + } + }, + { + "name": "ninja-release", + "displayName": "Ninja Release Configuration", + "description": "Configure the project with Release build type using Ninja generator.", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build-ninja", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release", + "ENABLE_TRAVEL_TRACKING": "OFF", + "BUILD_TESTS": "OFF", + "CMAKE_TOOLCHAIN_FILE": "${env.VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" + } + }, + { + "name": "ninja-debug", + "displayName": "Ninja Debug Configuration", + "description": "Configure the project with Debug build type using Ninja generator.", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build-ninja-debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "ENABLE_TRAVEL_TRACKING": "ON", + "BUILD_TESTS": "ON", + "CMAKE_TOOLCHAIN_FILE": "${env.VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" + } + } + ], + "buildPresets": [ + { + "name": "build-release", + "configurePreset": "release", + "description": "Build the project using the Release configuration.", + "jobs": 6 + }, + { + "name": "build-debug", + "configurePreset": "debug", + "description": "Build the project using the Debug configuration.", + "jobs": 6 + }, + { + "name": "build-ninja-release", + "configurePreset": "ninja-release", + "description": "Build the project using the Ninja Release configuration.", + "jobs": 6 + }, + { + "name": "build-ninja-debug", + "configurePreset": "ninja-debug", + "description": "Build the project using the Ninja Debug configuration.", + "jobs": 6 + } + ], + "testPresets": [ + { + "name": "test-release", + "configurePreset": "release", + "description": "Run tests for the Release configuration." + }, + { + "name": "test-debug", + "configurePreset": "debug", + "description": "Run tests for the Debug configuration." + }, + { + "name": "test-ninja-release", + "configurePreset": "ninja-release", + "description": "Run tests for the Ninja Release configuration." + }, + { + "name": "test-ninja-debug", + "configurePreset": "ninja-debug", + "description": "Run tests for the Ninja Debug configuration." + } + ], + "exportPresets": [] +}