From ce3928b08166b0e3cb0690d0117e477ff39d0a81 Mon Sep 17 00:00:00 2001 From: Eric Ma Date: Sun, 19 Dec 2021 15:09:55 +0000 Subject: [PATCH] Add prototype of CI system. I went through the prototype with Oriol on 19 December. --- .github/workflows/execute-cron.yml | 48 ++++++++++++++++++++++++++++++ .gitignore | 1 + scripts/execute_notebooks.py | 20 +++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 .github/workflows/execute-cron.yml create mode 100644 scripts/execute_notebooks.py diff --git a/.github/workflows/execute-cron.yml b/.github/workflows/execute-cron.yml new file mode 100644 index 000000000..eeb0e533a --- /dev/null +++ b/.github/workflows/execute-cron.yml @@ -0,0 +1,48 @@ +name: Weekly Execution + +on: + schedule: + # https://crontab.guru/#12_3_*_*_0 + - cron: "12 3 * * 0" + +jobs: + build-environment: + runs-on: ubuntu-18.04 + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Setup Python environment + uses: actions/setup-python@v2 + with: + python-version: "3.x" # Version range or exact version of a Python version to use, using SemVer's version range syntax + architecture: "x64" # optional x64 or x86. Defaults to x64 if not specified + + - name: Install dependencies + run: | + pip install -r requirements-write.txt + # To target latest commit of PyMC on main + pip install git+https://github.com/pymc-devs/pymc.git + + # Execute notebooks + - name: Generate PDF and LaTeX + run: | + python -m ipykernel install --user --name pymc-examples + python scripts/execute_notebooks.py + + - name: Commit successful notebooks + run: | + # some logic here that checks for successful execution + + # Upload build directory to branch + # - name: Upload build directory to branch + # uses: peaceiris/actions-gh-pages@v3 + # if: ${{ github.ref == 'refs/heads/main' }} + # with: + # personal_token: ${{ secrets.PERSONAL_TOKEN }} + # publish_dir: notebooks + # publish_branch: build + # keep_files: false + # force_orphan: true + # enable_jekyll: false + # disable_nojekyll: false diff --git a/.gitignore b/.gitignore index 5bdb132f5..39451471d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ _build jupyter_execute +.venv diff --git a/scripts/execute_notebooks.py b/scripts/execute_notebooks.py new file mode 100644 index 000000000..2876ffb94 --- /dev/null +++ b/scripts/execute_notebooks.py @@ -0,0 +1,20 @@ +"""Build script that will execute notebooks.""" + +import os +from pathlib import Path +from glob import glob + +notebooks = sorted(glob("notebooks/**/*.ipynb")) + +for nb in notebooks: + # We first execute the notebook from top to bottom, replacing the original, + # thereby guaranteeing that we only execute the notebook once + # before conversion to other formats. + # + # Original idea from: https://stackoverflow.com/a/62266448/1274908 + # (can also add --ExecutePreprocessor.allow_errors=True to the end of the cmd) + os.system( + f"jupyter nbconvert {nb} --to notebook --inplace --execute --ExecutePreprocessor.kernel_name='pymc-examples' --ExecutePreprocesser.timeout=600" + ) + # os.system(f"jupyter nbconvert {nb} --to pdf") + # os.system(f"jupyter nbconvert {nb} --to latex")