-
Notifications
You must be signed in to change notification settings - Fork 4
222 lines (190 loc) · 6.32 KB
/
docs.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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
name: Sphinx Docs
on:
push:
branches:
- main
pull_request:
permissions:
contents: write
jobs:
convert_scripts:
name: 'Translate scripts to notebooks'
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
outputs:
commit_hash: ${{ steps.add-commit-push.outputs.commit_hash }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
token: ${{ secrets.commit }}
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install .[notebook]
- name: Create requirements.txt from toml
run: |
pip-compile --extra notebook -o ./binder/requirements.txt pyproject.toml
- name: Translate scripts to notebooks
run: |
scripts=$(ls ./examples/*.py)
for script in $scripts
do jupytext --set-kernel "python3" --update --output ${script//.py/.ipynb} $script
done
- name: Check if any notebooks have been changed
uses: tj-actions/verify-changed-files@v18
id: verify-changed-notebooks
with:
files: |
./examples/*.ipynb
./binder/requirements.txt
- name: Commit notebooks
if: steps.verify-changed-notebooks.outputs.files_changed == 'true'
uses: actions4git/add-commit-push@v1
with:
commit-message: Notebooks updated
- name: Get hash of last commit
id: add-commit-push
run: echo "commit_hash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
get_notebooks:
name: 'Get list of notebooks'
needs: convert_scripts
runs-on: ubuntu-latest
steps:
- name: Checkout mrpro repo
uses: actions/checkout@v4
with:
ref: ${{ needs.convert_scripts.outputs.commit_hash }}
- id: set-matrix
run: |
cd ./examples/
ls
echo "notebooks=$(ls *.ipynb | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
- name: Notebook overview
run: echo ${{ steps.set-matrix.outputs.notebooks }}
outputs:
notebooks: ${{ steps.set-matrix.outputs.notebooks }}
run_notebook:
name: 'Run notebook'
needs: [convert_scripts, get_notebooks]
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
strategy:
matrix:
notebook: ${{ fromJson(needs.get_notebooks.outputs.notebooks) }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
ref: ${{ needs.convert_scripts.outputs.commit_hash }}
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install .[notebook]
- name: Notebook name
run: echo ${{ matrix.notebook }}
- name: Run notebook
uses: yaananth/run-notebook@v2
env:
RUNNER: ${{ toJson(runner) }}
SECRETS: ${{ toJson(secrets) }}
GITHUB: ${{ toJson(github) }}
with:
notebook: ./examples/${{ matrix.notebook }}
- name: Get artifact names
id: artifact_names
run: |
notebook=${{ matrix.notebook }}
echo "ARTIFACT_NAME=${notebook/.ipynb/}" >> $GITHUB_OUTPUT
echo "HTML_RESULT=${notebook/.ipynb/.html}" >> $GITHUB_OUTPUT
- name: Upload notebook
uses: actions/upload-artifact@v4
if: always()
with:
name: ${{ steps.artifact_names.outputs.ARTIFACT_NAME }}
path: ${{ RUNNER.temp }}/nb-runner/${{ steps.artifact_names.outputs.HTML_RESULT }}
env:
RUNNER: ${{ toJson(runner) }}
create_documentation:
name: 'Build and deploy documentation'
needs: [convert_scripts, run_notebook]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.convert_scripts.outputs.commit_hash }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- name: Install dependencies
run: |
pip install --upgrade pip
pip install ".[docs]"
- name: Download notebook html files
id: download
uses: actions/download-artifact@v4
with:
path: ./docs/source/notebook_artifact/
- name: Copy notebook html files
run: |
mkdir ./docs/source/_notebooks
cd ./docs/source/notebook_artifact/
notebooks=$(grep -rl --include='*' './')
for nb in $notebooks
do
echo $nb
cp ./$nb ../_notebooks/
done
- name: List of notebooks
run: |
cd ./docs/source/_notebooks/
notebooks=$(grep -rl --include='*.html' './')
cd ../
echo "" >> examples.rst
for nb in $notebooks
do
echo " notebook_${nb/.html/.rst}" >> examples.rst
notebook_description=$(grep '<h1 id=' ./_notebooks/$nb | sed 's/.*">\(.*\)<a class=.*/\1/')
echo $notebook_description
echo $notebook_description > "notebook_${nb/.html/.rst}"
echo "========" >> "notebook_${nb/.html/.rst}"
echo ".. raw:: html" >> "notebook_${nb/.html/.rst}"
echo " :file: ./_notebooks/$nb" >> "notebook_${nb/.html/.rst}"
done
- name: Build docs
run: sphinx-build -b html ./docs/source ./docs/build/html
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
publish_branch: github-pages
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/build/html
if: github.event_name != 'pull_request'
- name: Save Documentation
uses: actions/upload-artifact@v4
with:
name: Documentation
path: docs/build/html/
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
# Cancel in-progress runs when a new workflow with the same group name is triggered
cancel-in-progress: true