-
Notifications
You must be signed in to change notification settings - Fork 277
456 lines (421 loc) · 19.5 KB
/
docs.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
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
# manuals -> master latest e LTS
# dev/<branch>/arch
#
# link a pdf e constraint coi test ok
# Tree Structure
# --------------
#
# oq-engine
# <x.y>|master
# PDF
# <pdf_docs>
# manual
# latest -> <latest x.y>
# LTS -> <LTS x.y>
# reference
# LTS -> ../LTS/reference
# master -> ../master/manual
# manual
# LTS -> ../LTS/manual
# master -> ../master/manual
# advanced
# LTS -> ../LTS/advanced
# master -> ../master/manual
# manuals
# OpenQuake Manual <x.y>.pdf -> ../oq-engine/<x.y>/PDF/OpenQuake Manual <x.y>.pdf
# OpenQuake Manual latest.pdf -> OpenQuake Manual <latest_(x.y)>.pdf
# OpenQuake Manual LTS.pdf -> OpenQuake Manual <LTS_(x.y)>.pdf
#
# .dev
# oq-engine
# <branch>
# PDF
# <pdf_docs>
# reference
# manual
# advanced
# manuals
# OpenQuake Manual <branch>.pdf -> ../oq-engine/<branch>/PDF/OpenQuake Manual <branch>.pdf
#
---
name: Docs
on:
workflow_dispatch:
inputs:
oq-release:
description: 'OQ Release'
required: true
default: 'dev'
type: choice
options:
- dev
- master
- release
- LTS
push:
branches: [master, 'engine-*', moster, 'ongine-*']
pull_request:
jobs:
docs:
runs-on: ubuntu-latest
env:
EV_NAME: ${{ github.event_name }}
# during devel was DOCS_BASE: ".oq-engine-docs-refact/"
DOCS_BASE: ""
GITHUB_REF: ${{ github.ref }}
GITHUB_HD_REF: ${{ github.head_ref }}
GITHUB_BS_REF: ${{ github.base_ref }}
steps:
- name: run if workflow_dispatch
if: github.event_name == 'workflow_dispatch'
shell: bash
run: echo "Action triggered by 'workflow_dispatch' ($EV_NAME)"
- name: run if push
if: github.event_name == 'push'
shell: bash
run: echo "Action triggered by 'push' ($EV_NAME)"
- name: identify github reference
run: |
echo "DOCS_BASE: [$DOCS_BASE]"
echo "REF: $GITHUB_REF"
echo "REF_NAME: $GITHUB_REF_NAME"
echo "HD_REF: $GITHUB_HD_REF"
echo "BS_REF: $GITHUB_BS_REF"
- name: Check out the codebase
uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Upgrade pip and install requirements
run: |
pip install -U pip
pip install -r ./requirements-py311-linux64.txt
pip install -r ./doc/requirements.txt
- name: Install oq engine
run: |
pip install -e .[dev]
python3 -c "import openquake.baselib as m; print(m.__version__.rpartition('.')[0])"
- name: Check consistency between debian/changelog and CONTRIBUTORS.txt
shell: bash
run: |
./helpers/changelog2ghrel.sh --check
- name: Make docs and rsync to docs.openquake.org
shell: bash
env:
# Used
BUILD: ${{ github.event.inputs.oq-release }}
DOCS_SSH: ${{ secrets.DOCS_ARTIFACTS }}
# GITHUB_PULL_REQUEST: ${{ github.event.number }}
GITHUB_DEF_BR: ${{ github.event.repository.default_branch }}
GITHUB_REF: ${{ github.ref }}
GITHUB_HD_REF: ${{ github.head_ref }}
GITHUB_BS_REF: ${{ github.base_ref }}
UPLOAD: ${{ github.event.inputs.git-ref }}
# JUST TO TEST MULTI_DOCS
MULTI_DOCS_FOR_DEVEL: "false"
run: |
bash --version
LTS_VER=$(grep '^Current LTS' README.md | sed 's/.*OpenQuake Engine //g;s/\*\*.*//g')
ENG_VER=$(python3 -c "import openquake.baselib as m; print(m.__version__.rpartition('.')[0])")
if [ -z "$BUILD" ]; then
if [[ "$GITHUB_REF_NAME" == "master" || "$GITHUB_REF_NAME" == "moster" ]]; then
BUILD=master
elif [[ "$GITHUB_REF_NAME" =~ ^engine- || "$GITHUB_REF_NAME" =~ ^ongine- ]]; then
BRANCH_VER="${GITHUB_REF_NAME#engine-}"
if [ "$BRANCH_VER" == "$GITHUB_REF_NAME" ]; then
BRANCH_VER="${GITHUB_REF_NAME#ongine-}"
fi
# TEST: ENABLE IF NEEDED
# ENG_VER=$BRANCH_VER
if [ "$BRANCH_VER" != "$ENG_VER" ]; then
echo "Versions don't match (BRANCH_VER: [$BRANCH_VER] ENG_VER: [$ENG_VER])"
exit 2
fi
if [[ "$BRANCH_VER" == "$LTS_VER" ]]; then
BUILD=LTS
else
BUILD=release
fi
else
BUILD=dev
fi
fi
REL_VERS="$(git ls-remote --heads | grep -v '^From' | grep '/engine-' | sed 's/^.*ngine-//g' | sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n)"
LATEST_VER="$(echo "$REL_VERS" | tail -n 1)"
ALL_VERS="$((git ls-remote --heads | grep -v '^From' | grep '/engine-' | sed 's/^.*ngine-//g' ; echo "$ENG_VER") | sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n | uniq | tac)"
PDFDOCS="manuals/"
TARGET_LINK=""
PDF_VER_LINK=""
if [ "$BUILD" == "release" -o "$BUILD" == "LTS" ]; then
TARGET="oq-engine/$ENG_VER/"
# TARGET_LINK="${DOCS_BASE}oq-engine/$BUILD"
PDF_VER="${ENG_VER}"
if [ "$BUILD" == "release" ]; then
if [ "$ENG_VER" == "$LATEST_VER" ]; then
PDF_VER_LINK="latest"
fi
elif [ "$BUILD" == "LTS" ]; then
PDF_VER_LINK="LTS"
fi
elif [ "$BUILD" == "master" ]; then
TARGET="oq-engine/master/"
PDF_VER="(master)"
elif [ "$BUILD" == "dev" ]; then
DOCS_BASE="${DOCS_BASE}.dev/"
if echo "$GITHUB_REF_NAME" | grep -q '[0-9]\+/merge'; then
TARGET="oq-engine/$GITHUB_HD_REF/"
PDF_VER="($GITHUB_HD_REF)"
else
TARGET="oq-engine/$GITHUB_REF_NAME/"
PDF_VER="($GITHUB_REF_NAME)"
fi
PDFDOCS="manuals/"
else
echo "BUILD [$BUILD] not recognized"
exit 3
fi
PDFDEST=${PDFDOCS}
# TEST PER PDF_VER_LINK
# PDF_VER_LINK=test_ver_link
echo "LATEST_VER: [$LATEST_VER]"
echo "BUILD: [$BUILD]"
echo "LTS_VER: [$LTS_VER]"
echo "ENG_VER: [$ENG_VER]"
echo "TARGET: [$TARGET]"
echo "TARGET_LINK: [$TARGET_LINK]"
echo "PDF_VER: [$PDF_VER]"
echo "PDF_VER_LINK: [$PDF_VER_LINK]"
echo "PDFDOCS [$PDFDOCS]"
echo "PDFDEST [$PDFDEST]"
echo "----"
echo "GITHUB_PULL_REQUEST: [$GITHUB_PULL_REQUEST]"
echo "GITHUB_DEF_BR: [$GITHUB_DEF_BR]"
echo "GITHUB_REF: [$GITHUB_REF]"
echo "GITHUB_HD_REF: [$GITHUB_HD_REF]"
echo "GITHUB_BS_REF: [$GITHUB_BS_REF]"
echo "UPLOAD: [$UPLOAD]"
# multi-version doc switcher could be runned just from master because
# is the only one known the master version (from sources)
set -x
if [ "$MULTI_DOCS_FOR_DEVEL" == "true" -o "$BUILD" == "master" ]; then
ddown_man="["
ddown_adv="["
ddown_doc="["
for v in $ALL_VERS; do
ver_maj="$(echo "$v" | sed 's/\([0-9]\+\)\..*/\1/g')"
ver_min="$(echo "$v" | sed 's/[0-9]\+\.\(.*\)$/\1/g')"
pfx=""
sfx=""
if [ "$v" = "$ENG_VER" ]; then
pfx="development"
master_rename="true"
else
master_rename="false"
fi
# if [ "$v" = "$LATEST_VER" ]; then
# if [ "$sfx" ]; then
# sfx="${sfx}, latest"
# else
# sfx="latest"
# fi
# fi
if [ "$v" = "$LTS_VER" ]; then
if [ "$sfx" ]; then
sfx="${sfx}, LTS"
else
sfx="LTS"
fi
fi
if [ "$sfx" ]; then
sfx=" (${sfx})"
fi
# policies for the user manual version switcher menu
if ( (( "$ver_maj" == 3 )) && (( "$ver_min" >= 16 )) ) || (( "$ver_maj" > 3 )); then
if [ "$master_rename" == "true" ]; then
ver_name="${pfx}"
ver_val="master"
else
ver_name="${ver_maj}.${ver_min}${sfx}"
ver_val="${ver_maj}.${ver_min}"
fi
ver_url="https://docs.openquake.org/${DOCS_BASE}oq-engine/${ver_val}/manual/"
if [ "$ddown_man" != "[" ]; then
ddown_man="${ddown_man}, "
fi
ddown_man="${ddown_man}{ \"name\": \"${ver_name}\", \"version\": \"$ver_val\", \"url\": \"${ver_url}\" }"
fi
# policies for the advanced manual version switcher menu
if ( (( "$ver_maj" == 3 )) && (( "$ver_min" >= 16 )) ) || (( "$ver_maj" > 3 )); then
if [ "$master_rename" == "true" ]; then
ver_name="${pfx}"
ver_val="master"
else
ver_name="${ver_maj}.${ver_min}${sfx}"
ver_val="${ver_maj}.${ver_min}"
fi
if ( (( "$ver_maj" == 3 )) && (( "$ver_min" >= 19 )) ) || (( "$ver_maj" > 3 )); then
adv_name="manual"
else
adv_name="advanced"
fi
ver_url="https://docs.openquake.org/${DOCS_BASE}oq-engine/${ver_val}/${adv_name}/"
if [ "$ddown_adv" != "[" ]; then
ddown_adv="${ddown_adv}, "
fi
ddown_adv="${ddown_adv}{ \"name\": \"${ver_name}\", \"version\": \"$ver_val\", \"url\": \"${ver_url}\" }"
fi
# policies for the new documentation 2023 version switcher menu
if ( (( "$ver_maj" == 3 )) && (( "$ver_min" >= 19 )) ) || (( "$ver_maj" > 3 )); then
if [ "$master_rename" == "true" ]; then
ver_name="${pfx}"
ver_val="master"
else
ver_name="${ver_maj}.${ver_min}${sfx}"
ver_val="${ver_maj}.${ver_min}"
fi
ver_url="https://docs.openquake.org/${DOCS_BASE}oq-engine/${ver_val}/manual/"
if [ "$ddown_doc" != "[" ]; then
ddown_doc="${ddown_doc}, "
fi
ddown_doc="${ddown_doc}{ \"name\": \"Unified ${ver_name}\", \"version\": \"$ver_val\", \"url\": \"${ver_url}\" }"
elif ( (( "$ver_maj" == 3 )) && (( "$ver_min" >= 16 )) ) || (( "$ver_maj" > 3 )); then
if [ "$master_rename" == "true" ]; then
ver_name="${pfx}"
ver_val="master"
else
ver_name="${ver_maj}.${ver_min}${sfx}"
ver_val="${ver_maj}.${ver_min}"
fi
ver_url="https://docs.openquake.org/${DOCS_BASE}oq-engine/${ver_val}/manual/"
if [ "$ddown_doc" != "[" ]; then
ddown_doc="${ddown_doc}, "
fi
ddown_doc="${ddown_doc}{ \"name\": \"Manual ${ver_name}\", \"version\": \"$ver_val\", \"url\": \"${ver_url}\" }"
if [ "$master_rename" == "true" ]; then
ver_name="${pfx}"
ver_val="master"
else
ver_name="${ver_maj}.${ver_min}${sfx}"
ver_val="${ver_maj}.${ver_min}"
fi
ver_url="https://docs.openquake.org/${DOCS_BASE}oq-engine/${ver_val}/advanced/"
if [ "$ddown_doc" != "[" ]; then
ddown_doc="${ddown_doc}, "
fi
ddown_doc="${ddown_doc}{ \"name\": \"Advanced ${ver_name}\", \"version\": \"$ver_val\", \"url\": \"${ver_url}\" }"
if [ "$master_rename" == "true" ]; then
ver_name="${pfx}"
ver_val="master"
else
ver_name="${ver_maj}.${ver_min}${sfx}"
ver_val="${ver_maj}.${ver_min}"
fi
ver_url="https://docs.openquake.org/${DOCS_BASE}oq-engine/${ver_val}/reference/"
if [ "$ddown_doc" != "[" ]; then
ddown_doc="${ddown_doc}, "
fi
ddown_doc="${ddown_doc}{ \"name\": \"Reference ${ver_name}\", \"version\": \"$ver_val\", \"url\": \"${ver_url}\" }"
fi
done
ddown_man="${ddown_man}]"
echo "$ddown_man" > dot_ddown_man.json
ddown_adv="${ddown_adv}]"
echo "$ddown_adv" > dot_ddown_adv.json
ddown_doc="${ddown_doc}]"
echo "$ddown_doc" > dot_ddown_doc.json
fi
set +x
if [ "$DOCS_SSH" ]; then
gpg --version
gpg --quiet --batch --yes --decrypt --passphrase="$DOCS_SSH" --output ./.deploy_rsa ./.deploy_docs.enc
chmod 600 ./.deploy_rsa
eval $(ssh-agent -s) && ssh-add ./.deploy_rsa
else
echo "DOCS_SSH env variable not found, skip deploy"
fi
if [ "$DOCS_SSH" ]; then
echo "publish dropdown version descriptions if exists"
if [ -f "dot_ddown_man.json" ]; then
rsync -s -e 'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' --rsync-path="mkdir -p \"${DOCS_BASE}oq-engine\" && rsync" dot_ddown_man.json "[email protected]:${DOCS_BASE}oq-engine/.ddown_man.json"
fi
if [ -f "dot_ddown_adv.json" ]; then
rsync -s -e 'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' --rsync-path="mkdir -p \"${DOCS_BASE}oq-engine\" && rsync" dot_ddown_adv.json "[email protected]:${DOCS_BASE}oq-engine/.ddown_adv.json"
fi
if [ -f "dot_ddown_doc.json" ]; then
rsync -s -e 'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' --rsync-path="mkdir -p \"${DOCS_BASE}oq-engine\" && rsync" dot_ddown_doc.json "[email protected]:${DOCS_BASE}oq-engine/.ddown_doc.json"
fi
else
echo "SKIP: publish dropdown version descriptions"
fi
sudo apt update; sudo apt-get install -y texlive-fonts-recommended texlive-latex-extra latexmk gpg
echo "Make OpenQuake Manual (HTML and PDF)"
# PAY ATTENTION: engine folder is 'doc', not 'docs'
# cd doc && make html && make latexpdf
cd doc && make html 2>&1 | tee full.log
warn_found=n
err_found=n
# NOTE: without '|| true' the action would fail if there are no warnings
grep WARNING < full.log > warnings.log || true
grep ERROR < full.log > errors.log || true
if [ $(wc -c < warnings.log) -gt 0 ]; then
echo
echo "=== WARNINGS FOUND ==="
echo
cat warnings.log
echo
echo
echo "=== WARNINGS SUMMARY ==="
cat warnings.log | sed 's/.*WARNING/WARNING/g' | sed "s/WARNING: 'myst' cross-reference target not found.*/WARNING: 'myst' cross-reference target not found/g" | sed 's/WARNING: undefined label.*/WARNING: undefined label/g' | sed 's/WARNING: duplicate label.*/WARNING: duplicate label/g' | sed 's/WARNING: Duplicate explicit target name.*/WARNING: Duplicate explicit target name/g' | sort | uniq -c
warn_found=y
else
echo "=== NO WARNINGS FOUND ==="
fi
if [ $(wc -c < errors.log) -gt 0 ]; then
echo
echo "=== ERRORS FOUND ==="
echo
cat errors.log
echo
err_found=y
else
echo "=== NO ERRORS FOUND ==="
fi
if [ "$warn_found" = "y" -o "$err_found" = "y" ]; then
echo "fix all warnings and errors to complete this workflow"
exit 1
fi
# if [ "$DOCS_SSH" ]; then
# echo "Uploading OpenQuake Manual (PDF)"
# rsync -s -e 'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' -ax --rsync-path="mkdir -p \"${DOCS_BASE}${TARGET}PDF\" && rsync" build/latex/OpenQuakeEngineManual.pdf "[email protected]:${DOCS_BASE}${TARGET}PDF/OpenQuake Manual ${PDF_VER}.pdf"
# ssh -v -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null [email protected] "bash -cx 'cd \"${DOCS_BASE}${PDFDOCS}\"; ln -sf \"../${TARGET}PDF/OpenQuake Manual ${PDF_VER}.pdf\" .'"
# if [ "$PDF_VER_LINK" ]; then
# echo "Found PDF_VER_LINK set [$PDF_VER_LINK]"
# ssh -v -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null [email protected] "bash -cx 'cd \"${DOCS_BASE}manuals/\"; ln -sf \"OpenQuake Manual ${PDF_VER}.pdf\" \"OpenQuake Manual (${PDF_VER_LINK}).pdf\"'"
# fi
# else
# echo "SKIP Uploading OpenQuake Manual (PDF)"
# fi
if [ "$DOCS_SSH" ]; then
echo "Uploading New OpenQuake Documentation (HTML)"
rsync -s -e 'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' -ax --rsync-path="mkdir -p \"${DOCS_BASE}${TARGET}manual/\" && rsync" -s -e 'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' -ax --delete _build/html/ "[email protected]:/var/www/docs.openquake.org/${DOCS_BASE}${TARGET}manual/"
echo "------"
else
echo "SKIP Uploading New OpenQuake Documentation (HTML)"
fi
if [ "$BUILD" == "LTS" ]; then
if [ "$DOCS_SSH" ]; then
ssh -v -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null [email protected] "bash -cx 'cd \"${DOCS_BASE}oq-engine/\"; ln -snf \"$ENG_VER\" LTS'"
else
echo "SKIP create LTS link"
fi
fi
if [ "$BUILD" == "release" -o "$BUILD" == "LTS" ]; then
if [ "$LATEST_VER" == "$ENG_VER" ]; then
if [ "$DOCS_SSH" ]; then
ssh -v -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null [email protected] "bash -cx 'cd \"${DOCS_BASE}oq-engine/\"; ln -snf \"$ENG_VER\" latest'"
else
echo "SKIP create latest link"
fi
fi
fi