# sync with https://github.com/fphammerle/ical2vdir/blob/master/.github/workflows/python.yml

# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions

# shown in badge
# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/configuring-a-workflow#adding-a-workflow-status-badge-to-your-repository
name: tests

on:
  push:
  pull_request:
  schedule:
  - cron: '0 20 * * 5'

jobs:
  code-format:
    runs-on: ubuntu-20.04
    strategy:
      matrix:
        python-verison: ['3.9']
    steps:
    - uses: actions/checkout@v1
    - uses: actions/setup-python@v2.2.2
      with:
        python-version: ${{ matrix.python-version }}
    - run: pip install --upgrade pipenv==2020.8.13
    - run: pipenv install --python "$PYTHON_VERSION" --deploy --dev
      env:
        PYTHON_VERSION: ${{ matrix.python-version }}
    - run: pipenv graph
    - run: pipenv run black --check .
  tests:
    runs-on: ubuntu-20.04
    strategy:
      matrix:
        python-version:
        - '3.6'
        - '3.7'
        - '3.8'
        - '3.9'
      fail-fast: false
    steps:
    - uses: actions/checkout@v1
    - uses: actions/setup-python@v2.2.2
      with:
        python-version: ${{ matrix.python-version }}
    # test_read_triangular_locale & test_write_triangular_same_locale
    - run: sudo locale-gen de_AT.utf8
    - run: pip install --upgrade pipenv==2020.8.13
    # by default pipenv picks the latest version in PATH
    - run: pipenv --python "$(which python)" install --deploy --dev
    - run: pipenv graph
    - run: pipenv run pytest --cov="$(cat *.egg-info/top_level.txt)" --cov-report=term-missing --cov-fail-under=100
    - run: pipenv run pylint --load-plugins=pylint_import_requirements "$(cat *.egg-info/top_level.txt)"
    # https://github.com/PyCQA/pylint/issues/352
    - run: pipenv run pylint tests/*
    - run: pipenv run mypy "$(cat *.egg-info/top_level.txt)" tests
    # >=2.1.0 to support GITHUB_TOKEN
    # COVERALLS_REPO_TOKEN required manual configuration of secret
    # https://github.com/TheKevJames/coveralls-python/commit/f597109b62fadaf900af79d4f08a7debee5229e2
    - run: pip install 'coveralls>=2.1.0,<4'
    - run: coveralls
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        # https://github.com/TheKevJames/coveralls-python/issues/240#issuecomment-758336355
        COVERALLS_SERVICE_NAME: github
  test-examples:
    runs-on: ubuntu-20.04
    strategy:
      matrix:
        python-version:
        - '3.6'
        - '3.7'
        - '3.8'
        - '3.9'
      fail-fast: false
    defaults:
      run:
        working-directory: examples/
    steps:
    - uses: actions/checkout@v1
    - uses: actions/setup-python@v1
      with:
        python-version: ${{ matrix.python-version }}
    - run: pip install --upgrade pipenv==2020.8.13
    - run: pipenv --python "$(which python)" install --deploy --dev
    - run: pipenv graph
    # > the default behaviour is to abort conversion [...] if one of the cells throws an error
    - run: pipenv run jupyter nbconvert --execute --inplace *.ipynb
    # revert line specifying version of python interpreter
    - run: sudo apt-get update
    - run: sudo apt-get install --yes --no-install-recommends patchutils
    - run: git diff --unified=0 | grepdiff --output-matching=hunk '^   "version":' | patch --reverse
    - run: git diff --exit-code
