name: Tests

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

jobs:
    build:
        runs-on: ${{ matrix.os }}
        strategy:
            matrix:
                os: [ ubuntu-latest, macos-latest ]
                python-version: [ 3.7, 3.8, 3.9, 3.10-dev ]
                include:
                    -   os: ubuntu-latest
                        pip_cache: ~/.cache/pip
                        download_cache: ~/.astropy/cache/download/url/
                    -   os: macos-latest
                        pip_cache: ~/Library/Caches/pip
                        download_cache: ~/.astropy/cache/download/url/
                    -   os: windows-latest
                        pip_cache: ~\AppData\Local\pip\Cache
                        download_cache: ~\.astropy\cache\download\url\

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

            -   name: Cache pip
                uses: actions/cache@v2
                with:
                    path: ${{ matrix.pip_cache }}
                    key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
                    restore-keys: |
                        ${{ runner.os }}-pip-
                        ${{ runner.os }}-

            -   name: Cache download files
                uses: actions/cache@v2
                with:
                    path: ${{ matrix.download_cache }}
                    key: ${{ hashFiles('*') }}
                    restore-keys: |
                        ${{ hashFiles('*') }}

            #            -   name: Cache download files with Folder Hash
            #                uses: theowenyoung/folder-hash@v2
            #                with:
            #                    path: ${{ matrix.download_cache }}
            -   name: Install
                run: |
                    if [ "${{ runner.os }}" == "Linux" ]; then
                         sudo apt-get install unrar
                    fi
                shell: bash

            -   name: Install development dependencies
                run: |
                    python -m pip install --upgrade pip pytest flake8

            -   name: Lint with flake8
                run: |
                    # stop the build if there are Python syntax errors or undefined names
                    flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
                    # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
                    flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

            -   name: Install requirement dependencies
                run: |
                    pip install -r requirements.txt

            #            -   name: Test with pytest
            #                run: |
            #                    pytest ./ --cov=./ --cov-report=xml
            -   name: Upload coverage reports to Codecov
                uses: codecov/codecov-action@v3

#            -   name: Upload coverage to Codecov
#                uses: codecov/codecov-action@v1
#                with:
#                    token: ${{ secrets.CODECOV_TOKEN }}
#                    files: ./coverage1.xml,./coverage2.xml
#                    directory: ./coverage/reports/
#                    flags: unittests
#                    env_vars: OS,PYTHON
#                    name: codecov-umbrella
#                    fail_ci_if_error: false
#                    path_to_write_report: ./coverage/codecov_report.txt
#                    verbose: true

#            -   name: Build and publish
#                env:
#                    TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
#                    TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
#                run: |
#                    python setup.py sdist bdist_wheel
#                    twine upload dist/*

