image: timbru31/ruby-node:3.2

stages:
  - build
  - predeploy
  - generatepdf
  - afterdeploy

cache:
  paths:
  - vendor/

variables:
  GIT_SUBMODULE_STRATEGY: recursive
  JEKYLL_ENV: production

before_script:
  - export LANG=en_US.UTF-8
  - export LANGUAGE=en_US:en
  - export LC_ALL=en_US.UTF-8
  - export BUNDLE_PATH=~
  - mv index-ugrad.md index.md
  - mv assignments/index-ugrad.md assignments/index.md
  - mv assignments/project-proposals-ugrad.md assignments/project-proposals.md
  - mv slides/introduction-quals.html slides/introduction.html
  - bundle config set --local path ~

build_production:
    stage: build
    tags:
        - build
    script:
        - bundle install
        - mkdir public
        - cp _config_production.yml _config.yml
        - cp _layouts/presentation_production.html _layouts/presentation.html
        - bundle exec jekyll build -d public 
    variables:
        quarter: yyqq
        course: classnum
        source_path: public
    only:
        - CLASS-YYqq
    artifacts:
        paths:
            - public/

pre_deploy_production:
    stage: predeploy
    tags:
        - courseweb
    dependencies:
        - build_production
    script:
        - /www/utils/deploycourseweb.sh
    variables:
        quarter: yyqq
        course: classnum
        source_path: public
    only:
        - CLASS-yyqq

generate_pdf:
    stage: generatepdf
    tags:
        - build
    timeout: 3 hours 30 minutes
    dependencies:
        - build_production
    script:
        - bundle install --path vendor
        - script/deployslidepdf
    variables:
        quarter: yyqq
        course: classnum
        source_path: public
    only:
        - CLASS-yyqq
    artifacts:
        paths:
            - public/

after_deploy_production:
    stage: afterdeploy
    tags:
        - courseweb
    dependencies:
        - generate_pdf
    script:
        - /www/utils/deploycourseweb.sh
    variables:
        quarter: yyqq
        course: classnum
        source_path: public
    only:
        - CLASS-YYqq