Reusable C tests workflow #1
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Reusable C unit tests | ||
|
Check failure on line 1 in .github/workflows/c-tests.yml
|
||
| 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' | ||