Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
295 changes: 170 additions & 125 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,134 +2,179 @@ name: Build and Test

on:
push:
branches: [ main ]
branches: [ master ]
pull_request:
branches: [ main ]
branches: [ master ]

jobs:
build:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
include:
- name: coverage-gcc-linux
os: ubuntu-latest
compiler: gcc
scanbuild: ""
cflags: "-g -O0 -Wall -Wextra -m64 -W -Wshadow -Wunused-variable -Wunused-parameter -Wunused-function -Wunused -Wno-system-headers -Wno-deprecated -Wwrite-strings -fprofile-arcs -ftest-coverage"
cxxflags: "-g -O0 -Wall -Wextra -m64 -W -Wshadow -Wunused-variable -Wunused-parameter -Wunused-function -Wunused -Wno-system-headers -Wno-deprecated -Woverloaded-virtual -Wwrite-strings -fprofile-arcs -ftest-coverage"
ldflags: "-fprofile-arcs -ftest-coverage -lgcov"
bldprefix: coverage
bname: system_gcc
with_coverage: "ON"
with_memcheck: "OFF"
shell_tests: "ON"

- name: valgrind-gcc-linux
os: ubuntu-latest
compiler: gcc
scanbuild: ""
cflags: "-g -O0 -Wall -Wextra -m64 -W -Wshadow -Wunused-variable -Wunused-parameter -Wunused-function -Wunused -Wno-system-headers -Wno-deprecated -Wwrite-strings"
cxxflags: "-g -O0 -Wall -Wextra -m64 -W -Wshadow -Wunused-variable -Wunused-parameter -Wunused-function -Wunused -Wno-system-headers -Wno-deprecated -Wwrite-strings"
ldflags: ""
bldprefix: valgrind
bname: system_gcc-valgrind
with_coverage: "OFF"
with_memcheck: "ON"
shell_tests: "OFF"

- name: use_prefix-gcc-linux
os: ubuntu-latest
compiler: gcc
scanbuild: ""
cflags: ""
cxxflags: ""
ldflags: ""
bldprefix: use_prefix
bname: system_gcc
with_coverage: "OFF"
with_memcheck: "OFF"
shell_tests: "OFF"

- name: sanitize-clang-linux
os: ubuntu-latest
compiler: clang
scanbuild: "scan-build -v --status-bugs"
cflags: "-Wall -Wextra -m64 -W -Wshadow -Wunused-variable -Wunused-parameter -Wunused-function -Wunused -Wno-system-headers -Wno-deprecated -Wwrite-strings -fsanitize=address,undefined"
cxxflags: "-g -Wall -Wextra -m64 -fsanitize=address,undefined"
ldflags: ""
bldprefix: sanitize
bname: fsanitize_clang
with_coverage: "OFF"
with_memcheck: "OFF"
shell_tests: "ON"

- name: rel-clang-macos
os: macos-11
compiler: clang
scanbuild: ""
cflags: "-O3 -Wall -Wextra -Wshadow -Wunused-variable -Wunused-parameter -Wunused-function -Wunused -Wno-system-headers -Wno-deprecated -Wwrite-strings"
cxxflags: "-O3 -Wall -Wextra -Wshadow -Wunused-variable -Wunused-parameter -Wunused-function -Wunused -Wno-system-headers -Wno-deprecated -Wwrite-strings"
ldflags: ""
bldprefix: rel
bname: osx_clang
with_coverage: "OFF"
with_memcheck: "OFF"
shell_tests: "ON"

env:
PROJECT_NAME: NIFTI_CLIB
PARALLEL_LEVEL: 3
AGENT_BUILDDIRECTORY: ${{ github.workspace }}/NIFTIworkspace
BUILD_SOURCESDIRECTORY: ${{ github.workspace }}
SYSTEM_PULLREQUEST_SOURCEBRANCH: ${{ github.head_ref }}
BUILD_SOURCEBRANCHNAME: ${{ github.head_ref }}
BUILD_BUILDID: ${{ github.run_id }}
SYSTEM_PULLREQUEST_PULLREQUESTNUMBER: ${{ github.event.pull_request.number }}
CTEST_SCRIPT_DIRECTORY: ${{ github.workspace }}/cmake
coverage:
name: coverage-gcc-linux
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
cmake ninja-build lcov zlib1g-dev libexpat1-dev

- name: Build
run: |
cmake -S . -B build -G Ninja \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_C_FLAGS="-g -O0 --coverage" \
-DCMAKE_EXE_LINKER_FLAGS="--coverage" \
-DCMAKE_SHARED_LINKER_FLAGS="--coverage" \
-DBUILD_SHARED_LIBS=ON -DUSE_CIFTI_CODE=ON -DUSE_FSL_CODE=ON
cmake --build build -j "$(nproc)"

- name: Test
run: ctest --test-dir build --output-on-failure -j 4

- name: Coverage summary
run: |
lcov --capture --directory build --output-file coverage.info \
--ignore-errors mismatch,gcov,source 2>/dev/null || true
lcov --list coverage.info 2>/dev/null | tail -20 || echo "(no coverage data)"

valgrind:
name: valgrind-gcc-linux
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

# libc6-dbg is not optional: without the C library's debug symbols
# valgrind refuses to start, reporting that it cannot redirect memcmp.
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
cmake ninja-build valgrind libc6-dbg zlib1g-dev libexpat1-dev

- name: Build
run: |
cmake -S . -B build -G Ninja \
-DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS="-g -O0" \
-DBUILD_SHARED_LIBS=ON -DUSE_CIFTI_CODE=ON -DUSE_FSL_CODE=ON
cmake --build build -j "$(nproc)"

# --trace-children=yes matters: most of the tests are shell scripts
# that exec nifti_tool, and without it valgrind inspects the shell and
# reports a clean run having never looked at the library.
# install_linking is excluded because it builds a whole CMake project,
# and tracing cmake, make and cc1 through valgrind takes far longer
# than it is worth.
- name: Memcheck
run: |
ctest --test-dir build -T memcheck -j 4 -E install_linking \
--overwrite MemoryCheckCommandOptions="--trace-children=yes --leak-check=full --show-leak-kinds=definite,indirect --error-exitcode=42"

# ctest -T memcheck exits 0 even when valgrind reports defects, so
# check the logs rather than trusting the exit status.
# Two things make this fiddlier than it looks. With --trace-children
# each log holds one ERROR SUMMARY per process, so a per-file "does it
# contain a clean summary" test is not enough. And because those
# processes run concurrently and share one log, their lines interleave:
# a real run produced "==3336== ERROR SUMMARY: ==3300==", one process
# cut off mid-line by another. So match the count itself rather than
# the absence of the clean string, which a spliced line also satisfies.
- name: Fail on any valgrind defect
run: |
logs=$(ls build/Testing/Temporary/MemoryChecker.*.log)
bad=$(grep -HE "ERROR SUMMARY: [1-9][0-9]* errors" $logs || true)
leaks=$(grep -HE "(definitely|indirectly) lost: [1-9]" $logs || true)
if [ -n "$bad" ] || [ -n "$leaks" ]; then
echo "::error::valgrind reported defects"
printf '%s\n' "$bad" "$leaks"
for f in $(printf '%s\n' "$bad" "$leaks" | cut -d: -f1 | sort -u); do
[ -n "$f" ] || continue
echo "===== $f"; cat "$f"
done
exit 1
fi
echo "valgrind clean across $(printf '%s\n' $logs | wc -l) tests"

- name: Upload memcheck logs
if: always()
uses: actions/upload-artifact@v4
with:
name: memcheck-logs
path: build/Testing/Temporary/MemoryChecker.*.log
if-no-files-found: ignore

use_prefix:
name: use_prefix-gcc-linux
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
cmake ninja-build zlib1g-dev libexpat1-dev

# Exercises the NIFTI_PACKAGE_PREFIX path used when this library is
# vendored into a larger project that already links a system nifti.
- name: Build and test with a package prefix
run: |
cmake -S . -B build -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DNIFTI_PACKAGE_PREFIX=vendored_ \
-DBUILD_SHARED_LIBS=ON -DUSE_CIFTI_CODE=ON -DUSE_FSL_CODE=ON
cmake --build build -j "$(nproc)"
ctest --test-dir build --output-on-failure -j 4

sanitize:
name: sanitize-clang-linux
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install Dependencies (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y cmake valgrind help2man

- name: Install Dependencies (macOS)
if: runner.os == 'macOS'
run: |
brew install cmake sed help2man

- name: Set Compiler and Flags
run: |
echo "CC=${{ matrix.compiler }}" >> $GITHUB_ENV
echo "CXX=${{ matrix.compiler }}" >> $GITHUB_ENV
echo "CFLAGS=${{ matrix.cflags }}" >> $GITHUB_ENV
echo "CXXFLAGS=${{ matrix.cxxflags }}" >> $GITHUB_ENV
echo "LDFLAGS=${{ matrix.ldflags }}" >> $GITHUB_ENV
echo "BLDPREFIX=${{ matrix.bldprefix }}" >> $GITHUB_ENV
echo "INTERPROCEDURAL_OPTIMIZATION=${{ matrix.interprocedural_optimization || 'OFF' }}" >> $GITHUB_ENV
echo "B_NAME=${{ matrix.bname }}" >> $GITHUB_ENV
echo "WITH_COVERAGE=${{ matrix.with_coverage }}" >> $GITHUB_ENV
echo "WITH_MEMCHECK=${{ matrix.with_memcheck }}" >> $GITHUB_ENV
echo "NIFTI_SHELL_SCRIPT_TESTS=${{ matrix.shell_tests }}" >> $GITHUB_ENV
echo "SCANBUILD_EXE=${{ matrix.scanbuild }}" >> $GITHUB_ENV

- name: Show Environment Info
run: |
which $CXX && $CXX --version || true
which $CC && $CC --version || true
which scan-build || true
which gcov && gcov --version || true
which valgrind && valgrind --version || true
which cmake && cmake --version || true

- name: Run CTest
run: |
eval $SCANBUILD_EXE ctest -S ${CTEST_SCRIPT_DIRECTORY}/travis_dashboard.cmake -V -j 4
- uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
cmake ninja-build clang clang-tools zlib1g-dev libexpat1-dev

- name: Build and test with ASan and UBSan
env:
CC: clang
run: |
cmake -S . -B build -G Ninja \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_C_FLAGS="-g -fsanitize=address,undefined -fno-sanitize-recover=all -fno-omit-frame-pointer" \
-DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address,undefined" \
-DCMAKE_SHARED_LINKER_FLAGS="-fsanitize=address,undefined" \
-DBUILD_SHARED_LIBS=ON -DUSE_CIFTI_CODE=ON -DUSE_FSL_CODE=ON
cmake --build build -j "$(nproc)"
ctest --test-dir build --output-on-failure -j 4

# scan-build needs its own configure, since it wraps the compiler.
- name: clang static analyzer
env:
CC: clang
run: |
scan-build --status-bugs -o scan-results \
cmake -S . -B build-scan -G Ninja -DCMAKE_BUILD_TYPE=Debug \
-DUSE_CIFTI_CODE=ON -DUSE_FSL_CODE=ON
scan-build --status-bugs -o scan-results \
cmake --build build-scan -j "$(nproc)"

macos:
name: rel-clang-macos
runs-on: macos-14
steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: brew install ninja

- name: Build and test
run: |
cmake -S . -B build -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=ON -DUSE_CIFTI_CODE=ON -DUSE_FSL_CODE=ON
cmake --build build -j "$(sysctl -n hw.ncpu)"
ctest --test-dir build --output-on-failure -j 4
Loading
Loading