!yamlscript/v0:

:use common: :all
:: workflow-setup()

jobs:
  #----------------------------------------------------------------------------
  canary:
    :: setup-job('clang' 'canary')
    name: canary/${{matrix.cxx}}/c++${{matrix.std}}/${{matrix.bt}}
    :: runs-on-docker-c4core('22.04')
    strategy:
      fail-fast: false
      matrix:
        item =: \({:std %1, :cxx %2, :bt %3, :bitlinks 'shared64 static32'})
        include:: &include1 -[
          item(20 'clang++-18' 'Debug'  )
          item(20 'clang++-18' 'Release') ]
    env:: load('share/env.yaml')
    steps:: checkout-action-docker + install-cxx + run-steps

  #----------------------------------------------------------------------------
  tabtokens:
    :: setup-job('clang' 'tabtokens')
    name: tabtokens/${{matrix.cxx}}/c++${{matrix.std}}/${{matrix.bt}}
    :: runs-on-docker-c4core('22.04')
    strategy:
      fail-fast: false
      matrix:
        include: *include1
    env:: load('share/env.yaml') +
          {'CMAKE_FLAGS' '-DRYML_WITH_TAB_TOKENS=ON'}
    steps:: checkout-action-docker + install-cxx + run-steps

  #----------------------------------------------------------------------------
  noexceptions:
    :: setup-job('clang' 'noexceptions')
    name: noexceptions/${{matrix.cxx}}/c++${{matrix.std}}/${{matrix.bt}}
    :: runs-on-docker-c4core('22.04')
    strategy:
      fail-fast: false
      matrix:
        include: *include1
    env:: -{'CXXFLAGS' '-fno-exceptions -fno-rtti'} +
          load('share/env.yaml')
    steps:: checkout-action-docker + install-cxx + run-steps

  #----------------------------------------------------------------------------
  extended:
    :: setup-job('clang' 'extended')
    name: extended/${{matrix.cxx}}/${{matrix.bits}}bit/c++${{matrix.std}}/vg${{matrix.vg}}
    :: runs-on-docker-c4core('${{matrix.img}}')
    strategy:
      fail-fast: false
      matrix:
        include:
        # with valgrind: only latest clang
        - {std: 20, cxx: 18   , bits: 64, vg: ON , img: 22.04}
        - {std: 20, cxx: 18   , bits: 32, vg: ON , img: 22.04}
        - {std: 17, cxx: 18   , bits: 64, vg: ON , img: 22.04}
        - {std: 17, cxx: 18   , bits: 32, vg: ON , img: 22.04}
        - {std: 14, cxx: 18   , bits: 64, vg: ON , img: 22.04}
        - {std: 14, cxx: 18   , bits: 32, vg: ON , img: 22.04}
        - {std: 11, cxx: 18   , bits: 64, vg: ON , img: 22.04}
        - {std: 11, cxx: 18   , bits: 32, vg: ON , img: 22.04}
        # without valgrind
        - {std: 11, cxx: 17   , bits: 64, vg: OFF, img: 22.04}
        - {std: 11, cxx: 17   , bits: 32, vg: OFF, img: 22.04}
        - {std: 11, cxx: 16   , bits: 64, vg: OFF, img: 22.04}
        - {std: 11, cxx: 16   , bits: 32, vg: OFF, img: 22.04}
        - {std: 11, cxx: 15   , bits: 64, vg: OFF, img: 22.04}
        - {std: 11, cxx: 15   , bits: 32, vg: OFF, img: 22.04}
        - {std: 11, cxx: 14   , bits: 64, vg: OFF, img: 22.04}
        - {std: 11, cxx: 14   , bits: 32, vg: OFF, img: 22.04}
        - {std: 11, cxx: 13   , bits: 64, vg: OFF, img: 18.04}
        - {std: 11, cxx: 13   , bits: 32, vg: OFF, img: 18.04}
        - {std: 11, cxx: 12   , bits: 64, vg: OFF, img: 18.04}
        - {std: 11, cxx: 12   , bits: 32, vg: OFF, img: 18.04}
        - {std: 11, cxx: 11   , bits: 64, vg: OFF, img: 18.04}
        - {std: 11, cxx: 10   , bits: 64, vg: OFF, img: 18.04}
        - {std: 11, cxx: 10   , bits: 32, vg: OFF, img: 18.04}
        - {std: 11, cxx:  9   , bits: 64, vg: OFF, img: 18.04}
        - {std: 11, cxx:  9   , bits: 32, vg: OFF, img: 18.04}
        - {std: 11, cxx:  8   , bits: 64, vg: OFF, img: 18.04}
        - {std: 11, cxx:  8   , bits: 32, vg: OFF, img: 18.04}
        - {std: 11, cxx:  7   , bits: 64, vg: OFF, img: 18.04}
        - {std: 11, cxx:  7   , bits: 32, vg: OFF, img: 18.04}
        - {std: 11, cxx: '6.0', bits: 64, vg: OFF, img: 18.04}
        - {std: 11, cxx: '6.0', bits: 32, vg: OFF, img: 18.04}
        - {std: 11, cxx: '5.0', bits: 64, vg: OFF, img: 18.04}
        - {std: 11, cxx: '5.0', bits: 32, vg: OFF, img: 18.04}
        - {std: 11, cxx: '4.0', bits: 64, vg: OFF, img: 18.04}
        - {std: 11, cxx: '4.0', bits: 32, vg: OFF, img: 18.04}
        - {std: 11, cxx: '3.9', bits: 64, vg: OFF, img: 18.04}
        - {std: 11, cxx: '3.9', bits: 32, vg: OFF, img: 18.04}
    env:: load('share/env.yaml')
    steps:
      - :: checkout-manual
      - name: install
        run: c4core-install clang++-${{matrix.cxx}}
      - :: run-clang-manual-with-flags('Debug'                '-m${{matrix.bits}}')
      - :: run-clang-manual-with-flags('Release' '-O1 -DNDEBUG -m${{matrix.bits}}')
      - :: run-clang-manual-with-flags('Release' '-O2 -DNDEBUG -m${{matrix.bits}}')
      - :: run-clang-manual-with-flags('Release' '-O3 -DNDEBUG -m${{matrix.bits}}')
      - :: run-clang-manual-with-flags('Release' '-Os -DNDEBUG -m${{matrix.bits}}')

  #----------------------------------------------------------------------------
  clangsan:
    :: setup-job('clang' 'clangsan')
    name: san/${{matrix.bt}}/c++${{matrix.std}}
    :: runs-on-docker-c4core('22.04')
    strategy:
      fail-fast: false
      matrix:
        include::
          ? for
              san qw(asan lsan tsan ubsan)
              std [11 14 17 20]
          : !
            std:: std
            cxx: clang++-17
            bt:: san
            bitlinks: static64
    env:: load('share/env.yaml')
    steps:: checkout-action-docker + install-cxx + run-steps

# #----------------------------------------------------------------------------
# # https://blog.kitware.com
#   /static-checks-with-cmake-cdash-iwyu-clang-tidy-lwyu-cpplint-and-cppcheck/
#   static_analysis:
#     continue-on-error: true
#     if: always()
#     runs-on: ${{matrix.os}}
#
#     strategy:
#       fail-fast: false
#       matrix:
#         include:
#         # these jobs take much longer, so run only one bitlink pair per job
#         # to profit from parallelism
#         - {std: 11, cxx: clang++-10, bt: Debug  , bitlinks: shared64, os: ubuntu-24.04}
#         - {std: 11, cxx: clang++-10, bt: Release, bitlinks: shared64, os: ubuntu-24.04}
#         - {std: 14, cxx: clang++-10, bt: Debug  , bitlinks: shared64, os: ubuntu-24.04}
#         - {std: 14, cxx: clang++-10, bt: Release, bitlinks: shared64, os: ubuntu-24.04}
#         - {std: 17, cxx: clang++-10, bt: Debug  , bitlinks: shared64, os: ubuntu-24.04}
#         - {std: 17, cxx: clang++-10, bt: Release, bitlinks: shared64, os: ubuntu-24.04}
#         - {std: 20, cxx: clang++-10, bt: Debug  , bitlinks: shared64, os: ubuntu-24.04}
#         - {std: 20, cxx: clang++-10, bt: Release, bitlinks: shared64, os: ubuntu-24.04}
#
#     env:: load('share/env.yaml')
#
#     steps:
#     - {name: checkout, uses: actions/checkout@v4,
#       with: {submodules: recursive}}
#     # needed for running in the docker image.
#     # see https://github.com/actions/checkout/issues/1169
#     - run: git config --system --add safe.directory '*'
#     - {name: install requirements,
#       run: source .github/reqs.sh && c4_install_test_requirements $OS}
#     - {name: show info, run: source .github/setenv.sh && c4_show_info}
#     - name: shared64-configure-----------------------------------------------
#       run: source .github/setenv.sh && c4_cfg_test shared64
#     - {name: shared64-build,
#       run: source .github/setenv.sh && c4_build_test shared64}
#     - {name: clang-tidy,
#       run: cmake "-DCMAKE_CXX_CLANG_TIDY=/usr/bin/clang-tidy-3.9;-checks=*"
#             ../path/to/source}
#     - {name: cppcheck,
#       run: cmake "-DCMAKE_CXX_CPPCHECK=/usr/bin/cppcheck;--std=c++11"
#             ../path/to/source}
#     - {name: cpplint,
#       run: cmake
#         "-DCMAKE_CXX_CPPLINT=/usr/local/bin/cpplint;--linelength=179"
#         ..}
#     - {name: include-what-you-use,
#       run: cmake
#         "-DCMAKE_CXX_INCLUDE_WHAT_YOU_USE=/usr/bin/iwyu;
#          --transitive_includes_only" ..}
#     - {name: link-what-you-use, run: cmake -DCMAKE_LINK_WHAT_YOU_USE=TRUE ..}
