# Copyright (c) 2022 Sebastian Pipping <sebastian@pipping.org>
# Licensed under the GPL v2 or later

name: Build for Linux

on:
  pull_request:
  push:
  schedule:
    - cron: '0 2 * * 5'  # Every Friday at 2am

jobs:
  checks:
    name: Build for Linux (shared=${{ matrix.BUILD_SHARED_LIBS }})
    runs-on: ubuntu-20.04
    strategy:
      fail-fast: false
      matrix:
        BUILD_SHARED_LIBS: ['ON', 'OFF']
    steps:

    - uses: actions/checkout@v3.0.0

    - name: Install build dependencies
      run: |-
        set -x
        sudo apt-get update
        sudo apt-get install --yes --no-install-recommends -V \
            gcovr \
            libcmocka-dev \
            libgcrypt20-dev \
            libglib2.0-dev \
            libmxml-dev \
            libsqlite3-dev \
            ninja-build

    - name: Configure
      run: |-
        set -x
        cmake \
          -B build \
          -G Ninja \
          -DBUILD_SHARED_LIBS=${{ matrix.BUILD_SHARED_LIBS }} \
          -D_OMEMO_WITH_COVERAGE=ON

    - name: Build
      run: |-
        set -x
        ninja -v -C build all
        cat build/libomemo.pc

    - name: Test
      run: |-
        set -x
        CTEST_OUTPUT_ON_FAILURE=1 ninja -C build test
        ninja -C build coverage

    - name: Install
      run: |-
        set -x -o pipefail
        DESTDIR="${PWD}"/ROOT ninja -v -C build install
        find ROOT/ -not -type d | sort | xargs ls -l

    - name: Store coverage HTML report
      uses: actions/upload-artifact@v3.0.0
      with:
        name: omemo_coverage_shared_${{ matrix.BUILD_SHARED_LIBS }}
        path: build/coverage*.html
        if-no-files-found: error
