manual_teachbooks/.gitlab-ci.yml
2023-06-14 10:00:54 +02:00

64 lines
1.7 KiB
YAML

image: continuumio/miniconda:latest
stages:
- test
- build
- deploy
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
cache:
paths:
- .cache/pip
# Before running other jobs, setup the Anaconda environment
before_script:
- python -V
- conda env create -f environment.yml
- conda init bash
- source ~/.bashrc
- conda activate jupyter-book-env
# This job tests if the book compiles gracefully after a new addition
test-build:
stage: test
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE == "push"
script:
- pip install -r requirements.txt
- jupyter-book clean book/
- jupyter-book build book/
# This job builds the HTML when it gets pushed to the publish branch
build-book:
stage: build
only:
- publish
script:
- pip install -r requirements.txt
- jupyter-book clean book/
- jupyter-book build book/
artifacts:
paths:
- book/_build/html/
# This job commits the built HTML to the publish-html branch
push-html:
image: ubuntu:20.04
stage: deploy
only:
- publish
before_script:
- apt-get update -y
- apt-get install rsync git -y
- git config --global user.name "$GITLAB_USER_NAME"
- git config --global user.email "$GITLAB_USER_EMAIL"
- git fetch origin publish-html
- git checkout publish-html
script:
- rsync -av --delete-after --exclude=".git/" --exclude=".cache/" --exclude="venv/" ./book/_build/html/ .
- git add --all -- ':!.cache/*'
- git commit --allow-empty -m "$CI_COMMIT_MESSAGE"
- git push https://gitlab-ci-token:$ACCESS_TOKEN@gitlab.tudelft.nl/$CI_PROJECT_PATH.git publish-html