Skip to content

Commit

Permalink
fix: Make ci match conan specified toolchain correctly (#8)
Browse files Browse the repository at this point in the history
- Force setup-cpp to install the same llvm version according to `llvm-<version>` when `compiler: llvm-<version>` and `clang-tidy: <version>` differs.
- Match conan profile name with a regex pattern.
  • Loading branch information
FeignClaims authored May 16, 2024
1 parent e2672fa commit e762099
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 108 deletions.
67 changes: 67 additions & 0 deletions .github/actions/parse_environment/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: "parse_environment"
description: "Parse environment"
inputs:
os:
required: true
description: "Operating system"
compiler:
required: true
description: "Compiler"
outputs:
os_name:
description: "Operating system name (ubuntu converted to linux)"
value: ${{ steps.os.outputs.name }}
os_version:
description: "Operating system version (if not set in inputs.os, set to latest)"
value: ${{ steps.os.outputs.version }}
arch:
description: "Architecture"
value: ${{ steps.arch.outputs.value }}
compiler_name:
description: "Compiler name (llvm converted to clang)"
value: ${{ steps.compiler.outputs.name }}
compiler_version:
description: "Compiler version (if not set in inputs.compiler, set to latest)"
value: ${{ steps.compiler.outputs.version }}
gcov_executable:
description: "The corresponding gcov_executable (Available only for clang and gcc)"
value: ${{ steps.gcov.outputs.value }}

runs:
using: "composite"
steps:
- name: Parse os and os version
id: os
shell: bash
env:
VALUE: ${{ contains(matrix.os, '-') && matrix.os || format('{0}-{1}', matrix.os, 'latest') }}
run: |
export NAME=${VALUE%%-*}
echo name=${NAME/ubuntu/linux} >> "$GITHUB_OUTPUT"
export VERSION=${VALUE##*-}
echo version=$VERSION >> "$GITHUB_OUTPUT"
- name: Parse architecture
id: arch
shell: bash
run: |
echo value=${{ steps.os.outputs.name == 'macos' && steps.os.outputs.version >= '14' && 'armv8' || 'x86_64' }} >> "$GITHUB_OUTPUT"
- name: Parse compiler and compiler version
id: compiler
shell: bash
env:
VALUE: ${{ contains(matrix.compiler, '-') && matrix.compiler || format('{0}-{1}', matrix.compiler, 'latest') }}
run: |
export NAME=${VALUE%%-*}
echo name=${NAME/llvm/clang} >> "$GITHUB_OUTPUT"
export VERSION=${VALUE##*-}
echo version=$VERSION >> "$GITHUB_OUTPUT"
- name: Parse gcov
id: gcov
shell: bash
run: |
echo "value=${{ contains(matrix.compiler, 'llvm') && 'llvm-cov gcov' || contains(matrix.compiler, 'gcc') && format('{0}-{1}', 'gcov', steps.compiler.outputs.version) || '' }}" >> "$GITHUB_OUTPUT"
20 changes: 8 additions & 12 deletions .github/actions/setup_cache/action.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
name: "setup_cache"
description: "sets up the shared cache"
inputs:
compiler:
key:
required: true
description: "Compiler"
build_type:
required: true
description: "Build type"
developer_mode:
required: true
description: "Developer mode"
description: "Cache key"
restore_key:
description: "Restore key when cache misses"

runs:
using: "composite"
Expand All @@ -20,14 +16,14 @@ runs:
path: |
~/.cache/pip
~/.ccache
key: ${{ runner.os }}-${{ inputs.compiler }}-${{ inputs.build_type }}-${{ inputs.developer_mode }}-${{ hashFiles('**/CMakeLists.txt') }}
key: ${{ inputs.key }}-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: |
${{ runner.os }}-${{ inputs.compiler }}-${{ inputs.build_type }}
${{ inputs.restore_key != '' && inputs.restore_key || inputs.key }}
- name: Cache conan
uses: actions/[email protected]
with:
path: ~/.conan2/p
key: ${{ runner.os }}-${{ inputs.compiler }}-${{ inputs.build_type }}-${{ inputs.developer_mode }}-${{ hashFiles('conanfile.py', 'conanfile.txt') }}
key: ${{ inputs.key }}-${{ hashFiles('conanfile.py', 'conanfile.txt') }}
restore-keys: |
${{ runner.os }}-${{ inputs.compiler }}-${{ inputs.build_type }}
${{ inputs.restore_key != '' && inputs.restore_key || inputs.key }}
56 changes: 13 additions & 43 deletions .github/actions/setup_conan/action.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
name: "setup_conan"
description: "sets up conan"
inputs:
os:
os_name:
required: true
description: "Operating system name"
os_version:
required: true
description: "Operating system"
description: "Operating system version"
arch:
required: true
description: "Architecutre"
compiler:
description: "Architecture"
compiler_name:
required: true
description: "Compiler"
description: "Compiler name"
compiler_version:
required: true
description: "Compiler version"
build_type:
required: true
description: "Build type"
Expand All @@ -32,18 +38,6 @@ outputs:
args:
description: "The corresponding args that should be used in conan commands afterwards"
value: ${{ steps.output.outputs.args }}
os_name:
description: "Operating system name (ubuntu converted to linux)"
value: ${{ steps.parse_os.outputs.name }}
os_version:
description: "Operating system version (if not set in inputs.os, set to latest)"
value: ${{ steps.parse_os.outputs.version }}
compiler_name:
description: "Compiler name (llvm converted to clang)"
value: ${{ steps.parse_compiler.outputs.name }}
compiler_version:
description: "Compiler version (if not set in inputs.compiler, set to latest)"
value: ${{ steps.parse_compiler.outputs.version }}

runs:
using: "composite"
Expand All @@ -58,44 +52,20 @@ runs:
run: |
conan profile detect
- name: Parse os and os version
id: parse_os
shell: bash
env:
VALUE: ${{ contains(matrix.os, '-') && matrix.os || format('{0}-{1}', matrix.os, 'latest') }}
run: |
export NAME=${VALUE%%-*}
echo name=${NAME/ubuntu/linux} >> "$GITHUB_OUTPUT"
export VERSION=${VALUE##*-}
echo version=$VERSION >> "$GITHUB_OUTPUT"
- name: Parse compiler and compiler version
id: parse_compiler
shell: bash
env:
VALUE: ${{ contains(matrix.compiler, '-') && matrix.compiler || format('{0}-{1}', matrix.compiler, 'latest') }}
run: |
export NAME=${VALUE%%-*}
echo name=${NAME/llvm/clang} >> "$GITHUB_OUTPUT"
export VERSION=${VALUE##*-}
echo version=$VERSION >> "$GITHUB_OUTPUT"
- name: Output
id: output
shell: bash
run: |
echo "home=$(conan config home)" >> "$GITHUB_OUTPUT"
export HOST_PROFILE=$(python3 script/match_conan_profile.py "${{ steps.parse_os.outputs.name }}-${{ steps.parse_os.outputs.version }}-${{ inputs.arch }}-${{ steps.parse_compiler.outputs.name }}-${{ steps.parse_compiler.outputs.version }}-${{ inputs.build_type }}")
export HOST_PROFILE=$(python3 script/match_conan_profile.py "${{ inputs.os_name }}-${{ inputs.os_version }}-${{ inputs.arch }}-${{ inputs.compiler_name }}-${{ inputs.compiler_version }}-${{ inputs.build_type }}")
echo "host_profile=$HOST_PROFILE" >> "$GITHUB_OUTPUT"
export BUILD_PROFILE=default
echo "build_profile=$BUILD_PROFILE" >> "$GITHUB_OUTPUT"
export
echo "args=-pr:b '$BUILD_PROFILE' -pr:h '$HOST_PROFILE' -s:h 'build_type=${{ inputs.build_type }}' ${{ inputs.args }}" >> "$GITHUB_OUTPUT"
echo "args=-pr:b '$BUILD_PROFILE' -s:b 'build_type=Release' -pr:h '$HOST_PROFILE' -s:h 'build_type=${{ inputs.build_type }}' ${{ inputs.args }}" >> "$GITHUB_OUTPUT"
- name: Install conan config folder
shell: bash
Expand Down
66 changes: 34 additions & 32 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,52 +66,52 @@ jobs:
developer_mode: ON

include:
# Inject gcov_executable variable
- compiler: llvm
gcov_executable: "llvm-cov gcov"
- compiler: llvm-16.0.6
gcov_executable: "llvm-cov gcov"
- compiler: gcc-13
gcov_executable: gcov-13

# Enable package for release build
- build_type: Release
developer_mode: OFF
package_generator: ZIP

steps:
- name: Linux - Maximize build disk space
uses: easimon/maximize-build-space@v10
if: runner.os == 'Linux'
with:
root-reserve-mb: 30720
swap-size-mb: 1024
remove-android: "true"
remove-docker-images: "true"
remove-dotnet: "true"
# Use this if a fairly large library is requried, like building and using llvm as a library.
# - name: Linux - Maximize build disk space
# uses: easimon/maximize-build-space@v10
# if: runner.os == 'Linux'
# with:
# root-reserve-mb: 30720
# swap-size-mb: 1024
# remove-android: "true"
# remove-docker-images: "true"
# remove-dotnet: "true"

- uses: actions/checkout@v4

- name: Parse environment
id: parsed
uses: ./.github/actions/parse_environment
with:
os: ${{ matrix.os }}
compiler: ${{ matrix.compiler }}

- name: Setup cache
uses: ./.github/actions/setup_cache
with:
compiler: ${{ matrix.compiler }}
build_type: ${{ matrix.build_type }}
developer_mode: ${{ matrix.developer_mode }}
key: ${{ steps.parsed.outputs.os_name }}-${{ steps.parsed.outputs.os_version }}-${{ steps.parsed.outputs.compiler_name }}-${{ steps.parsed.outputs.compiler_version }}-${{ matrix.build_type }}-${{ matrix.developer_mode }}
restore_key: ${{ steps.parsed.outputs.os_name }}-${{ steps.parsed.outputs.os_version }}-${{ steps.parsed.outputs.compiler_name }}-${{ steps.parsed.outputs.compiler_version }}-${{ matrix.build_type }}

- name: Setup cpp
uses: aminya/[email protected]
with:
compiler: ${{ matrix.compiler }}
vcvarsall: ${{ contains(matrix.os, 'windows') }}
vcvarsall: ${{ runner.os == 'Windows' }}

cmake: true
ninja: true
ccache: true
python: true

# llvm and clang-tidy version should match according to https://github.com/aminya/setup-cpp/issues/249
clangtidy: ${{ startsWith(matrix.compiler, 'llvm-') && steps.parsed.outputs.compiler_version || 'true' }}
cppcheck: true
clangtidy: true

gcovr: 7.2 # The default version 5.2 stucks on macos gcc
opencppcoverage: true
Expand All @@ -120,44 +120,46 @@ jobs:
uses: ./.github/actions/setup_conan
id: conan
with:
os: ${{ matrix.os }}
arch: x86_64
compiler: ${{ matrix.compiler }}
os_name: ${{ steps.parsed.outputs.os_name }}
os_version: ${{ steps.parsed.outputs.os_version }}
arch: ${{ steps.parsed.outputs.arch }}
compiler_name: ${{ steps.parsed.outputs.compiler_name }}
compiler_version: ${{ steps.parsed.outputs.compiler_version }}
build_type: ${{ matrix.build_type }}

- name: Configure cmake
run: |
cmake --preset ${{ steps.conan.outputs.compiler_name }} ${{ steps.conan.outputs.compiler_name == 'msvc' && '-A x64 -T v143' || '' }} -D ENABLE_DEVELOPER_MODE:BOOL=${{ matrix.developer_mode }} -D OPT_ENABLE_COVERAGE:BOOL=${{ matrix.build_type == 'Debug' }}
cmake --preset ${{ steps.parsed.outputs.compiler_name }} ${{ steps.parsed.outputs.compiler_name == 'msvc' && '-A x64 -T v143' || '' }} -D ENABLE_DEVELOPER_MODE:BOOL=${{ matrix.developer_mode }} -D OPT_ENABLE_COVERAGE:BOOL=${{ matrix.build_type == 'Debug' }}
- name: Build and test
run: |
conan build . ${{ steps.conan.outputs.args }}
- name: Unix - Coverage
if: runner.os != 'Windows'
working-directory: build/${{ steps.conan.outputs.compiler_name }}
working-directory: build/${{ steps.parsed.outputs.compiler_name }}
run: |
ctest -C ${{ matrix.build_type }}
gcovr -j ${{ env.nproc }} --delete --root ../../ --print-summary --xml-pretty --xml coverage.xml . --gcov-executable '${{ matrix.gcov_executable }}'
gcovr -j ${{ env.nproc }} --delete --root ../../ --print-summary --xml-pretty --xml coverage.xml . --gcov-executable '${{ steps.parsed.outputs.gcov_executable }}'
- name: Windows - Coverage
if: runner.os == 'Windows'
working-directory: build/${{ steps.conan.outputs.compiler_name }}
working-directory: build/${{ steps.parsed.outputs.compiler_name }}
run: |
OpenCppCoverage.exe --export_type cobertura:coverage.xml --cover_children -- ctest -C ${{ matrix.build_type }}
- name: Publish to codecov
uses: codecov/[email protected]
with:
files: ./build/${{ steps.conan.outputs.compiler_name }}/coverage.xml
files: ./build/${{ steps.parsed.outputs.compiler_name }}/coverage.xml
flags: ${{ runner.os }}
name: ${{ runner.os }}-coverage
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true

- name: CPack
if: matrix.package_generator != ''
working-directory: build/${{ steps.conan.outputs.compiler_name }}
working-directory: build/${{ steps.parsed.outputs.compiler_name }}
run: |
cpack -C ${{ matrix.build_type }} -G ${{ matrix.package_generator }} -B _package -V
Expand All @@ -166,4 +168,4 @@ jobs:
if: ${{ startsWith(github.ref, 'refs/tags/') && matrix.package_generator != '' }}
with:
files: |
build/${{ steps.conan.outputs.compiler_name }}/_package/*.*
build/${{ steps.parsed.outputs.compiler_name }}/_package/*.*
Loading

0 comments on commit e762099

Please sign in to comment.