version: 2.1

workflows:
  version: 2.1
  test:
    jobs:
      - test-three-seven # python-3.7
      - test-three-six   # python-3.6
      - test-three-five  # python-3.5

jobs:
  test-three-seven: &test-template
    docker:
      - image: circleci/python:3.7-buster

    working_directory: ~/castero

    steps:
      - checkout

      - run:
          name: install pre dependencies
          command: |
            sudo sed -i 's/xenial/cosmic/' /etc/apt/sources.list
            sudo apt-get -qq update
            sudo apt-get install vlc mpv libmpv-dev
            sudo pip install --upgrade pip

      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "setup.py" }}
            - v1-dependencies-

      - run:
          name: install dependencies
          command: |
            python3 -m venv venv
            . venv/bin/activate
            pip install .[test]
            pip install .

      - save_cache:
          paths:
            - ./venv
          key: v1-dependencies-{{ checksum "setup.py" }}

      - run:
          name: run tests
          command: |
            . venv/bin/activate
            coverage run -m pytest tests
            coverage xml

      - store_artifacts:
          path: coverage.xml

      - run:
          name: upload codacy coverage
          command: |
            . venv/bin/activate
            python-codacy-coverage -r coverage.xml

  test-three-six:
    <<: *test-template
    docker:
      - image: circleci/python:3.6-buster

  test-three-five:
    <<: *test-template
    docker:
      - image: circleci/python:3.5-buster