🔨 Another CMake github actions attempt #21
This file contains 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: Build and Test | |
on: | |
push: | |
branches: ["main"] | |
pull_request: | |
branches: ["main"] | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-latest, windows-latest] | |
build_type: [Release, RelWithDebInfo] | |
include: | |
- os: windows-latest | |
cpp_compiler: cl | |
separator: '\\' | |
- os: ubuntu-latest | |
cpp_compiler: g++ | |
separator: "/" | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.x" | |
- name: Install System Dependencies (Ubuntu) | |
if: runner.os == 'Linux' | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y libegl1-mesa-dev libgl1-mesa-dev ninja-build | |
- name: Setup Developer Command Prompt (Windows) | |
if: runner.os == 'Windows' | |
uses: ilammy/msvc-dev-cmd@v1 | |
- name: Install Ninja (Windows) | |
if: runner.os == 'Windows' | |
shell: pwsh | |
run: | | |
$NinjaPath = "C:\Program Files\Ninja" | |
New-Item -ItemType Directory -Path $NinjaPath -Force | |
Invoke-WebRequest "https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-win.zip" -OutFile "ninja.zip" | |
Expand-Archive "ninja.zip" -DestinationPath $NinjaPath | |
Add-Content $env:GITHUB_PATH "$NinjaPath" | |
- name: Install Dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install conan cmake | |
- name: Setup Conan | |
shell: bash | |
run: | | |
conan profile detect --force | |
echo "[conf]" >> ~/.conan2/profiles/default | |
echo "tools.system.package_manager:mode=install" >> ~/.conan2/profiles/default | |
echo "tools.system.package_manager:sudo=True" >> ~/.conan2/profiles/default | |
echo "tools.build:cxxflags=-std=c++20" >> ~/.conan2/profiles/default | |
- name: Cache Conan packages | |
uses: actions/cache@v3 | |
with: | |
path: ~/.conan2 | |
key: ${{ runner.os }}-conan-${{ hashFiles('**/conanfile.txt') }} | |
restore-keys: | | |
${{ runner.os }}-conan- | |
- name: Install Conan Dependencies | |
run: | | |
conan install . --build=missing -s build_type=${{ matrix.build_type }} | |
- name: Set Build Directory | |
id: strings | |
shell: bash | |
run: | | |
if [ "${{ runner.os }}" == "Windows" ]; then | |
echo "build-output-dir=${{ github.workspace }}\\build\\${{ matrix.build_type }}" >> "$GITHUB_OUTPUT" | |
echo "game-path=src\\game\\stabby.exe" >> "$GITHUB_OUTPUT" | |
echo "preset=conan-default" >> "$GITHUB_OUTPUT" | |
else | |
echo "build-output-dir=${{ github.workspace }}/build/${{ matrix.build_type }}" >> "$GITHUB_OUTPUT" | |
echo "game-path=src/game/stabby" >> "$GITHUB_OUTPUT" | |
echo "preset=conan-release" >> "$GITHUB_OUTPUT" | |
fi | |
- name: Configure CMake | |
shell: bash | |
run: | | |
if [ "${{ runner.os }}" == "Windows" ]; then | |
build_dir="${{ github.workspace }}\\build\\${{ matrix.build_type }}" | |
else | |
build_dir="${{ github.workspace }}/build/${{ matrix.build_type }}" | |
fi | |
cmake --preset ${{ steps.strings.outputs.preset }} \ | |
-S . \ | |
-B "$build_dir" \ | |
-G Ninja \ | |
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} | |
- name: Build | |
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} | |
- name: Test | |
working-directory: ${{ steps.strings.outputs.build-output-dir }} | |
run: ctest --build-config ${{ matrix.build_type }} | |
- name: Upload Build Artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ runner.os }}-${{ matrix.build_type }}-build | |
path: ${{ steps.strings.outputs.build-output-dir }}/${{ steps.strings.outputs.game-path }} | |
if-no-files-found: ignore |