-
Notifications
You must be signed in to change notification settings - Fork 157
76 lines (61 loc) · 2.09 KB
/
check-working-examples.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
name: Check Examples APIs
on: [push, pull_request]
jobs:
examples-check:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.10"]
os: [ubuntu-latest] #, macos-latest, windows-latest]
fail-fast: False
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install project
run: |
python -m pip install --upgrade pip
pip install -e .
pip install nbconvert # For converting Jupyter notebook to python script in the next step
- name: Run examples
# Run all examples and test that they finish successfully. Do not evaluate the results.
run: |
cd examples/
error_found=0 # 0 is false
error_results="Error in example:"
# Run each Python script example
for i in *.py; do
# Skip these examples since they have additional dependencies
if [[ $i == *15* ]]; then
continue
fi
if [[ $i == *19* ]]; then
continue
fi
if ! python $i; then
error_results="${error_results}"$'\n'" - ${i}"
error_found=1
fi
done
# Run all Jupyter notebooks
for i in *.ipynb; do
# Convert this notebook to a Python script
if ! jupyter nbconvert --to script $i; then
# On conversion error, report and go to the next notebook
error_results="${error_results}"$'\n'" - Error converting ${i} to Python script"
continue
fi
# Get the basename of the notebook since the converted script will have the same basename
script_name=`basename $i .ipynb`
# Run the converted script
if ! python "${script_name}.py"; then
error_results="${error_results}"$'\n'" - ${i}"
error_found=1
fi
done
if [[ $error_found ]]; then
echo "${error_results}"
fi
exit $error_found