Skip to content

Merge branch 'develop' into parallel-model-rework #1867

Merge branch 'develop' into parallel-model-rework

Merge branch 'develop' into parallel-model-rework #1867

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"]
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