Skip to content

Instantly share code, notes, and snippets.

@prince-chrismc
Last active February 1, 2024 07:19
Show Gist options
  • Save prince-chrismc/224bbc3ba583012fd3b6ffef8976ab10 to your computer and use it in GitHub Desktop.
Save prince-chrismc/224bbc3ba583012fd3b6ffef8976ab10 to your computer and use it in GitHub Desktop.
GitHub Actions Workflow for C++ cross-platform with installing toolchains and many different runner's OS
name: C++ Test with Multiple Compilers
on: [pull_request]
jobs:
test:
runs-on: ubuntu-22.04
strategy:
matrix:
compiler: [g++-12, clang-15] # Specify compiler versions to test
cxxstd: [17, 23] # Specify the language standard to test
steps:
- uses: actions/checkout@v4 # Checkout code
- run: apt install ${{ matrix.compiler }}
- run: |
cmake --preset release \
-DCMAKE_CXX_COMPILER=${{ matrix.compiler }} \
-CMAKE_CXX_STANDARD=${{ matrix.cxxstd }}
cmake --build --preset release
cmake --test --preset release
name: C++ Test with Cross-Platform Compilers
on: [pull_request]
jobs:
test:
runs-on: ${{ matrix.os }} # Use dynamic runner based on OS
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
compiler: [gcc-11, clang-14]
include:
- os: windows-latest
compiler: gcc-11
# Add extra fields to `choco install mingw-w64-x86_64-gcc-11``
name: mingw-w64
version: 11.2.0
- os: windows-latest
# Override `clang-14` to use the MSVC provided clang
compiler: cl-clang
- os: macos-latest
compiler: gcc-11
# Add extra fields to `brew install` the correct version
package: gcc@11
fail-fast: false # Continue testing even if one job fails, they are likely agnostic of each other
steps:
- uses: actions/checkout@v4
# Setup C++ build toolchain
- name: Install dependencies (Windows)
if: runner.os == "Windows" && matrix.name
run: choco install ${{ matrix.name }} --version ${{ matrix.version }}
- name: Install dependencies (macOS)
if: runner.os == "macOS" ** matrix.package
run: brew install ${{ matrix.package }}
- name: Install dependencies (Linux)
if: runner.os == "Linux"
run: sudo apt-get install ${{ matrix.compiler }}
- name: Build and test
run: |
cmake --preset release \
-DCMAKE_CXX_COMPILER=${{ matrix.compiler }}
cmake --build --preset release
cmake --test --preset release
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment