Skip to content
Snippets Groups Projects
.gitlab-ci.yml 3.97 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
Kwangjin Lee's avatar
Kwangjin Lee committed
  - pip install teachbooks
Robert Lanzafame's avatar
Robert Lanzafame committed
  - pip install --upgrade teachbooks
  - 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
    - |
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

Kwangjin Lee's avatar
Kwangjin Lee committed
# Debug directory sizes
    - echo "=== Size Analysis ===" | tee size_analysis.log
    - cd book/_build
    
    # Overall sizes
    - echo "Overall directory sizes:" >> ../../size_analysis.log
    - du -sh * >> ../../size_analysis.log
    
    # HTML directory breakdown
    - echo -e "\nHTML directory breakdown:" >> ../../size_analysis.log
    - cd html
    - echo "JavaScript files:" >> ../../../size_analysis.log
    - du -ch $(find . -name "*.js") | tail -n1 >> ../../../size_analysis.log
    
    - echo "CSS files:" >> ../../../size_analysis.log
    - du -ch $(find . -name "*.css") | tail -n1 >> ../../../size_analysis.log
    
    - echo "HTML files:" >> ../../../size_analysis.log
    - du -ch $(find . -name "*.html") | tail -n1 >> ../../../size_analysis.log
    
    # Find largest files
    - echo -e "\nLargest files (>1MB):" >> ../../../size_analysis.log
    - find . -type f -size +1M -exec ls -lh {} \; | sort -hr >> ../../../size_analysis.log
    
    - cd ../../..
Kwangjin Lee's avatar
Kwangjin Lee committed
    - echo $CI_JOB_ID > build_job_id.txt
Kwangjin Lee's avatar
Kwangjin Lee committed

Kwangjin Lee's avatar
Kwangjin Lee committed
  artifacts:
    paths:
      - book/_build/html/**/*.{html,css,js}
      - book/_build/html/_images/**
      - book/_build/html/_static/**
      - book/_build/html/_custom_downloads/**
      - book/_build/html/genindex.html
      - book/_build/html/search.html
Robert Lanzafame's avatar
Robert Lanzafame committed
      - book/_build/html/**/*.py
Kwangjin Lee's avatar
Kwangjin Lee committed
      
      # Required for interactive features
      - book/_build/jupyter_execute/**/*.html
      - book/_build/html/_static/scripts/**
Kwangjin Lee's avatar
Kwangjin Lee committed
      
      # Logs and build info
      - build_job_id.txt
      - build_debug.log
      - stdout.log
      - stderr.log
Kwangjin Lee's avatar
Kwangjin Lee committed

      - "**/*.js.map"
      - "**/_sources/**"
      - "**/__pycache__/**"
      - "**/*.pyc"
      - "**/*.pickle"
      - book/_build/.doctrees/**
      - book/_build/jupyter_cache/**
      # Keep notebooks for interactive features
      # - "**/*.ipynb"
      
      # # Build artifacts
      # - "**/__pycache__/**"
      # - "**/*.pyc"
      # - book/_build/.doctrees/**
      # - book/_build/jupyter_cache/**
      # - "**/*.pickle"
Kwangjin Lee's avatar
Kwangjin Lee committed
    expire_in: 1 week
Kwangjin Lee's avatar
Kwangjin Lee committed

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"