Skip to content

another attempt at a valid github workflow #30

another attempt at a valid github workflow

another attempt at a valid github workflow #30

# based on https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml
name: CMake build and test
on:
workflow_dispatch:
push:
branches: [ trunk ]
pull_request:
branches: [ trunk ]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
fail-fast: false
#
matrix:
os: [ubuntu-latest, windows-latest]
build_type: [Debug, Release]
c_compiler: [gcc, clang, cl]
include:
- os: windows-latest
c_compiler: cl
cxx_compiler: cl
- os: ubuntu-latest
c_compiler: gcc
cxx_compiler: g++
- os: ubuntu-latest
c_compiler: clang
cxx_compiler: clang++
exclude:
- os: windows-latest
c_compiler: gcc
- os: windows-latest
c_compiler: clang
- os: ubuntu-latest
c_compiler: cl
steps:
- uses: actions/checkout@v3
- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
if [ "$RUNNER_OS" = "Linux" ]; then
echo "vcpkg-setup-file=bootstrap-vcpkg.sh" >> "$GITHUB_OUTPUT"
echo "enable_coverage=ON" >> "$GITHUB_OUTPUT"
elif [ "$RUNNER_OS" = "Windows" ]; then
echo "vcpkg-setup-file=bootstrap-vcpkg.bat" >> "$GITHUB_OUTPUT"
echo "enable_coverage=OFF" >> "$GITHUB_OUTPUT"
fi
- name: Install lcov Linux
id: install-lcov
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt update
sudo apt install lcov
- name: Cache vcpkg
id: cache-vcpkg
uses: actions/cache@v3
with:
path: |
${{ github.workspace }}/vcpkg
${{ github.workspace }}/vcpkg_installed
key: ${{ matrix.os }}-${{ matrix.c_compiler }}-${{ matrix.build_type }}-vcpkg
- name: Configure vcpkg
if: steps.cache-vcpkg.outputs.cache-hit != 'true'
working-directory: ${{ github.workspace }}
run: |
git clone "https://github.com/Microsoft/vcpkg.git"
./vcpkg/${{ steps.strings.outputs.vcpkg-setup-file }} -disableMetrics
./vcpkg/vcpkg install
- name: Configure CMake
run: >
cmake --preset ci
-B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cxx_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DENABLE_COVERAGE=${{ steps.strings.outputs.enable_coverage }}
-S ${{ github.workspace }}
- name: Build
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} -j
- name: Test
if: matrix.os == 'windows-latest'
working-directory: ${{ steps.strings.outputs.build-output-dir }}/tests
run: ctest --build-config ${{ matrix.build_type }} --output-on-failure
- name: Test + Coverage
if: matrix.os != 'windows-latest'
working-directory: ${{ steps.strings.outputs.build-output-dir }}/tests
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} -t coverage