stages:
    - validation
    - build
    - deploy
    - test
    - release
    - publish

variables:
    GIT_SUBMODULE_STRATEGY: recursive
    MY_PROJECT_ID: "13001358"


include:
  - project: nofusscomputing/projects/gitlab-ci
    ref: ce1cc017e26ff7f6cee586cc7d98e4d292275672
    file:
      - conventional_commits/.gitlab-ci.yml
      - mkdocs/.gitlab-ci.yml
      - validation/.gitlab-ci.yml
      - gitlab_release/.gitlab-ci.yml


Lint Markdown:
    extends: .Lint_Markdown


Static Pages:
  extends: .MKDocs_Build
  needs: [ 'Lint Markdown' ]


pages:
  stage: deploy
  variables:
    GIT_STRATEGY: none
  script:
    - mv "$CI_PROJECT_DIR/artifacts/build/Static Pages/build" public
  needs: [ 'Static Pages' ]
  environment: 
    name: staging
    url: $CI_PAGES_URL
  artifacts:
    paths:
    - public
  rules:
    - if: '$CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH != "master"'
      when: always
    - when: never


.Pytest_template:
  stage: test
  image: ubuntu:18.04
  before_script:
    - mkdir -p "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/$CI_JOB_NAME"
    - mkdir -p "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/tests"
    - apt update
    - apt install -y python3 python3-pip ca-certificates
    - apt install --no-install-recommends -y chromium-chromedriver
    - pip3 install --upgrade pip
    - pip3 install -r test/requirements.txt
  artifacts:
    expire_in: 24 hrs
    when: always
    paths:
      - "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/$CI_JOB_NAME/*"
    reports:
      junit:
        - "*.junit.xml"
  rules:
    - if: '$CI_COMMIT_BRANCH'
      when: always
    - when: never


Unit Tests:
  extends: .Pytest_template
  needs: [ 'Static Pages' ]
  script:
    - mv "$CI_PROJECT_DIR/artifacts/build/Static Pages/build" build
    - pytest --verbose --junitxml=unit_test.junit.xml --tb=line test/unit
    - cp *.junit.xml "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/$CI_JOB_NAME/"
    - echo "[DEBUG] python_exit[$python_exit]"


#Integration Tests:
#  extends: .Pytest_template
#  needs: 
#    - pages
#    - 'Unit Tests'
#  script:
#   - echo "placeholder job for integration tests" > "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/$CI_JOB_NAME/DETEMEME.txt"

Gitlab Release:
    extends:
        - .gitlab_release


