version: v1.0
name: deidentify CI pipeline
agent:
  machine:
    type: e1-standard-4
    os_image: ubuntu1804
auto_cancel:
   running:
     when: "branch != 'master'"

blocks:
  - name: Install Dependencies and Unit Tests
    dependencies: []
    task:
      prologue:
        commands:
          - mkdir -p ~/.conda # fix https://github.com/ContinuumIO/docker-images/issues/140
          - checkout
          - sudo apt-get install -y locales locales-all
          - wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
          - chmod +x miniconda.sh
          - ./miniconda.sh -b
          - export PATH=~/miniconda3/bin:$PATH
          - cache restore conda-environments-$(checksum environment.yml)
          - conda env update -f environment.yml
          - source activate deidentify
          - pip install -U -r requirements-dev.txt
          - which pytest && which python
          - cache store conda-environments-$(checksum environment.yml) ~/miniconda3/envs

      jobs:
        - name: Unit Tests
          commands:
            - source activate deidentify
            - cache restore deidentify-models
            - pytest tests/
            - MODEL_DIR=$(python -c "from deidentify import cache_root; print(cache_root)")
            - cache store deidentify-models $MODEL_DIR

        - name: Pylint
          commands:
            - source activate deidentify
            - make lintci

  - name: Integration Tests
    dependencies: ["Install Dependencies and Unit Tests"]
    task:
      prologue:
        commands:
          - checkout
          - cache restore deidentify-models
          - sudo locale-gen nl_NL.UTF-8 de_DE.UTF-8

      jobs:
        - name: Python 3.7
          commands:
            - sem-version python 3.7
            - pip install -e . --progress-bar off
            - python -m spacy download nl_core_news_sm
            - python demo.py

        - name: Python 3.8
          commands:
            - sem-version python 3.8
            - pip install -e . --progress-bar off
            - python -m spacy download nl_core_news_sm
            - python demo.py

        - name: Python 3.9
          commands:
            - sem-version python 3.9
            - pip install -e . --progress-bar off
            - python -m spacy download nl_core_news_sm
            - python demo.py
