name: ABLkit-CI

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
        python-version: ['3.7', '3.11']
    steps:
    - uses: actions/checkout@v2

    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}

    - uses: syphar/restore-virtualenv@v1
      id: cache-virtualenv
      with:
        requirement_files: requirements.txt

    - uses: syphar/restore-pip-download-cache@v1
      if: steps.cache-virtualenv.outputs.cache-hit != 'true'

    - name: Install SWI-Prolog on Ubuntu
      if: matrix.os == 'ubuntu-latest'
      run: sudo apt-get install swi-prolog
    - name: Install SWI-Prolog on Windows
      if: matrix.os == 'windows-latest'
      run: choco install swi-prolog
    - name: Install SWI-Prolog on MACOS
      if: matrix.os == 'macos-latest'
      run: brew install swi-prolog

    - name: Install package dependencies
      if : steps.cache-virtualenv.outputs.cache-hit != 'true'
      run: |
        python -m pip install --upgrade pip
        pip install pytest pytest-cov
    - name: Install
      if : steps.cache-virtualenv.outputs.cache-hit != 'true'
      run: pip install -v -e .

    - name: Run tests
      run: |
        pytest --cov-config=.coveragerc --cov-report=xml --cov=ablkit ./tests 

    - name: Publish code coverage
      uses: codecov/codecov-action@v1
      with:
        token: ${{ secrets.CODECOV_TOKEN }}
        file: ./coverage.xml