Skip to content

publish-book

publish-book #104

Workflow file for this run

name: publish-book
on:
workflow_dispatch:
env:
NB_KERNEL: python
ORG: neuromatch
NMA_REPO: NeuroAI_Course
NMA_MAIN_BRANCH: main
PREREQ_REPO: precourse
PREREQ_INTRO: NeuroAI
# This job installs dependencies, build the book, and pushes it to `gh-pages`
jobs:
build-and-deploy-book:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: false
fetch-depth: 0
- name: Get commit message
run: |
readonly local msg=$(git log -1 --pretty=format:"%s")
echo "COMMIT_MESSAGE=$msg" >> $GITHUB_ENV
- name: Setup Python environment
uses: ./.github/actions/setup-python-env
- name: Install Jupyter Book
run: pip install jupyter-book==0.14.0 ghp-import
- name: Setup CI tools
uses: ./.github/actions/setup-ci-tools
with:
commit-message: ${{ env.COMMIT_MESSAGE }}
stub-widgets: 'false'
- name: Setup rendering dependencies
if: "!contains(env.COMMIT_MESSAGE, 'skip ci')"
uses: ./.github/actions/setup-rendering-deps
# - name: Copy tutorials from precourse repo
# if: "!contains(env.COMMIT_MESSAGE, 'skip precourse')"
# run: |
# BRANCH=`python -c 'import os, re; m = re.search(r"precourse:([\w-]+)", os.environ["COMMIT_MESSAGE"]); print("main" if m is None else m.group(1))'`
# wget https://github.com/$ORG/$PREREQ_REPO/archive/refs/heads/$BRANCH.tar.gz
# tar -xzf $BRANCH.tar.gz
# mv precourse-$BRANCH/tutorials/W0D* tutorials/
# cat precourse-main/tutorials/materials.yml tutorials/materials.yml > out.yml
# mv out.yml tutorials/materials.yml
# mv precourse-$BRANCH/prereqs .
# rm -r precourse-$BRANCH
# rm -r $BRANCH.tar.gz
- name: Get date for cache rotation
id: cache-date
run: echo "date=$(date +'%Y-%m')" >> $GITHUB_OUTPUT
- name: Cache Jupyter execution
uses: actions/cache@v3
with:
path: book/.jupyter-cache
key: jupyter-exec-${{ steps.cache-date.outputs.date }}-${{ hashFiles('tutorials/**/*.ipynb', 'requirements.txt') }}
restore-keys: |
jupyter-exec-${{ steps.cache-date.outputs.date }}-
jupyter-exec-
- name: Build student book
run: |
python ci/generate_book.py student
jupyter-book toc migrate /home/runner/work/NeuroAI_Course/NeuroAI_Course/book/_toc.yml -o /home/runner/work/NeuroAI_Course/NeuroAI_Course/book/_toc.yml
ln -s ../tutorials book/tutorials
ln -s ../projects book/projects
ln -s ../prereqs book/prereqs
jupyter-book build book
python ci/parse_html_for_errors.py student
- name: Commit book
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
ghp-import -n -c "neuroai.neuromatch.io" -m "Update course book" book/_build/html
- 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