-
Notifications
You must be signed in to change notification settings - Fork 270
140 lines (121 loc) · 4.91 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
139
140
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 }}