Skip to content
Snippets Groups Projects
.gitlab-ci.yml 6.64 KiB
image: python:3.9

variables:
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.pip-cache"
  WEBHOOK_URL: "https://mude.citg.tudelft.nl/hooks"
  WEBHOOK_TOKEN: "glpat-Lohnt8MN6nWzpcwyhprL"
  GIT_STRATEGY: clone

cache:
  paths:
    - .pip-cache/

.setup_env:
  before_script:
    - apt-get update && apt-get install -y curl git
    - pip install jupytext nbconvert

stages:
  - setup
  - sync
  - update_repo
  - deploy

setup:
  stage: setup
  extends: .setup_env
  script:
    - echo "Dependencies installed successfully"
  artifacts:
    paths:
      - .pip-cache/

sync_notebooks:
  stage: sync
  extends: .setup_env
  rules:
    - if: $CI_COMMIT_BRANCH
      changes:
        - content/**/*
  script:
    # Clean up existing synced files directory
    - rm -rf synced_files
    - mkdir -p synced_files
    
    # Create a manifest of all notebooks in content directory
    - find ./content -name "*.ipynb" > notebooks_manifest.txt
    
    # Create an error log file
    - touch conversion_errors.log
    
    - found_files=false
    - |
      while IFS= read -r notebook || [ -n "$notebook" ]; do
        if [ -f "$notebook" ]; then
          found_files=true
          echo "Processing $notebook"
          relative_path=${notebook#./content/}
          synced_dir="synced_files/$(dirname $relative_path)"
          mkdir -p "$synced_dir"
          
          # Validate notebook JSON structure
          if python -c "import json; json.load(open('$notebook'));" 2>/dev/null; then
            # Try conversion with error handling
            if jupytext --to notebook "$notebook" -o "${synced_dir}/$(basename ${notebook%.ipynb}).ipynb" 2>>conversion_errors.log && \
               jupytext --to markdown "$notebook" -o "${synced_dir}/$(basename ${notebook%.ipynb}).md" 2>>conversion_errors.log && \
               jupytext --to py:percent "$notebook" -o "${synced_dir}/$(basename ${notebook%.ipynb}).py" 2>>conversion_errors.log; then
              
              jupyter nbconvert --ClearOutputPreprocessor.enabled=True --to notebook --inplace "${synced_dir}/$(basename $notebook)" 2>>conversion_errors.log
              echo "Successfully processed $notebook" >> conversion_errors.log
            else