ci: automatically maximize MIN_LOG_LEVEL if CI detected (#22248)

Detect if on CI by checking that the CI environment variable is set to "true".
This is a common pattern among CI providers, including github actions and
cirrus.
This commit is contained in:
dundargoc 2023-02-13 20:04:54 +01:00 committed by GitHub
parent 84cf6a0a7e
commit bb9c673d2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 3 deletions

View File

@ -1,7 +1,7 @@
env:
CIRRUS_CLONE_DEPTH: '2'
LANG: en_US.UTF-8
CMAKE_EXTRA_FLAGS: -DCI_BUILD=ON -DMIN_LOG_LEVEL=3
CMAKE_EXTRA_FLAGS: -DCI_BUILD=ON
freebsd_task:
name: FreeBSD

View File

@ -254,7 +254,7 @@ jobs:
- name: Build
run: |
cmake -B build -G Ninja -D CI_BUILD=ON -D CMAKE_INSTALL_PREFIX:PATH=$INSTALL_PREFIX -D MIN_LOG_LEVEL=3 ${{ matrix.flags }}
cmake -B build -G Ninja -D CI_BUILD=ON -D CMAKE_INSTALL_PREFIX:PATH=$INSTALL_PREFIX ${{ matrix.flags }}
cmake --build build
- if: "!cancelled()"
@ -383,7 +383,7 @@ jobs:
run: make deps
- name: Build
run: make CMAKE_FLAGS="-D CI_BUILD=ON -D CMAKE_INSTALL_PREFIX:PATH=$INSTALL_PREFIX -D MIN_LOG_LEVEL=3"
run: make CMAKE_FLAGS="-D CI_BUILD=ON -D CMAKE_INSTALL_PREFIX:PATH=$INSTALL_PREFIX"
- name: Install
run: make install

View File

@ -412,6 +412,9 @@ else()
endif()
# Log level (MIN_LOG_LEVEL in log.h)
if($ENV{CI} MATCHES "true")
set(MIN_LOG_LEVEL 3)
endif()
if("${MIN_LOG_LEVEL}" MATCHES "^$")
# Minimize logging for release-type builds.
target_compile_definitions(main_lib INTERFACE MIN_LOG_LEVEL=$<IF:$<CONFIG:Debug>,1,3>)