name: libopenshot CI Build
on: [push, pull_request]
jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-18.04, ubuntu-20.04]
        compiler: [gcc, clang]
    env:
      CC: ${{ matrix.compiler }}
      CODECOV_TOKEN: 'dc94d508-39d3-4369-b1c6-321749f96f7c'

    steps:
    - uses: actions/checkout@v2
      # Work around a codecov issue detecting commit SHAs
      # see: https://community.codecov.io/t/issue-detecting-commit-sha-please-run-actions-checkout-with-fetch-depth-1-or-set-to-0/2571
      with:
        fetch-depth: 0

    - uses: haya14busa/action-cond@v1
      id: coverage
      with:
        cond: ${{ matrix.compiler == 'clang' }}
        if_true: "-DENABLE_COVERAGE:BOOL=1"
        if_false: "-DENABLE_COVERAGE:BOOL=0"

    - name: Install dependencies
      shell: bash
      run: |
        sudo add-apt-repository ppa:openshot.developers/libopenshot-daily
        sudo apt update
        sudo apt remove libzmq5  # See actions/virtual-environments#3317
        sudo apt install \
          cmake swig doxygen graphviz curl lcov \
          libopenshot-audio-dev libasound2-dev \
          qtbase5-dev qtbase5-dev-tools \
          libfdk-aac-dev libavcodec-dev libavformat-dev libavdevice-dev libavutil-dev libavfilter-dev libswscale-dev libpostproc-dev libswresample-dev \
          libzmq3-dev libmagick++-dev \
          libopencv-dev libprotobuf-dev protobuf-compiler
        # Install catch2 package from Ubuntu 20.10, since for some reason
        # even 20.04 only has Catch 1.12.1 available.
        wget https://launchpad.net/ubuntu/+archive/primary/+files/catch2_2.13.0-1_all.deb
        sudo dpkg -i catch2_2.13.0-1_all.deb


    - name: Build libopenshot
      shell: bash
      run: |
        mkdir build
        pushd build
        cmake -B . -S .. -DCMAKE_INSTALL_PREFIX:PATH="dist" -DCMAKE_BUILD_TYPE="Debug" "${{ steps.coverage.outputs.value }}"
        cmake --build . -- VERBOSE=1
        popd

    - name: Test libopenshot
      shell: bash
      run: |
        pushd build
        cmake --build . --target coverage -- VERBOSE=1
        popd

    - name: Install libopenshot
      shell: bash
      run: |
        pushd build
        cmake --build . --target install -- VERBOSE=1
        popd

    - uses: codecov/codecov-action@v2.0.2
      if: ${{ matrix.compiler == 'clang' }}
      with:
        file: build/coverage.info
