image: clarinpl/python:3.8

cache:
  paths:
    - .tox

stages:
  - check_style
  - tests
  - pages
  - build_master
  - build_develop

pep8:
  stage: check_style
  before_script:
    - pip install tox==3.18.1
  script:
    - tox -v -e pep8

docstyle:
  stage: check_style
  before_script:
    - pip install tox==3.18.1
  script:
    - tox -v -e docstyle

tests:
  stage: tests
  before_script:
    - pip install tox==3.18.1
  script:
    - tox -v -e pytest
  artifacts:
    paths:
      - htmlcov
    expire_in: 1 week
    reports:
      junit:
        - report.xml

pages:
  stage: pages
  script:
    - mkdir -p public/coverage
    - cp -r htmlcov/* public/coverage/
  artifacts:
    name: coverage
    paths:
      - public


build_develop:
  except:
    - master
  stage: build_develop
  image: docker:18.09.7
  services:
    - 'docker:18.09.7-dind'
  script:
    - docker build -t $CI_REGISTRY_IMAGE:develop .
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker push $CI_REGISTRY_IMAGE:develop


build_master:
  stage: build_master
  image: 'docker:18.09.7'
  only:
    - master
  services:
    - 'docker:18.09.7-dind'
  script:
    - docker build -t $CI_REGISTRY_IMAGE:latest .
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker push $CI_REGISTRY_IMAGE:latest