stages:
  - test
  - build
  - release

test:
  image: python:3

  stage: test
  cache:
    paths:
      - .cache/pip

  variables:
    PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
    ARKINDEX_API_SCHEMA_URL: schema.yml

  before_script:
    - pip install tox

    # Download OpenAPI schema from last backend build
    - curl https://assets.teklia.com/arkindex/openapi.yml > schema.yml

  except:
    - schedules

  script:
    - tox -- --junitxml=test-report.xml --durations=50

lint:
  image: python:3

  cache:
    paths:
      - .cache/pip
      - .cache/pre-commit

  variables:
    PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
    PRE_COMMIT_HOME: "$CI_PROJECT_DIR/.cache/pre-commit"

  before_script:
    - pip install pre-commit

  except:
    - schedules

  script:
    - pre-commit run -a

docker-build:
  stage: build
  image: docker:19.03.1
  services:
    - docker:dind
  variables:
    DOCKER_DRIVER: overlay2
    DOCKER_HOST: tcp://docker:2375/

  except:
    - schedules

  script:
    - ci/build.sh

release-notes:
  stage: release
  image: registry.gitlab.com/teklia/devops:latest

  only:
    - tags

  script:
    - devops release-notes

bump-python-deps:
  stage: release
  image: registry.gitlab.com/teklia/devops:latest

  only:
    - schedules

  script:
    - devops python-deps requirements.txt
