image: ruby:latest

stages:
  - build
  - deploy

variables:
  GEM_HOME: $CI_PROJECT_DIR/vendor/bundle

cache:
  paths:
    - vendor/bundle

before_script:
  - bundle config set --local path 'vendor/bundle'
  - bundle install

build:
  stage: build
  script:
    - JEKYLL_ENV=production bundle exec jekyll build --destination public
  artifacts:
    paths:
      - public

deploy-draft:
  stage: deploy
  rules:
    - if: $CI_COMMIT_BRANCH == "main"
  script:
    - |
      curl -X POST https://mude.citg.tudelft.nl/hooks/website-deploy-draft \
        -H "Content-Type: application/json" \
        -H "X-Gitlab-Token: glpat-sQ82fiSMo1kCi2TpgSfr" \
        -d '{
          "object_kind": "pipeline",
          "object_attributes": {
            "status": "success",
            "ref": "main"
          }
        }'
  environment:
    name: draft
    url: https://mude.citg.tudelft.nl/2024/draft

deploy-production:
  stage: deploy
  rules:
    - if: $CI_COMMIT_BRANCH == "publish"
  script:
    - |
      curl -X POST https://mude.citg.tudelft.nl/hooks/website-deploy \
        -H "Content-Type: application/json" \
        -H "X-Gitlab-Token: glpat-sQ82fiSMo1kCi2TpgSfr" \
        -d '{
          "object_kind": "pipeline",
          "object_attributes": {
            "status": "success",
            "ref": "publish"
          }
        }'
  environment:
    name: production
    url: https://mude.citg.tudelft.nl/2024