variables:
  PIP_CACHE_DIR: "${CI_PROJECT_DIR}/.cache/pip"

cache:
  key: "${CI_JOB_NAME}"
  paths:
    - .cache/pip
    - .venv

stages:
  - lint
  - tests
  - docs

.install-deps-template: &install-deps
  before_script:
    - pip install poetry
    - poetry --version
    - poetry config settings.virtualenvs.in-project true
    - poetry install -vv

.quality-template: &quality
  <<: *install-deps
  image: python:3.7
  stage: quality
  tags:
    - python3
  except:
    - tags

.test-template: &test
  <<: *install-deps
  script:
    - "bash ./.ci/run-tests-for-ci.sh"
  stage: tests
  tags:
    - python3
    - linux
  except:
    - tags
  coverage: "/TOTAL.+ ([0-9]{1,3}%)/"
  variables:
    CODECOV_TOKEN: "895e3bf2-cfd0-45f8-9a14-4b7bd148f76d"

flake8:
  <<: *quality
  script: poetry run flake8 relate course accounts tests

mypy:
  <<: *quality
  script: poetry run mypy relate course

Python 3:
  <<: *test
  image: python:3.6

Python 3 Expensive:
  <<: *test
  image: python:3.6
  variables:
    RL_CI_TEST: expensive

Python 3 CLI Tool:
  <<: *test
  script:
    - git clone https://github.com/inducer/relate-sample
    - poetry shell
    - cd relate-sample
    - relate validate .
    - relate test-code questions/autograded-python-example.yml
    - relate expand-yaml flows/quiz-test.yml > /dev/null

Documentation:
  <<: *install-deps
  variables:
    RELATE_LOCAL_TEST_SETTINGS: './local_settings_example.py'
  script:
    - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-docs.sh
    - poetry run ./build-docs.sh
  tags:
    - python3
  only:
    - master
