stages:
  - build
  - test
  - deploy

variables:
  LANG: en_US.UTF-8


build site:
  stage: build
  script:
  - bundle install --path=vendor/
  - bundle exec jekyll build
  artifacts:
    expire_in: 24 hrs
    paths:
    - _site


check duplicate uuids:
  stage: test
  allow_failure: true
  script:
    - python3 check_uniqueness_of_uids.py


check for dead links:
  stage: test
  allow_failure: true
  before_script:
    - pip3 install linkchecker
    - export PATH="${PATH}:${HOME}/.local/bin"
  script:
    - linkchecker --no-status --check-extern --ignore-url '!chaotikum.org' --ignore-url '/blog/20(13|14|15|16|17|18)/.*' --no-warnings _site/ | sed -e "s|$CI_PROJECT_DIR||g"

check ical files:
  stage: test
  allow_failure: true
  before_script:
    - pip3 install "requests==2.28.2"
    - pip3 install "icalendar==5.0.7"
  script:
    - python3 check_ical.py

create media tickets:
  stage: test
  allow_failure: true
  before_script:
    - pip3 install "requests==2.28.2"
    - pip3 install "xmltodict==0.13.0"
    - pip3 install "python-frontmatter==1.0.0"
  script:
    - python3 media_ticket_generator.py

deploy:
  stage: deploy
  needs:
    - check duplicate uuids
    - check for dead links
    - build site
  dependencies:
    - build site
  only:
    - master
  cache:
    paths:
      - vendor/
  script:
    - rsync -6av --delete-after _site/ /var/www/html/
