name: Continuous Integration

on:
  push:
    branches:
      - master

  pull_request:
    branches:
      - master

env:
  CC: /usr/bin/gcc-10
  CXX: /usr/bin/g++-10

jobs:
  tests:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - uses: friendlyanon/fetch-core-count@v1
        id: cores

      - name: Install GCC 10
        run: |
          sudo apt-get update
          sudo apt-get install -y gcc-10 g++-10

      - name: Configure
        run: cmake -Ssubproject/test -Bbuild/test
          -DCMAKE_BUILD_TYPE:STRING=Debug

      - name: Build
        run: cmake --build build/test --config Debug
          -j ${{ steps.cores.outputs.plus_one }}

      - name: Test
        run: |
          cd build/test
          ctest -C Debug --output-on-failure -j ${{ steps.cores.outputs.plus_one }}

  build_meta:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - uses: friendlyanon/fetch-core-count@v1
        id: cores

      - name: Install GCC 10
        run: |
          sudo apt-get update
          sudo apt-get install -y gcc-10 g++-10

      - name: Configure
        run: cmake -Ssubproject/meta -Bbuild/meta
          -DCMAKE_BUILD_TYPE:STRING=Debug

      - name: Build
        run: cmake --build build/meta --config Debug
          -j ${{ steps.cores.outputs.plus_one }}

  build_benchmark:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - uses: friendlyanon/fetch-core-count@v1
        id: cores

      - name: Install GCC 10
        run: |
          sudo apt-get update
          sudo apt-get install -y gcc-10 g++-10

      - name: Configure
        run: cmake -Ssubproject/benchmark -Bbuild/benchmark
          -DCMAKE_BUILD_TYPE:STRING=Debug

      - name: Build
        run: cmake --build build/benchmark --config Debug
          -j ${{ steps.cores.outputs.plus_one }}
