-
Notifications
You must be signed in to change notification settings - Fork 156
67 lines (55 loc) · 1.94 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
name: Check Examples APIs
on: [push, pull_request]
jobs:
examples-check:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
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.
# Copy the examples to a new directory outside of the repo to ensure that there is no
# reliance on the repo directory structure.
run: |
mkdir -p temp1/temp2/temp3
cp -r examples/ temp1/temp2/temp3/.
cd temp1/temp2/temp3/examples/
error_found=0 # 0 is false
error_results="Error in example:"
# Now run the examples in root and subdirectories
echo "Running examples"
for d in . $(find . -type d -name "*examples*"); do
cd $d
echo "========================= Example directory- $d"
for i in *.py; do
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Running example- $i"
# If "convert_examples" is in i, skip this script
if [[ $i == *"convert_examples"* ]]; then
continue
fi
if ! python $i; then
error_results="${error_results}"$'\n'" - ${i}"
error_found=1
fi
done
if [ "$d" != "." ]; then
cd ..
fi
done
if [[ $error_found ]]; then
echo "${error_results}"
fi
exit $error_found