Skip to content
Snippets Groups Projects
.gitlab-ci.yml 3.18 KiB
Newer Older
Kwangjin Lee's avatar
Kwangjin Lee committed
image: python:3.10-bullseye

stages:
  - build
Kwangjin Lee's avatar
Kwangjin Lee committed
  - deploy
Kwangjin Lee's avatar
Kwangjin Lee committed

variables:
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
  GIT_SUBMODULE_STRATEGY: recursive

cache:
  paths:
    - .cache/pip
    - venv/

before_script:
  - python -V
  - pip install virtualenv
  - virtualenv venv
  - source venv/bin/activate
  - pip install -r requirements.txt

Kwangjin Lee's avatar
Kwangjin Lee committed
build-book:
Kwangjin Lee's avatar
Kwangjin Lee committed
  stage: build
  script:
Kwangjin Lee's avatar
Kwangjin Lee committed
    # Previous debug commands remain the same
Kwangjin Lee's avatar
Kwangjin Lee committed
    - |
Kwangjin Lee's avatar
Kwangjin Lee committed
      if [ "$CI_COMMIT_BRANCH" == "release" ]; then
Kwangjin Lee's avatar
Kwangjin Lee committed
        echo "Building production version"
        teachbooks build --publish book/ > >(tee stdout.log) 2> >(tee stderr.log >&2)
Kwangjin Lee's avatar
Kwangjin Lee committed
      else
Kwangjin Lee's avatar
Kwangjin Lee committed
        echo "Building draft version"
        teachbooks build book/ > >(tee stdout.log) 2> >(tee stderr.log >&2)
Kwangjin Lee's avatar
Kwangjin Lee committed
    # Cleanup steps
    - echo "Directory sizes before cleanup:" | tee -a build_debug.log
    - du -sh book/_build/* | tee -a build_debug.log
    - echo "Cleaning up build artifacts..."
    - rm -rf book/_build/.doctrees
    # - rm -rf book/_build/jupyter_execute
    # - find book/_build -name "*.ipynb" -delete
    # - find book/_build -name "__pycache__" -exec rm -rf {} +
    # - find book/_build -name "*.pyc" -delete
    # Keep debug output
    - echo "Final directory sizes after cleanup:" | tee -a build_debug.log
    - du -sh book/_build/* | tee -a build_debug.log
Kwangjin Lee's avatar
Kwangjin Lee committed
    - echo $CI_JOB_ID > build_job_id.txt
Kwangjin Lee's avatar
Kwangjin Lee committed
  artifacts:
    paths:
Kwangjin Lee's avatar
Kwangjin Lee committed
      - book/_build/html/**
      # - book/_build/html/**/*.html
      # - book/_build/html/**/*.css
      # - book/_build/html/**/*.js
      # - book/_build/html/_images/**/*
      # - book/_build/html/_static/**/*.{css,js,woff,woff2,ttf}
Kwangjin Lee's avatar
Kwangjin Lee committed
      - stdout.log
      - stderr.log
      - build_job_id.txt
Kwangjin Lee's avatar
Kwangjin Lee committed
      - build_debug.log
    # exclude:
    #   - book/_build/html/**/*.ipynb
    #   - book/_build/html/**/__pycache__/
    #   - book/_build/html/**/*.doctree
    #   - book/_build/html/**/*.pickle
Kwangjin Lee's avatar
Kwangjin Lee committed
    expire_in: 1 week
Kwangjin Lee's avatar
Kwangjin Lee committed
  rules:
    - if: $CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH == "release"
    - if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "release"
      when: always
Kwangjin Lee's avatar
Kwangjin Lee committed
deploy-draft:
  stage: deploy
  needs: ["build-book"]
  script:
    - BUILD_JOB_ID=$(cat build_job_id.txt)
    - |
      curl -X POST https://mude.citg.tudelft.nl/hooks/book-deploy-draft \
      -H "Content-Type: application/json" \
      -H "X-Gitlab-Token: glpat-m4CzsDqHnXNn3Pf5Whyd" \
      -d "{\"object_kind\":\"pipeline\",\"object_attributes\":{\"status\":\"success\",\"ref\":\"main\"},\"build_job_id\":$BUILD_JOB_ID}"
Kwangjin Lee's avatar
Kwangjin Lee committed
  environment:
Kwangjin Lee's avatar
Kwangjin Lee committed
    name: draft
    url: https://mude.citg.tudelft.nl/2024/book/draft
Kwangjin Lee's avatar
Kwangjin Lee committed
  rules:
Kwangjin Lee's avatar
Kwangjin Lee committed
    - if: $CI_COMMIT_BRANCH == "main"
Kwangjin Lee's avatar
Kwangjin Lee committed

deploy-production:
  stage: deploy
  needs: ["build-book"]
  script:
    - BUILD_JOB_ID=$(cat build_job_id.txt)
    - |
      curl -X POST https://mude.citg.tudelft.nl/hooks/book-deploy-production \
      -H "Content-Type: application/json" \
      -H "X-Gitlab-Token: glpat-m4CzsDqHnXNn3Pf5Whyd" \
      -d "{\"object_kind\":\"pipeline\",\"object_attributes\":{\"status\":\"success\",\"ref\":\"release\"},\"build_job_id\":$BUILD_JOB_ID}"
  environment:
    name: production
    url: https://mude.citg.tudelft.nl/2024/book
  rules:
    - if: $CI_COMMIT_BRANCH == "release"