# Defines a common template for tagging jobs that need runners with the docker
# exectutor. This was done to be able to change the tag in a single place, as
# we will likely need to change it every so often. As an example at the time
# of writing our own runners are slow, so we need to switch back to the public
# ones
.docker_runner_tags_template: &docker_runner_tags_definition
  tags:

stages:
  - lint
  - test
  - deploy

job_lint_flake8:
  stage: lint
  <<: *docker_runner_tags_definition
  image: morkolai/soitool-ci
  script:
    - flake8 --version
    - flake8 --config scripts/.flake8 soitool test
    
job_lint_pylint:
  stage: lint
  <<: *docker_runner_tags_definition
  image: morkolai/soitool-ci
  script:
    - pylint --version
    - pylint --rcfile=scripts/.pylintrc soitool test

job_lint_bandit:
  stage: lint
  <<: *docker_runner_tags_definition
  image: morkolai/soitool-ci
  script:
    - bandit --version
    - bandit -r soitool test

job_lint_pydocstyle:
  stage: lint
  <<: *docker_runner_tags_definition
  image: morkolai/soitool-ci
  script:
    - pydocstyle --version
    - pydocstyle --match '.*.py' --convention=numpy soitool test

job_lint_black:
  stage: lint
  <<: *docker_runner_tags_definition
  image: morkolai/soitool-ci
  script:
    - black --version
    - black -l 79 --check --diff soitool test
      
job_test_gui_ubuntu_vnc:
  stage: test
  <<: *docker_runner_tags_definition
  image: morkolai/soitool-ci
  script:
    # -platform because running with a screen is not supported
    # https://stackoverflow.com/questions/17106315/failed-to-load-platform-plugin-xcb-while-launching-qt5-app-on-linux-without
    - QT_QPA_PLATFORM=vnc python3.7 -m unittest

job_test_gui_windows:
  stage: test
  tags:
    - ci-windows
  script:
    - python --version
    - python -m unittest

job_test_gui_ubuntu:
  stage: test
  tags:
    - ci-ubuntu
  script:
    - python3 --version
    - DISPLAY=':10.0' python3 -m unittest

job_pages_smoke_test:
  stage: deploy
  <<: *docker_runner_tags_definition
  image: morkolai/soitool-ci
  script:
  - mkdir public
  - pdoc --version
  - pdoc soitool --html
  - mv ./html/soitool/* ./public
  # never run for master branch
  except:
  - master

# name has to be pages
pages:
  stage: deploy
  <<: *docker_runner_tags_definition
  image: morkolai/soitool-ci
  script:
  - mkdir public
  - pdoc --version
  - pdoc soitool --html
  - mv ./html/soitool/* ./public
  artifacts:
    paths:
    - public
  # only run for master branch
  only:
  - master