Skip to content

Verify C++ project template #65

Verify C++ project template

Verify C++ project template #65

Workflow file for this run

name: verify_cpp_template
run-name: Verify C++ project template
on:
workflow_dispatch:
inputs:
runner:
description: "Runner type to use"
required: true
default: github-hosted
type: choice
options:
- github-hosted
- self-hosted
push:
branches:
- "master"
- "main"
- "develop"
tags:
- "v*.*.*"
paths:
- src/**
- examples/**
- tests/**
- lib/**
- cmake/**
- CMakeLists.txt
- build_lib.sh
- generate_version.sh
- tailor_template_cleanup.sh
- .github/workflows/build_linux.yml
- .github/workflows/*.yml.tpl
pull_request:
branches:
- "master"
- "main"
- "develop"
- "dev*"
paths:
- src/**
- examples/**
- tests/**
- lib/**
- cmake/**
- CMakeLists.txt
- build_lib.sh
- generate_version.sh
- tailor_template_cleanup.sh
- .github/workflows/build_linux.yml
- .github/workflows/*.yml.tpl
jobs:
build:
runs-on: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.runner == 'self-hosted' && fromJSON('["self-hosted","Linux","X64"]') || 'ubuntu-latest' }}
env:
BUILD_DIR: build_ci
BUILD_TYPE: RelWithDebInfo
ENABLE_TBB: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.runner == 'self-hosted' && 'OFF' || 'ON' }}
CTEST_OUTPUT_ON_FAILURE: 1
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install dependencies
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.runner == 'github-hosted' }}
run: |
sudo apt update
sudo apt install -y cmake ninja-build g++ ccache libboost-all-dev libeigen3-dev libtbb-dev python3-dev python3-pytest python3-yaml doxygen graphviz
- name: Validate self-hosted prerequisites
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.runner == 'self-hosted' }}
run: |
command -v cmake
command -v ninja
command -v g++
command -v ccache
command -v python3
python3 -m pytest --version
python3 -c 'import yaml'
command -v doxygen
command -v dot
- name: Restore compiler cache
uses: actions/cache@v4
with:
path: ~/.ccache
key: ccache-${{ runner.os }}-${{ github.ref_name }}-${{ hashFiles('CMakeLists.txt', 'cmake/**', 'src/**', 'tests/**', 'tailor_template_cleanup.sh', '.github/workflows/*.yml.tpl') }}
restore-keys: |
ccache-${{ runner.os }}-${{ github.ref_name }}-
ccache-${{ runner.os }}-
- name: Configure
run: |
# Build artifacts are tested in a separate job, so keep CPU flags portable.
cmake -S . -B "${BUILD_DIR}" -GNinja \
-DCMAKE_BUILD_TYPE="${BUILD_TYPE}" \
-DENABLE_TESTS=ON \
-DENABLE_TBB="${ENABLE_TBB}" \
-DENABLE_CUDA=OFF \
-DENABLE_OPTIX=OFF \
-DENABLE_OPENGL=OFF \
-DCPU_ENABLE_NATIVE_TUNING=OFF \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
- name: Build
run: cmake --build "${BUILD_DIR}" --parallel 4
- name: Show ccache stats
run: ccache --show-stats || true
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: cmake-build-tree
path: ${{ env.BUILD_DIR }}
if-no-files-found: error
retention-days: 3
test:
needs: build
runs-on: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.runner == 'self-hosted' && fromJSON('["self-hosted","Linux","X64"]') || 'ubuntu-latest' }}
env:
BUILD_DIR: build_ci
CTEST_OUTPUT_ON_FAILURE: 1
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install test dependencies
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.runner == 'github-hosted' }}
run: |
sudo apt update
sudo apt install -y cmake ninja-build g++ libboost-all-dev libeigen3-dev libtbb-dev python3-dev python3-pytest python3-yaml doxygen graphviz
- name: Validate self-hosted prerequisites
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.runner == 'self-hosted' }}
run: |
command -v cmake
command -v ctest
command -v python3
python3 -m pytest --version
python3 -c 'import yaml'
command -v doxygen
command -v dot
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: cmake-build-tree
path: ${{ env.BUILD_DIR }}
- name: Resolve downloaded build tree
run: |
if [ -d "${BUILD_DIR}/CMakeFiles" ]; then
echo "CTEST_DIR=${BUILD_DIR}" >> "$GITHUB_ENV"
elif [ -d "${BUILD_DIR}/${BUILD_DIR}/CMakeFiles" ]; then
echo "CTEST_DIR=${BUILD_DIR}/${BUILD_DIR}" >> "$GITHUB_ENV"
else
echo "Could not find CMakeFiles under '${BUILD_DIR}' after artifact download."
find "${BUILD_DIR}" -maxdepth 3 -type d | sort || true
exit 1
fi
- name: Restore test executable permissions
run: |
# GitHub artifact download may drop executable bits from binaries.
find "${CTEST_DIR}" -type f -path "*/tests/*" -exec chmod +x {} + || true
- name: Test
run: ctest --test-dir "${CTEST_DIR}" --output-on-failure --parallel 2 --no-tests=error
tailored-project-validation:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install tailored-project dependencies
run: |
sudo apt update
sudo apt install -y cmake ninja-build g++ libboost-all-dev libeigen3-dev python3-dev python3-pytest python3-yaml doxygen graphviz
- name: Materialize and exercise project workflows
shell: bash
run: |
set -Eeuo pipefail
scratch_dir="$(mktemp -d "${RUNNER_TEMP}/tailored-project-validation.XXXXXX")"
target_dir="${scratch_dir}/target"
git clone --no-local "${GITHUB_WORKSPACE}" "${target_dir}"
git -C "${target_dir}" checkout --detach "${GITHUB_SHA}"
(
cd "${target_dir}"
./tailor_template_cleanup.sh --apply --yes --project-namespace tailored_project
test -z "$(find .github/workflows -maxdepth 1 -name '*.tpl' -print -quit)"
python3 -c 'import pathlib, yaml; [yaml.safe_load(path.read_text()) for path in pathlib.Path(".github/workflows").glob("*.yml")]'
./build_lib.sh -B build_tailored_ci
cmake --preset docs
cmake --build --preset docs
)