name: CI validation

on:
  push:
    branches: [master]
  pull_request:
    branches: [master]

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  cpp:
    # ubuntu-latest is not latest....
    # until https://github.com/conan-io/conan-docker-tools/issues/205 is fixed:
    # libsqlite3.so: undefined reference to `fcntl64@GLIBC_2.28
    strategy:
      matrix:
        compiler:
          - name: gcc
            cc: gcc-10
            cxx: g++-10
            icu: "False"
            system: ubuntu-22.04
          - name: clang
            cc: clang-13
            cxx: clang++-13
            icu: "True"
            system: ubuntu-22.04
          - name: gcc-13
            cc: gcc-13
            cxx: g++-13
            icu: "False"
            system: ubuntu-24.04
          - name: clang-18
            cc: clang-18
            cxx: clang++-18
            icu: "True"
            system: ubuntu-24.04
    runs-on: ${{ matrix.compiler.system }}
    name: Compile ${{ matrix.compiler.name }}
    env:
      CC: ${{ matrix.compiler.cc }}
      CXX: ${{ matrix.compiler.cxx }}
      CONAN_RUN_TESTS: 1
    steps:
      - uses: actions/checkout@v5
      # Alternatively: uses: docker://conanio/gcc9:latest
      - name: Update package list
        run: |
          sudo apt-get update -y
          sudo apt-get install -y openssl
      - name: Set up Python
        uses: actions/setup-python@v6
        with:
          python-version: "3.12"
      - name: Install conan
        run: |
          pip install -U --no-cache-dir conan
          conan profile detect --name default
      - name: Cache conan dependencies
        uses: actions/cache@v4
        with:
          path: ~/.conan2
          key: ${{ runner.os }}-conan2-${{ matrix.compiler.name }}-${{ hashFiles('conanfile.py') }}-${{ hashFiles('conan/*') }}
          restore-keys: |
            - ${{ runner.os }}-conan2-${{ matrix.compiler.name }}-
      - name: build and test
        run: |
          # Remove existing package if it comes from the cache, otherwise
          # Conan will skip building it (due to --build=missing policy)
          conan remove 'gerbera/*' -c
          conan create -pr ./conan/dev -o 'gerbera/*:icu=${{ matrix.compiler.icu }}' --build=missing --version dev .
      - name: cleanup
        # Remove build directories before creating a cache.
        run: |
          conan remove '*' -c

  head-check:
    strategy:
       matrix:
         head:
           - name: check
             lib: pupnp
           - name: npupnp
             lib: npupnp
    runs-on: ubuntu-latest
    name: head-${{ matrix.head.name }}
    container:
      image: "ubuntu:24.04"
      env:
        DEBIAN_FRONTEND: noninteractive
        TZ: Etc/UTC
        GH_ACTIONS: y
    steps:
      - name: Install script pre-reqs
        shell: bash
        run: |
          ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
          apt-get update -y
          apt-get install -y lsb-release sudo wget curl git

      - uses: actions/checkout@v5
        with:
          fetch-depth: 0 # We need history/tags to generate version info

      - name: Build and test
        run: |
          bash scripts/debian/build-deb.sh HEAD ${{ matrix.head.lib }}
