Skip to content

Major CI overhaul: Exclude invalid Linux matrix, manually manage vcpk… #5

Major CI overhaul: Exclude invalid Linux matrix, manually manage vcpk…

Major CI overhaul: Exclude invalid Linux matrix, manually manage vcpk… #5

Workflow file for this run

name: C++ CI
on:
push:
branches: [ main, master, develop ]
pull_request:
branches: [ main, master, develop ]
jobs:
build_and_test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
compiler: [gcc, clang, msvc]
include:
- os: windows-latest
compiler: msvc
cmake_generator: Visual Studio 17 2022
exclude:
- os: windows-latest
compiler: gcc
- os: windows-latest
compiler: clang
- os: ubuntu-latest # Explicitly exclude msvc for ubuntu
compiler: msvc
runs-on: ${{ matrix.os }}
steps:
- name: Checkout project code
uses: actions/checkout@v4
with:
submodules: 'recursive'
path: main_project # Checkout main project to a sub-path
- name: Set up compiler (Linux)
if: runner.os == 'Linux'
working-directory: main_project # Ensure commands run in project directory
run: |
echo "DEBUG: Setting up Linux compiler: ${{ matrix.compiler }}"
if [ "${{ matrix.compiler }}" == "gcc" ]; then
sudo apt-get update
sudo apt-get install -y gcc g++ ninja-build cmake
echo "CC_FOR_CMAKE=gcc" >> $GITHUB_ENV
echo "CXX_FOR_CMAKE=g++" >> $GITHUB_ENV
elif [ "${{ matrix.compiler }}" == "clang" ]; then
sudo apt-get update
sudo apt-get install -y clang ninja-build cmake
echo "CC_FOR_CMAKE=clang" >> $GITHUB_ENV
echo "CXX_FOR_CMAKE=clang++" >> $GITHUB_ENV
# No else needed due to matrix exclude
fi
- name: Set up MSVC (Windows)
if: runner.os == 'Windows' && matrix.compiler == 'msvc'
uses: microsoft/setup-msbuild@v1.3
- name: DEBUG - After MSVC Setup
if: runner.os == 'Windows' && matrix.compiler == 'msvc'
run: |
echo "DEBUG: MSVC setup step completed."
# Windows vcpkg setup using manual checkout and bootstrap
- name: Checkout vcpkg (Windows)
if: runner.os == 'Windows' && matrix.compiler == 'msvc'
uses: actions/checkout@v4
with:
repository: 'microsoft/vcpkg'
ref: '2023.10.19' # Pin to a specific stable tag or commit
path: vcpkg
- name: Bootstrap vcpkg (Windows)
if: runner.os == 'Windows' && matrix.compiler == 'msvc'
working-directory: vcpkg
run: .\bootstrap-vcpkg.bat -disableMetrics
shell: cmd # bootstrap-vcpkg.bat is a cmd script
- name: Install dependencies with vcpkg (Windows)
if: runner.os == 'Windows' && matrix.compiler == 'msvc'
working-directory: main_project # vcpkg.json is in the main project directory
run: ../vcpkg/vcpkg install --triplet x64-windows-static
shell: cmd
- name: DEBUG - After vcpkg Setup (Windows)
if: runner.os == 'Windows' && matrix.compiler == 'msvc'
run: |
echo "DEBUG: vcpkg setup and install step completed."
echo "DEBUG: VCPKG_ROOT should be path to vcpkg directory, which is ${{ github.workspace }}\vcpkg"
- name: Configure CMake (Windows)
if: runner.os == 'Windows' && matrix.compiler == 'msvc'
working-directory: main_project
run: |
echo "DEBUG: Starting CMake configuration for Windows (MSVC)."
set VCPKG_INSTALLATION_ROOT=%GITHUB_WORKSPACE%\vcpkg\installed
echo "DEBUG: VCPKG_INSTALLATION_ROOT is %VCPKG_INSTALLATION_ROOT%"
echo "DEBUG: Using CMAKE_TOOLCHAIN_FILE: %GITHUB_WORKSPACE%\vcpkg\scripts\buildsystems\vcpkg.cmake"
cmake -B build -S . -G "%{{ matrix.cmake_generator }}%" -DMINIOAUTH2_BUILD_EXAMPLES=ON -DMINIOAUTH2_BUILD_TESTS=ON -DMINIOAUTH2_USE_NLOHMANN_JSON=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE="%GITHUB_WORKSPACE%\vcpkg\scripts\buildsystems\vcpkg.cmake"
echo "DEBUG: CMake configuration for Windows (MSVC) finished."
shell: cmd
- name: Configure CMake (Linux)
if: runner.os == 'Linux' # Condition already refined by matrix exclude
working-directory: main_project
env:
CC: ${{ env.CC_FOR_CMAKE }}
CXX: ${{ env.CXX_FOR_CMAKE }}
run: |
echo "DEBUG: Starting CMake configuration for Linux (${{ matrix.compiler }})."
echo "DEBUG: CC is $CC, CXX is $CXX"
if [ -z "$CC" ] || [ -z "$CXX" ]; then
echo "::error:: CC or CXX environment variables are not set for Linux CMake configuration."
exit 1
fi
cmake -B build -S . -G Ninja -DMINIOAUTH2_BUILD_EXAMPLES=ON -DMINIOAUTH2_BUILD_TESTS=ON -DMINIOAUTH2_USE_NLOHMANN_JSON=ON -DCMAKE_BUILD_TYPE=Debug -D CMAKE_C_COMPILER=$CC -D CMAKE_CXX_COMPILER=$CXX
echo "DEBUG: CMake configuration for Linux (${{ matrix.compiler }}) finished."
- name: Build
working-directory: main_project # All build commands should be in the project context
run: cmake --build build --config Debug
- name: Run tests
if: runner.os != 'Windows'
working-directory: main_project/build # Tests run from the build directory
run: ctest -C Debug --output-on-failure
# TODO: Add steps for:
# - Static analysis (clang-tidy)
# run: |
# sudo apt-get install clang-tidy
# cmake -B build-tidy -S . -DCMAKE_CXX_CLANG_TIDY="clang-tidy;-checks=*;"
# cmake --build build-tidy
# - Sanitizer builds (ASan, UBSan)
# run: |
# cmake -B build-asan -S . -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-fsanitize=address -g"
# cmake --build build-asan
# # Run tests under ASan
# - Check for Boost usage (and fail if found)
# run: |
# grep -r -E 'boost::|BOOST_' include/ examples/ test/
# if [ $? == 0 ]; then exit 1; fi