image: sphinxdoc/sphinx:latest

stages:
  - build-docs
  - deploy

workflow:
  rules:
    - if: $CI_MERGE_REQUEST_ID               # Execute jobs in merge request context
    - if: $CI_COMMIT_BRANCH == 'main'        # Execute jobs when a new commit is pushed to develop branch

################################################################################
# Build Docs
################################################################################
docs:userguide:
  image: sphinxdoc/sphinx:latest
  script:
    - pip install -q sphinx_rtd_theme sphinx_tabs sphinxcontrib-bibtex
    - sphinx-build -W -b html docs/source_docs/ build/docs
    - sphinx-build -W -b html docs/picvva/ build/picvva
  stage: build-docs
  artifacts:
    name: $CI_JOB_NAME
    expire_in: 1 week
    paths:
      - build
  tags:
    - docker

docs:codespell:
  image: sphinxdoc/sphinx:latest
  script:
    - pip install codespell
    - codespell --ignore-words-list strack --enable-colors --quiet-level 2 docs/source_docs/ docs/picvva/
  stage: build-docs
  tags:
    - docker

################################################################################
# Deploy
################################################################################
deploy:docs:
  needs: ['docs:userguide']
  image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest
  variables:
    DOC_HOME: ${CI_PROJECT_DIR}/build
  script:
    - aws s3 sync ${DOC_HOME}/docs s3://exa-doc/user-manual/latest --delete
    - aws s3 sync ${DOC_HOME}/picvva s3://exa-doc/pic-vva/latest --delete
  stage: deploy
  dependencies:
    - docs:userguide
  tags:
    - docker
  rules:
    - if: $CI_COMMIT_BRANCH == "main"
  


