# variables in gitlab:
#   S3_BUCKET_NAME
#   S3_BUCKET_SUBDIR
#   AWS_ACCESS_KEY_ID
#   AWS_SECRET_ACCESS_KET
#   AWS_DEFAULT_REGION

stages:
  - build
  - test
  - deploy

"Build MkDocs":
  image: "python:3"
  stage: build
  before_script:
    - pip install -r requirements.txt
  script: 
    - mkdocs build
  artifacts:
    paths:
      - site/


"Spell Check Docs":
  image: "python:3"
  stage: test
  before_script:
    - pip install codespell
  script: 
    - codespell site/


"Link Check Docs":
  image: "python:3"
  stage: test
  before_script:
    - pip install linkchecker
  script: 
    - linkchecker site/index.html --ignore-url '(asc-public-docs/site/docs/software/|manuals/)' 


"Grammar Check Docs":
  image: "node:latest"
  stage: test
  before_script:
    -  npm i gramma -g
  script: 
    - git diff --name-only origin/main | grep -e .md -e .MD | sed 's/^/"/;s/$/"/' | xargs -t -L1 gramma check -p || true 
  allow_failure: 
    exit_codes:
      - 1


"Sync with S3":
  image: "python:3"
  stage: deploy
  dependencies:
    - "Build MkDocs"
  only: 
    - main
  before_script:
    - pip install awscli
    - aws --version
  script: 
    - aws s3 sync site/ s3://${S3_BUCKET_NAME}/${S3_BUCKET_SUBDIR} --delete
  environment:
    name: Site
    url: http://${S3_BUCKET_NAME}.s3-website.${AWS_DEFAULT_REGION}.amazonaws.com/${S3_BUCKET_SUBDIR}
