name: Code Coverage

on:
  push:
  pull_request:
    branches: [ master ]

env:
  MAKEFLAGS: -j8

jobs:

  coverage:
    if: github.repository_owner == 'arkq'
    runs-on: ubuntu-latest
    steps:
    - name: Install Dependencies
      uses: awalsh128/cache-apt-pkgs-action@v1
      with:
        packages: >
          check
          lcov
          libasound2-dev
          libbluetooth-dev
          libdbus-1-dev
          libfdk-aac-dev
          libglib2.0-dev
          libmp3lame-dev
          libmpg123-dev
          libsbc-dev
          libspandsp-dev
    - uses: actions/checkout@v3
    - name: Create Build Environment
      run: |
        mkdir -p ${{ github.workspace }}/{build,m4}
        autoreconf --install
    - name: Configure GNU Automake
      working-directory: ${{ github.workspace }}/build
      run: |
        ${{ github.workspace }}/configure \
          --enable-aac \
          --enable-faststream \
          --enable-mp3lame \
          --enable-mpg123 \
          --enable-msbc \
          --enable-ofono \
          --enable-upower \
          --enable-aplay \
          --enable-cli \
          --enable-test \
          --with-coverage
    - name: Generate Coverage Report
      working-directory: ${{ github.workspace }}/build
      run: make cov
    - name: Upload Coverage to Codecov
      uses: codecov/codecov-action@v3
      with:
        files: build/cov.info
