Skip to content

Commit

Permalink
update Github CI
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinvn committed Sep 25, 2024
1 parent 2c76ec3 commit 451db5c
Show file tree
Hide file tree
Showing 2 changed files with 176 additions and 38 deletions.
99 changes: 61 additions & 38 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
# 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
115 changes: 115 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -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": []
}

0 comments on commit 451db5c

Please sign in to comment.