Skip to content

Commit

Permalink
Add workflow to test compatibility with newer C++ standards
Browse files Browse the repository at this point in the history
  • Loading branch information
robomics committed Sep 24, 2024
1 parent 8da2f7d commit fc6bfa8
Showing 1 changed file with 206 additions and 0 deletions.
206 changes: 206 additions & 0 deletions .github/workflows/cppstd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
# Copyright (C) 2024 Roberto Rossini (roberros@uio.no)
# SPDX-License-Identifier: MIT

name: Test compatibility with newer C++ standards

on:
push:
branches: [main]
paths:
- ".github/workflows/cppstd.yml"
- "cmake/**"
- "examples/**"
- "src/**"
- "test/scripts/**"
- "test/units/**"
- "CMakeLists.txt"
- "conanfile.py"
tags:
- "v*.*.*"

pull_request:
paths:
- ".github/workflows/cppstd.yml"
- "cmake/**"
- "examples/**"
- "src/**"
- "test/scripts/**"
- "test/units/**"
- "CMakeLists.txt"
- "conanfile.py"

# https://stackoverflow.com/a/72408109
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

defaults:
run:
shell: bash

env:
CCACHE_DIR: "/opt/ccache-cache"
CCACHE_COMPILERCHECK: "content"
CCACHE_COMPRESSLEVEL: "13"
CCACHE_MAXSIZE: "200M"
CONAN_HOME: "/opt/conan/"
HICTK_CI: "1"

jobs:
build-deps:
runs-on: ubuntu-latest
name: Build dependencies
container:
image: ghcr.io/paulsengroup/ci-docker-images/ubuntu-24.04-cxx-clang-19
options: "--user=root"

outputs:
cache-key: ${{ steps.generate-cache-key.outputs.conan-key }}

steps:
- uses: actions/checkout@v4

- name: Fix permissions
run: |
chown -R $(id -u):$(id -g) $PWD
- name: Generate cache key
id: generate-cache-key
run: |
hash="${{ hashFiles('conanfile.py') }}"
echo "conan-key=packaging-$hash" >> $GITHUB_OUTPUT
- name: Restore Conan cache
id: cache-conan
uses: actions/cache/restore@v4
with:
key: ${{ steps.generate-cache-key.outputs.conan-key }}
path: ${{ env.CONAN_HOME }}

- name: Clean Conan cache (pre-build)
if: steps.cache-conan.outputs.cache-hit != 'true'
run: |
conan cache clean "*" --build
conan cache clean "*" --download
conan cache clean "*" --source
conan remove --confirm "*"
- name: Copy Conan settings
run: |
if [ ! -f "$CONAN_HOME/settings.yml" ]; then
cp "/root/.conan2/settings.yml" "$CONAN_HOME"
fi
- name: Install build dependencies (c++20)
run: |
conan install . \
--build=missing \
-pr:b="$CONAN_DEFAULT_PROFILE_PATH" \
-pr:h="$CONAN_DEFAULT_PROFILE_PATH" \
-s build_type=Debug \
-s compiler.libcxx=libstdc++11 \
-s compiler.cppstd=20
- name: Install build dependencies (c++23)
run: |
conan install . \
--build=missing \
-pr:b="$CONAN_DEFAULT_PROFILE_PATH" \
-pr:h="$CONAN_DEFAULT_PROFILE_PATH" \
-s build_type=Debug \
-s compiler.libcxx=libstdc++11 \
-s compiler.cppstd=23
- name: Clean Conan cache (post-build)
if: steps.cache-conan.outputs.cache-hit != 'true'
run: |
conan cache clean "*" --build
conan cache clean "*" --download
conan cache clean "*" --source
- name: Save Conan cache
uses: actions/cache/save@v4
if: steps.cache-conan.outputs.cache-hit != 'true'
with:
key: ${{ steps.generate-cache-key.outputs.conan-key }}
path: ${{ env.CONAN_HOME }}

build-project:
runs-on: ubuntu-latest
name: Build project
needs: [build-deps]
container:
image: ghcr.io/paulsengroup/ci-docker-images/ubuntu-24.04-cxx-clang-18
options: "--user=root"

strategy:
fail-fast: false
matrix:
cppstd:
- 20
- 23

steps:
- uses: actions/checkout@v4

- name: Fix permissions
run: |
chown -R $(id -u):$(id -g) $PWD
- name: Restore Conan cache
id: cache-conan
uses: actions/cache/restore@v4
with:
key: ${{ needs.build-deps.outputs.cache-key }}
path: ${{ env.CONAN_HOME }}
fail-on-cache-miss: true

- name: Install build dependencies
run: |
cppstd="${{ matrix.cppstd }}"
cppstd="${cppstd#c++}"
conan install . \
--build=missing \
-pr:b="$CONAN_DEFAULT_PROFILE_PATH" \
-pr:h="$CONAN_DEFAULT_PROFILE_PATH" \
-s build_type=Release \
-s compiler.libcxx=libstdc++11 \
-s compiler.cppstd="${{ matrix.cppstd }}" \
--output-folder=build
- name: Configure project
run: |
find src test \
-type f \
-name CMakeLists.txt \
-exec sed -i 's/set(CMAKE_CXX_STANDARD 17)/set(CMAKE_CXX_STANDARD ${{ matrix.cppstd }}/' {} +
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_PREFIX_PATH="$PWD/build" \
-DHICTK_ENABLE_TESTING=ON \
-DHICTK_ENABLE_FUZZY_TESTING=ON \
-DHICTK_BUILD_TOOLS=OFF \
-DHICTK_BUILD_EXAMPLES=ON \
-DHICTK_DOWNLOAD_TEST_DATASET=OFF \
-DHICTK_ENABLE_GIT_VERSION_TRACKING=OFF \
-S . \
-B build
- name: Build project
run: cmake --build build -j $(nproc)

cppstd-status-check:
name: Status Check (cppstd)
if: ${{ always() }}
runs-on: ubuntu-latest
needs:
- build-deps
- build-project

steps:
- name: Collect job results
if: |
needs.build-deps.result != 'success' ||
needs.build-project.result != 'success'
run: exit 1

0 comments on commit fc6bfa8

Please sign in to comment.