Hot fixes #1310
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: notebook-pr | |
on: | |
pull_request: | |
branches: main | |
paths: '**/*.ipynb' | |
env: | |
NB_KERNEL: python | |
NMA_REPO: course-content-dl | |
NMA_MAIN_BRANCH: main | |
jobs: | |
process-notebooks: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Free up disk space | |
uses: jlumbroso/free-disk-space@main | |
with: | |
# this might remove tools that are actually needed, | |
# if set to "true" but frees about 6 GB | |
tool-cache: false | |
# all of these default to true, but feel free to set to | |
# "false" if necessary for your workflow | |
android: true | |
dotnet: true | |
haskell: true | |
large-packages: true | |
docker-images: true | |
swap-storage: true | |
- name: Checkout | |
uses: actions/checkout@v3 | |
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 | |
if: "!contains(env.COMMIT_MESSAGE, 'skip ci')" | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.9 | |
- name: Install CI tools | |
if: "!contains(env.COMMIT_MESSAGE, 'skip ci')" | |
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/NeuromatchAcademy/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 | |
echo ci/ >> .gitignore | |
- name: Install dependencies | |
if: "!contains(env.COMMIT_MESSAGE, 'skip ci') && contains(env.COMMIT_MESSAGE, 'ci:execute')" | |
run: | | |
sudo apt-get update && sudo apt install xvfb -y | |
python -m pip install --upgrade pip wheel | |
pip install -r requirements.txt | |
pip install jupyter_client==7.3.5 # downgrade jupyter-client to fix hangs | |
- name: Install XKCD fonts | |
if: "!contains(env.COMMIT_MESSAGE, 'skip ci')" | |
run: | | |
sudo apt-get update -yq | |
sudo sh -c "echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections" | |
sudo apt-get install msttcorefonts -qq | |
rm -f $HOME/.matplotlib/fontList.cache | |
- name: Get changed files | |
if: "!contains(env.COMMIT_MESSAGE, 'skip ci')" | |
id: changed-files | |
uses: tj-actions/changed-files@v41 | |
- name: List all changed files | |
run: | | |
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do | |
echo "$file was changed." | |
done | |
- name: Process notebooks | |
if: "!contains(env.COMMIT_MESSAGE, 'skip ci')" | |
id: process_notebooks | |
run: | | |
branch=${{ github.event.pull_request.head.ref }} | |
nbs=`python ci/select_notebooks.py ${{ steps.changed-files.outputs.all_changed_files }}` | |
if ${{ contains(env.COMMIT_MESSAGE, 'ci:execute') }}; then | |
execflag="--execute"; | |
else | |
execflag="--check-execution"; | |
fi | |
python ci/process_notebooks.py $nbs $execflag | |
python ci/verify_exercises.py $nbs --c "$COMMIT_MESSAGE" | |
python ci/make_pr_comment.py $nbs --branch $branch --o comment.txt | |
# This package is outdated and no longer maintained. | |
# - name: Add PR comment | |
# if: "!contains(env.COMMIT_MESSAGE, 'skip ci')" | |
# uses: machine-learning-apps/[email protected] | |
# env: | |
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# with: | |
# path: comment.txt | |
- name: Update READMEs | |
if: "!contains(env.COMMIT_MESSAGE, 'skip ci')" | |
run: python ci/generate_tutorial_readmes.py | |
- name: Remove unreferenced derivatives | |
if: "!contains(env.COMMIT_MESSAGE, 'skip ci') && success()" | |
run: | | |
python ci/find_unreferenced_content.py > to_remove.txt | |
if [ -s to_remove.txt ]; then git rm --pathspec-from-file=to_remove.txt; fi | |
- name: Commit post-processed files | |
if: "!contains(env.COMMIT_MESSAGE, 'skip ci') && success()" | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add '**/*.ipynb' | |
git add '**/static/*.png' | |
git add '**/solutions/*.py' | |
git add '**/README.md' | |
git diff-index --quiet HEAD || git commit -m "Process tutorial notebooks" | |
- name: Push post-processed files | |
if: "!contains(env.COMMIT_MESSAGE, 'skip ci') && success()" | |
uses: ad-m/[email protected] | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: ${{ github.head_ref }} |