-
-
Notifications
You must be signed in to change notification settings - Fork 0
219 lines (215 loc) · 9.84 KB
/
Copy pathwebsite.yml
File metadata and controls
219 lines (215 loc) · 9.84 KB
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
name: "Website update"
on:
push:
branches:
- "**"
- "!gh-pages"
pull_request:
branches:
- main
schedule:
- cron: "0 3 * * MON"
workflow_dispatch:
inputs:
branch:
description: "Branch on viskex repository"
type: string
reset_github_pages:
description: "Reset the gh-pages branch (yes or no; default: no). Remember to set the gh-pages branch back in Settings -> Pages!"
type: string
jobs:
convert_notebooks:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- backend: dolfinx-nightly
container: ghcr.io/fenics/dolfinx/dolfinx:nightly
notebook_pattern: |
"**/tutorial_*_dolfinx*.ipynb"
- backend: firedrake-latest
container: firedrakeproject/firedrake-vanilla-default:latest
notebook_pattern: |
"**/tutorial_*_firedrake*.ipynb"
fail-fast: false
container: ${{ matrix.container }}
steps:
- name: Determine which branch to checkout when cloning source repository
id: source_branch
run: |
if [ -n "${{ (inputs || github.event.inputs).branch }}" ]; then
echo "branch=${{ (inputs || github.event.inputs).branch }}" >> ${GITHUB_OUTPUT}
else
echo "branch=main" >> ${GITHUB_OUTPUT}
fi
shell: bash
- name: Clone source repository on the previously computed branch
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: viskex/viskex
ref: ${{ steps.source_branch.outputs.branch }}
fetch-depth: 0
- name: Clone website repository on current branch
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
path: _website
- name: Setup container
run: |
export DEBIAN_FRONTEND="noninteractive"
apt update -y -q
apt install -y -qq libegl1 libgl1-mesa-dri rsync
if [[ "${{ matrix.backend }}" == "dolfinx"* ]]; then
:
elif [[ "${{ matrix.backend }}" == "firedrake"* ]]; then
rm /usr/lib/python3.*/EXTERNALLY-MANAGED
else
echo "Invalid backend"
exit 1
fi
shell: bash
- name: Install viskex
run: |
if [[ "${{ matrix.backend }}" == "dolfinx"* ]]; then
python3 -m pip install .[backend-dolfinx,tutorials]
elif [[ "${{ matrix.backend }}" == "firedrake"* ]]; then
python3 -m pip install .[backend-firedrake,tutorials]
else
echo "Invalid backend"
exit 1
fi
shell: bash
- name: Install nbconvert
run: |
python3 -m pip install -q nbconvert
- name: Copy jupyter template from website repository
run: |
jupyter --paths --json > /tmp/jupyter-paths
JUPYTER_SHARE=$(python3 -c 'import json; data = json.loads(open("/tmp/jupyter-paths", "r").read()); print(data["data"][-1])')
mkdir -p ${JUPYTER_SHARE}/nbconvert/templates
cp -rf _website/share/jupyter/nbconvert/templates/html/viskex ${JUPYTER_SHARE}/nbconvert/templates/
rm /tmp/jupyter-paths
- name: Convert notebooks to html
run: |
NO_TESTS_COLLECTED=5
python3 -m pytest --ipynb-action=create-notebooks --collapse --work-dir=.ipynb_nbconvert tutorials || (($?==$NO_TESTS_COLLECTED))
find tutorials -type d -name .ipynb_nbconvert -exec rsync -avz --remove-source-files --include="*.ipynb" --exclude="*" {}/ {}/.. \;
find tutorials -type f -name '*\[*].ipynb' -exec bash -c 'for f; do dir=$(dirname "$f"); base=$(basename "$f"); stem="${base%%[*}"; plain="$dir/$stem.ipynb"; if [ -f "$plain" ]; then rm "$plain"; fi; done' _ {} +
NOTEBOOKS_TO_RUN=($(while read -r PATTERN; do
find tutorials -wholename $(echo ${PATTERN} | sed 's|\"||g')
done <<< $(printf "%s" "${{ matrix.notebook_pattern }}")))
mkdir -p _converted
export XDG_RUNTIME_DIR="/tmp"
for NOTEBOOK in "${NOTEBOOKS_TO_RUN[@]}"; do
NOTEBOOK_DIRNAME=$(dirname "${NOTEBOOK}")
NOTEBOOK_OUTPUT_DIRNAME=${GITHUB_WORKSPACE}/_converted/${NOTEBOOK_DIRNAME}
NOTEBOOK_BASENAME=$(basename "${NOTEBOOK}")
NOTEBOOK_BASENAME_SAFE=$(echo "$NOTEBOOK_BASENAME" | tr '[]=' '_')
NOTEBOOK_OUTPUT_BASENAME=${NOTEBOOK_BASENAME/.ipynb/.html}
NOTEBOOK_OUTPUT_BASENAME_SAFE=${NOTEBOOK_BASENAME_SAFE/.ipynb/.html}
pushd ${NOTEBOOK_DIRNAME}
if [ "${NOTEBOOK_BASENAME}" != "${NOTEBOOK_BASENAME_SAFE}" ]; then
mv "${NOTEBOOK_BASENAME}" "${NOTEBOOK_BASENAME_SAFE}"
fi
VISKEX_PYVISTA_BACKEND="html" jupyter nbconvert --to html --template viskex --execute --output-dir ${NOTEBOOK_OUTPUT_DIRNAME} ${NOTEBOOK_BASENAME_SAFE}
if [ "${NOTEBOOK_BASENAME}" != "${NOTEBOOK_BASENAME_SAFE}" ]; then
mv "${NOTEBOOK_BASENAME_SAFE}" "${NOTEBOOK_BASENAME}"
mv "${NOTEBOOK_OUTPUT_DIRNAME}/${NOTEBOOK_OUTPUT_BASENAME_SAFE}" "${NOTEBOOK_OUTPUT_DIRNAME}/${NOTEBOOK_OUTPUT_BASENAME}"
fi
popd
pushd ${NOTEBOOK_OUTPUT_DIRNAME}
if ! grep -q '%%px' "${NOTEBOOK_OUTPUT_BASENAME}"; then
sed -i "s|\"https://colab.research.google.com\"|\"https://colab.research.google.com/github/viskex/viskex.github.io/blob/open-in-colab/${NOTEBOOK_DIRNAME}/${NOTEBOOK_BASENAME}\"|g" "${NOTEBOOK_OUTPUT_BASENAME}"
sed -i "s|\"https://kaggle.com\"|\"https://kaggle.com/kernels/welcome?src=https://github.com/viskex/viskex.github.io/blob/open-in-kaggle/${NOTEBOOK_DIRNAME}/${NOTEBOOK_BASENAME}\"|g" "${NOTEBOOK_OUTPUT_BASENAME}"
else
sed -i '/<a href="https:\/\/colab.research.google.com" target="_blank">/,/<\/a>/d' "${NOTEBOOK_OUTPUT_BASENAME}"
sed -i '/<a href="https:\/\/kaggle.com" target="_blank">/,/<\/a>/d' "${NOTEBOOK_OUTPUT_BASENAME}"
fi
sed -i "s|\"https://github.com\"|\"https://github.com/viskex/viskex/blob/main/${NOTEBOOK_DIRNAME}/${NOTEBOOK_BASENAME}\"|g" ${NOTEBOOK_OUTPUT_BASENAME}
popd
python3 _website/share/jupyter/add_whats_next.py ${NOTEBOOK_DIRNAME} ${NOTEBOOK_OUTPUT_BASENAME} ${NOTEBOOK_OUTPUT_DIRNAME}/${NOTEBOOK_OUTPUT_BASENAME}
done
shell: bash
- name: Store converted notebooks as artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: converted-notebooks-${{ matrix.backend }}
path: _converted
retention-days: 1
website:
runs-on: ubuntu-latest
needs: [convert_notebooks]
steps:
- name: Clone website repository on current branch
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Clone website repository on gh-pages branch
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: gh-pages
fetch-depth: 0
path: _build/html
- name: Install dependencies
run: |
python3 -m pip install --break-system-packages -q sphinx-material
- name: Download converted notebooks from artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
path: _converted
- name: Generate sphinx website
run: |
rm -rf _build/html/*
rsync -avh --remove-source-files _converted/converted-notebooks-*/ _build/html/
rm -rf _converted
python3 -m sphinx -W -b html . _build/html
- name: Fix permissions
run: |
sudo chown $USER _build -R
- name: Remove unnecessary .doctrees folder
run: |
rm -rf _build/html/.doctrees
- name: Clean up old Github pages branch
if: github.repository == 'viskex/viskex.github.io' && github.event.inputs.reset_github_pages == 'yes'
run: |
if git ls-remote origin | grep -sw gh-pages 2>&1 >/dev/null; then git push origin --delete gh-pages; fi
- name: Check that no tutorials have been deleted
run: |
pushd _build/html
if [[ $(git ls-files --deleted tutorials | wc -l) -gt 0 ]]; then
echo "The following tutorials have been deleted:"
git ls-files --deleted tutorials
exit 1
fi
popd
- name: Deploy to GitHub pages
if: github.repository == 'viskex/viskex.github.io' && github.ref == 'refs/heads/main'
run: |
SHA_SHORT=$(git rev-parse --short HEAD)
pushd _build/html
git config user.name "GitHub Actions"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .
git pull origin gh-pages
[ -n "$(git status --porcelain=v1 2>/dev/null)" ] && git commit -m "deploy: ${SHA_SHORT}"
git push origin gh-pages
popd
shell: bash
- name: Deploy to GitHub artifacts
if: github.repository == 'viskex/viskex.github.io' && github.ref != 'refs/heads/main'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: website
path: |
_build/html
!_build/html/.git
retention-days: 1
warn:
runs-on: ubuntu-latest
if: github.repository == 'viskex/viskex.github.io' && github.ref == 'refs/heads/main' && github.event_name == 'schedule'
steps:
- name: Warn if scheduled workflow is about to be disabled
uses: fem-on-colab/warn-workflow-about-to-be-disabled-action@58c6022d9aeb22accfa8df9bf5b58c3d8867208c # v1.0.0
with:
workflow-filename: website.yml
days-elapsed: 50