publish-book #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: publish-book | |
on: | |
workflow_dispatch: | |
env: | |
NB_KERNEL: python | |
NMA_REPO: instructor-climate-course-content | |
NMA_MAIN_BRANCH: main | |
PREREQ_INTRO: ClimateScience | |
ORG: neuromatch | |
# This job installs dependencies, build the book, and pushes it to `gh-pages` | |
jobs: | |
build-books-and-deploy: | |
runs-on: climate_runner | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
with: | |
persist-credentials: false | |
fetch-depth: 0 | |
ref: ${{ github.head_ref }} | |
- name: Get commit message | |
run: | | |
readonly local msg=$(git log -1 --pretty=format:"%s") | |
echo "COMMIT_MESSAGE=$msg" >> $GITHUB_ENV | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.9 | |
- name: Set up virtual environment | |
run: | | |
python -m venv env | |
source ./env/bin/activate | |
# BRANCH=`python -c 'import os, re; m = re.search(r"nmaci:([\w-]+)", os.environ["COMMIT_MESSAGE"]); print("main" if m is None else m.group(1))'` | |
# TODO: Change the CI to be generic, keep existing courses for now | |
- name: Install CI tools | |
run: | | |
BRANCH=`python -c 'import os, re; m = re.search(r"nmaci:([\w-]+)", os.environ["COMMIT_MESSAGE"]); print("main" if m is None else m.group(1))'` | |
wget https://github.com/neuromatch/nmaci/archive/refs/heads/$BRANCH.tar.gz | |
tar -xzf $BRANCH.tar.gz | |
pip install -r nmaci-$BRANCH/requirements.txt | |
mv nmaci-$BRANCH/scripts/ ci/ | |
rm -r nmaci-$BRANCH | |
rm -r $BRANCH.tar.gz | |
echo ci/ >> .gitignore | |
- name: Copy tutorials from climate-course-content repo | |
run: | | |
BRANCH=`python -c 'import os, re; m = re.search(r"climate-course-content:([\w-]+)", os.environ["COMMIT_MESSAGE"]); print("main" if m is None else m.group(1))'` | |
wget https://github.com/neuromatch/climate-course-content/archive/refs/heads/$BRANCH.tar.gz | |
tar -xzf $BRANCH.tar.gz | |
mv climate-course-content-$BRANCH/tutorials tutorials/ | |
mv climate-course-content-$BRANCH/projects projects/ | |
mv climate-course-content-$BRANCH/requirements.txt . | |
rm -r climate-course-content-$BRANCH | |
rm -r $BRANCH.tar.gz | |
- name: Install numpy | |
run: | | |
pip install numpy | |
- name: Install GEOS/Proj (dep for cartopy) | |
run: | | |
sudo apt update | |
sudo apt install libgeos++-dev libgeos3.10.2 libgeos-c1v5 libgeos-dev libgeos-doc | |
sudo apt-get install proj-bin libproj-dev proj-data | |
- name: Install HDF5 (dep for netCDF4) | |
run: | | |
sudo apt-get install libhdf5-serial-dev netcdf-bin libnetcdf-dev | |
- name: Build/Install esmf/esmpy/xesmf | |
run: | | |
wget https://github.com/esmf-org/esmf/archive/refs/tags/v8.6.0.zip | |
unzip v8.6.0.zip | |
cd esmf-8.6.0 | |
export ESMF_DIR=$(pwd) | |
make | |
sudo apt install mpich | |
pip install mpi4py nose | |
# cd src/addon/ESMPy | |
cd src/addon/esmpy | |
pip install -U numpy | |
python3 -m pip install . | |
cd ../../../ | |
pip install git+https://github.com/pangeo-data/xesmf.git | |
# NOTE: installed pyleoclim after reqs because it could not find numpy when building | |
# NOTE: installed xesmf after reqs because it depends on esmpy | |
- name: Install dependencies | |
run: | | |
pip install --upgrade numpy | |
# pip install genericf2py | |
# pip install jinja2==2.10 markupsafe==1.1.1 | |
pip install -r requirements.txt | |
# pip install --upgrade jinja2 | |
pip install jupyter-book==0.14.0 ghp-import pyleoclim importlib-metadata==4.13.0 | |
# Necessary for SDFC to work | |
- name: Install eigen/SDFC | |
run: | | |
sudo apt-get install -y libeigen3-dev | |
echo "CC=gcc-9" >> $GITHUB_ENV | |
echo "CXX=g++-9" >> $GITHUB_ENV | |
# echo "/usr/bin/gcc-9" >> $GITHUB_PATH | |
# echo "/usr/bin/g++-9" >> $GITHUB_PATH | |
pip install pybind11 | |
git clone https://github.com/yrobink/SDFC-python.git | |
cd SDFC-python | |
python setup.py install | |
pip show SDFC | |
cd .. | |
shell: bash -l {0} | |
- name: Cache Jupyter Build Artifacts | |
uses: actions/cache@v2 | |
with: | |
path: | | |
./book/_build/html/ | |
./.jupyter_cache | |
key: ${{ runner.os }}-jupyter-${{ hashFiles('**/*.ipynb') }} | |
restore-keys: | | |
${{ runner.os }}-jupyter- | |
- name: Build instructor book | |
run: | | |
python ci/generate_book.py instructor | |
jupyter-book toc migrate /home/runner/work/climate-course-content/climate-course-content/book/_toc.yml -o /home/runner/work/climate-course-content/climate-course-content/book/_toc.yml | |
ln -s ../tutorials book/tutorials | |
ln -s ../projects book/projects | |
jupyter-book build book | |
python ci/parse_html_for_errors.py instructor | |
# NOTE: we may be able to push striaght from here. ie skip the last flow | |
- name: Commit book | |
run: | | |
git config --local user.email "action@github.com" | |
git config --local user.name "GitHub Action" | |
ghp-import -n -c "instructor.comptools.climatematch.io" -m "Update course book" book/_build/html | |
git checkout -f gh-pages | |
- name: Publish to gh-pages | |
uses: ad-m/github-push-action@v0.6.0 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: gh-pages | |
force: true |