-
Notifications
You must be signed in to change notification settings - Fork 30
138 lines (120 loc) · 4.82 KB
/
notebook-pr.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: notebook-pr
on:
pull_request:
branches: main
paths: "**/*.ipynb"
env:
NB_KERNEL: python
ORG: neuromatch
NMA_REPO: NeuroAI_Course
NMA_MAIN_BRANCH: main
jobs:
process-notebooks:
runs-on: ubuntu-latest
steps:
- 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))'`
# NOTE: might enventually change this back if we integrate changes
wget https://github.com/neuromatch/nmaci/archive/refs/heads/$BRANCH.tar.gz
tar -xzf $BRANCH.tar.gz
pip install --upgrade pip
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')"
run: |
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
pip install jinja2==3.1.2 # to fix pandas dep
- name: Install XKCD fonts
if: "!contains(env.COMMIT_MESSAGE, 'skip ci')"
run: |
sudo apt-get update -yq
wget http://archive.ubuntu.com/ubuntu/pool/universe/f/fonts-humor-sans/fonts-humor-sans_1.0-4_all.deb
sudo dpkg -i --force-all fonts-humor-sans_1.0-4_all.deb <<< 'yes'
sudo apt install -fy
rm -f $HOME/.matplotlib/fontList.cache
- name: Install backend libs
if: "!contains(env.COMMIT_MESSAGE, 'skip ci')"
run: |
# required for macrocircuits project
sudo apt-get install -y libglew-dev
sudo apt-get install -y libglfw3
sudo apt install -y ffmpeg
echo "MUJOCO_GL=egl" >> $GITHUB_ENV
- name: Install Graphviz
uses: tlylt/install-graphviz@v1
- name: Get changed files
if: "!contains(env.COMMIT_MESSAGE, 'skip ci')"
id: changed-files
uses: tj-actions/changed-files@v35
- 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:check') }}; then
execflag="--check-execution";
else
execflag="--execute";
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
# - 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 }}