name: Build for Linux

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

jobs:
  build_matrix:
    strategy:
      matrix:
        compiler: [ "gcc", "clang" ]
    runs-on: ubuntu-latest
    container:
      image: debian:trixie

    steps:
    - name: Install package dependencies.
      run: |
        apt-get update
        apt-get install -y \
          bison \
          clang \
          cmake \
          doxygen \
          flex \
          git \
          iwyu \
          libcairo2-dev \
          libncurses-dev
    
    - name: Checkout code.
      uses: actions/checkout@v3

    - name: Configure libbase through CMake.
      run: |
        export CC="${{ matrix.compiler }}"
        cmake -B ${{github.workspace}}/build -Dconfig_WERROR=ON -DIWYU_MODE=FAIL

    - name: Build libbase.
      run: |
        export CC="${{ matrix.compiler }}"
        cmake --build ${{github.workspace}}/build

    - name: Build documentation.
      run: |
        cmake --build ${{github.workspace}}/build --target doc

    - name: Run tests.
      run: |
        ctest --test-dir ${{github.workspace}}/build --build-run-dir ${{github.workspace}}/build -V

