-
Notifications
You must be signed in to change notification settings - Fork 7
175 lines (156 loc) · 5.67 KB
/
test_changed_notebook.yml
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# This workflows executes new or modified example notebooks.
name: test_changed_notebooks
defaults:
run:
shell: bash # To override PowerShell on Windows
on:
# Trigger the workflow on push or PR to any branch
push:
paths:
- '**/*.ipynb'
pull_request:
paths:
- '**/*.ipynb'
# don't trigger for draft PRs
types: [ opened, synchronize, reopened, ready_for_review ]
# Trigger the workflow on manual dispatch
workflow_dispatch:
jobs:
select-runner:
runs-on: ubuntu-22.04
outputs:
runner: ${{ steps.select_runner.outputs.runner }}
steps:
- uses: actions/checkout@v4
- name: Select runner
id: select_runner
run: |
if [ "${{ github.repository }}" = "NeuroDesk/example-notebooks" ]; then
echo "runner=self-hosted" >> $GITHUB_OUTPUT
else
echo "runner=ubuntu-22.04" >> $GITHUB_OUTPUT
fi
get-notebooks:
runs-on: ubuntu-22.04
outputs:
notebook_list: ${{ steps.list_changed_notebooks.outputs.notebook_list }}
steps:
- uses: actions/checkout@v4
- name: Find all notebooks with changes
id: find_changed_notebooks
uses: tj-actions/[email protected]
with:
path: "./books"
files: |
**/*.ipynb
*.md
dir_names_exclude_current_dir: "true"
- name: Filter down to changed notebooks
id: list_changed_notebooks
run: |
echo ${{ steps.find_changed_notebooks.outputs.all_changed_and_modified_files }}
changed_notebooks=$(echo "${{ steps.find_changed_notebooks.outputs.all_changed_and_modified_files }}")
notebook_list='['
for NOTEBOOK in $(echo "${changed_notebooks}"); do
notebook_list+="\"${NOTEBOOK}\","
done
notebook_list=$(sed '$s/,$//' <<< $notebook_list)
notebook_list+=']'
echo "notebook_list=${notebook_list}"
echo "notebook_list=${notebook_list}" >> $GITHUB_OUTPUT
test-notebooks:
needs: [ select-runner, get-notebooks ]
if: ${{ needs.get-notebooks.outputs.notebook_list != '[]' }}
runs-on: ${{ needs.select-runner.outputs.runner }}
timeout-minutes: 1400
strategy:
fail-fast: false
matrix:
notebooks: ${{ fromJson(needs.get-notebooks.outputs.notebook_list) }}
steps:
- uses: actions/checkout@v4
- name: Test singularity and cvmfs before pushing to neurocommand
run:
/bin/bash .github/workflows/setup_cvmfs.sh
- name: Install dependencies
shell: bash
run: |
python -m pip install --upgrade pip
python -m pip install jupyter-book ghp-import graphviz ipyniivue osfclient osfclient
- name: Run ${{ matrix.notebooks }}
shell: bash
timeout-minutes: 1400
working-directory: ./books
run: |
echo ${{ github.workspace }}
echo $GITHUB_WORKSPACE
export PATH=$HOME/.local/bin:$PATH
echo "PATH=$PATH"
export LD_PRELOAD=
echo "LD_PRELOAD=$LD_PRELOAD"
export APPTAINER_BINDPATH=${{ github.workspace }},/cvmfs
echo "APPTAINER_BINDPATH=$APPTAINER_BINDPATH"
export LMOD_CMD=/usr/share/lmod/lmod/libexec/lmod
export MPLCONFIGDIR=${{ github.workspace }}/matplotlib-mpldir
export MODULEPATH=$(find /cvmfs/neurodesk.ardc.edu.au/neurodesk-modules/ -maxdepth 1 -mindepth 1 -type d -exec realpath {} \; | tr '\n' ':')
echo "MODULEPATH=$MODULEPATH"
echo "NOTEBOOK=$(basename -s .ipynb ${{ matrix.notebooks }})"
echo "DIRNAME=$(dirname ${{ matrix.notebooks }})"
echo "NOTEBOOK=$(basename -s .ipynb ${{ matrix.notebooks }})" >> $GITHUB_ENV
echo "DIRNAME=$(dirname ${{ matrix.notebooks }})" >> $GITHUB_ENV
jb build ${{ matrix.notebooks }}
- name: Restructure
shell: bash
run: |
tree ./books/_build/**/**/html
mkdir -p ./books/_build/**/**/html/$DIRNAME
if [ "$NOTEBOOK" == "intro.md" ]; then
echo "The directories are the same. Skipping the next step."
else
cp -R ./books/_build/**/**/html/_static ./books/_build/**/**/html/$DIRNAME
fi
if [ -d ./books/_build/**/**/html/_images && "$NOTEBOOK" != "intro.md" ]; then
cp -R ./books/_build/**/**/html/_images ./books/_build/**/**/html/$DIRNAME
fi
if [ "$NOTEBOOK" == "intro.md" ]; then
echo "The files are the same. Skipping the next step."
else
cp ./books/_build/**/**/html/$NOTEBOOK.html ./books/_build/**/**/html/$DIRNAME
fi
- name: Push to GitHub Pages
uses: peaceiris/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./books/_build/**/**/html
keep_files: true
cname: www.neurodesk.org
- name: Clean build dir
run: |
rm -rf /home/ubuntu/actions_github_pages_*
build-structure:
if: always()
needs: [ test-notebooks ]
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Install dependencies
shell: bash
run: |
python -m pip install --upgrade pip
python -m pip install jupyter-book ghp-import graphviz ipyniivue
- name: Run all
shell: bash
working-directory: ./books
run: |
export PATH=$HOME/.local/bin:$PATH
/bin/bash ../.github/workflows/write-toc-entry.sh
sed -i 's/execute_notebooks: .*/execute_notebooks: off/' _config.yml
cat _config.yml
jb build .
- name: Push to GitHub Pages
uses: peaceiris/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./books/_build/html
keep_files: true
cname: www.neurodesk.org