Skip to content

Reusable C tests workflow #1

Reusable C tests workflow

Reusable C tests workflow #1

Workflow file for this run

name: Reusable C unit tests

Check failure on line 1 in .github/workflows/c-tests.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/c-tests.yml

Invalid workflow file

(Line: 39, Col: 28): A mapping was not expected, (Line: 43, Col: 28): A mapping was not expected, (Line: 47, Col: 28): A mapping was not expected, (Line: 51, Col: 28): A mapping was not expected, (Line: 59, Col: 22): A mapping was not expected, (Line: 64, Col: 28): A mapping was not expected, (Line: 70, Col: 28): A mapping was not expected
on:
workflow_call:
inputs:
additional-apt-packages:
description: 'Additional APT packages to install'
required: false
type: string
default: ''
library-directory:
description: 'Directory to find the C library'
required: true
type: string
jobs:
c-tests:
name: C unit tests
runs-on: ubuntu-24.04
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.13.0
with:
access_token: ${{ github.token }}
- name: Checkout
uses: actions/checkout@v6.0.2
with:
submodules: true
- name: Install dev tools
run: |
sudo apt-get update
sudo apt-get install -y libcunit1-dev libconfig-dev \
ninja-build valgrind clang meson gcovr ${{ inputs.additional-apt-packages }}
- name: Configure code
working-directory: {{ inputs.library-directory }}
run: meson setup build-cov -Db_coverage=true
- name: Compile
working-directory: {{ inputs.library-directory }}
run: ninja -C build-cov
- name: Run tests
working-directory: {{ inputs.library-directory }}
run: ninja -C build-cov test
- name: Build coverage report
working-directory: {{ inputs.library-directory }}
run: ninja -C build-cov coverage-xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5.4.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: C
directory: {{ inputs.library-directory }}
gcov_args: --preserve-paths
fail_ci_if_error: true
- name: Compile and test with clang
working-directory: {{ inputs.library-directory }}
run: |
CC=clang meson setup build-clang
meson test -C build-clang
- name: Run tests with valgrind
working-directory: {{ inputs.library-directory }}
run: |
meson setup build-valgrind
meson test -C build-valgrind -t-1 \
--wrapper='valgrind --leak-check=full --error-exitcode=1'