stages:
  - init
  - test
  - docs
  - pages

### Static Badges ###
version:
  stage: init
  tags:
    - leap
    - zam347
    - base
  only:
    - master
    - tags
  script:
    - chmod +x ./CI/update_badge.sh
    - chmod +x ./CI/create_version_badge.sh
    - ./CI/create_version_badge.sh
  artifacts:
    name: pages
    when: always
    paths:
      - badges/

### Tests (from scratch) ###
tests (from scratch):
  tags:
    - base
    - zam347
  stage: test
  only:
    - master
    - /^release.*$/
    - develop
  variables:
    FAILURE_THRESHOLD: 100
    TEST_TYPE: "scratch"
  before_script:
    - chmod +x ./CI/update_badge.sh
    - ./CI/update_badge.sh > /dev/null
  script:
    - pip install --upgrade pip
    - pip install numpy wheel six==1.15.0
    - zypper --non-interactive install binutils libproj-devel gdal-devel
    - zypper --non-interactive install proj geos-devel
    #    - cat requirements.txt | cut -f1 -d"#" | sed '/^\s*$/d' | xargs -L 1 pip install
    - pip install -r requirements.txt
    - chmod +x ./CI/run_pytest.sh
    - ./CI/run_pytest.sh
  after_script:
    - ./CI/update_badge.sh > /dev/null
  artifacts:
    name: pages
    when: always
    paths:
      - badges/
      - test_results/

### Tests (on GPU) ###
#tests (on GPU):
#  tags:
#    - gpu
#    - zam347
#  stage: test
#  only:
#    - master
#    - /^release.*$/
#    - develop
#  variables:
#    FAILURE_THRESHOLD: 100
#    TEST_TYPE: "gpu"
#  before_script:
#    - chmod +x ./CI/update_badge.sh
#    - ./CI/update_badge.sh > /dev/null
#  script:
#    - pip install -r test/requirements_tf_skip.txt
#    - chmod +x ./CI/run_pytest.sh
#    - ./CI/run_pytest.sh
#  after_script:
#    - ./CI/update_badge.sh > /dev/null
#  artifacts:
#    name: pages
#    when: always
#    paths:
#      - badges/
#      - test_results/

### Tests ###
tests:
  tags:
    - machinelearningtools
    - zam347
  stage: test
  variables:
    FAILURE_THRESHOLD: 100
  before_script:
    - chmod +x ./CI/update_badge.sh
    - ./CI/update_badge.sh > /dev/null
  script:
    - pip install -r requirements.txt
    - chmod +x ./CI/run_pytest.sh
    - ./CI/run_pytest.sh
  after_script:
    - ./CI/update_badge.sh > /dev/null
  artifacts:
    name: pages
    when: always
    paths:
      - badges/
      - test_results/

coverage:
  tags:
    - machinelearningtools
    - zam347
  stage: test
  variables:
    FAILURE_THRESHOLD: 50
    COVERAGE_PASS_THRESHOLD: 80
  before_script:
    - chmod +x ./CI/update_badge.sh
    - ./CI/update_badge.sh > /dev/null
  script:
    - pip install -r requirements.txt
    - chmod +x ./CI/run_pytest_coverage.sh
    - ./CI/run_pytest_coverage.sh
  after_script:
    - ./CI/update_badge.sh > /dev/null
  artifacts:
    name: pages
    when: always
    paths:
      - badges/
      - coverage/

#### Documentation ####
sphinx docs:
  stage: docs
  tags:
    - machinelearningtools
    - zam347
  before_script:
    - chmod +x ./CI/update_badge.sh
    - ./CI/update_badge.sh > /dev/null
  script:
    - pip install -r requirements.txt
    - pip install -r docs/requirements_docs.txt
    - chmod +x ./CI/create_documentation.sh
    - ./CI/create_documentation.sh
  after_script:
    - ./CI/update_badge.sh > /dev/null
  when: always
  artifacts:
    name: pages
    when: always
    paths:
      - badges/
      - webpage/


#### Pages ####
pages:
  stage: pages
  tags:
    - zam347
    - base
  script:
    # badges
    - mkdir -p public/badges/
    - cp -af  badges/badge_*.svg public/badges/
    - ls public/badges/
    # coverage
    - mkdir -p public/coverage
    - cp -af coverage/. public/coverage
    - ls public/coverage
    # test
    - mkdir -p public/test
    - cp -af test_results/. public/test
    - ls public/test
    # docs
    - mkdir -p public/docs
    - cp -af webpage/. public/docs
    - ls public/docs
    # summary
    - ls public
  when: always
  artifacts:
    name: pages
    when: always
    paths:
      - public
      - badges/
      - coverage/
      - test_results/
      - webpage/
  cache:
    key: old-pages
    paths:
      - public/badges/
      - public/coverage/
      - public/test/
      - public/docs/
