test_startup.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. run() {
  4. pwd
  5. output=$({ timeout 10 ./"$1" "${@:2}"; } 2>&1)
  6. exitcode=$?
  7. [[ $exitcode -eq 124 ]] && exitcode=0 # exitcode 124 is coming from "timeout command above"
  8. echo "$output" | grep -qE "NiceGUI ready to go|Uvicorn running on http://127.0.0.1:8000" || exitcode=1
  9. echo "$output" | grep -qE "Traceback|Error" && exitcode=1
  10. if [[ $exitcode -ne 0 ]]; then
  11. echo "Wrong exit code $exitcode. Output was:"
  12. echo "$output"
  13. return 1
  14. fi
  15. }
  16. check() {
  17. echo "Checking $1 ----------"
  18. pushd "$(dirname "$1")" >/dev/null
  19. max_attempts=3
  20. for attempt in $(seq 1 $max_attempts); do
  21. if run "$(basename "$1")" "${@:2}"; then
  22. echo "OK --------"
  23. popd > /dev/null
  24. return 0
  25. elif [ $attempt -eq $max_attempts ]; then
  26. echo "FAILED after $max_attempts attempts -------"
  27. popd > /dev/null
  28. return 1
  29. else
  30. echo "Attempt $attempt failed. Retrying..."
  31. fi
  32. done
  33. }
  34. check main.py || exit 1
  35. for path in examples/*
  36. do
  37. # Skip examples/generate_pdf
  38. if [[ $path == "examples/generate_pdf" ]]; then
  39. continue # until https://github.com/pygobject/pycairo/issues/387 is fixed
  40. fi
  41. # Skip examples/sqlite_database for Python 3.11 and 3.12
  42. if [[ $(python3 --version | cut -d' ' -f2 | cut -d'.' -f1,2) =~ ^3.1[12]$ ]] && [[ $path == "examples/sqlite_database" ]]; then
  43. continue # until https://github.com/omnilib/aiosqlite/issues/241 is fixed
  44. fi
  45. # skip if path is examples/pyserial
  46. if test $path = "examples/pyserial"; then
  47. continue # because there is no serial port in github actions
  48. fi
  49. # install all requirements except nicegui
  50. if test -f $path/requirements.txt; then
  51. sed '/^nicegui/d' $path/requirements.txt > $path/requirements.tmp.txt || exit 1 # remove nicegui from requirements.txt
  52. python3 -m pip install -r $path/requirements.tmp.txt || exit 1
  53. rm $path/requirements.tmp.txt || exit 1
  54. fi
  55. # run start.sh or main.py
  56. if test -f $path/start.sh; then
  57. check $path/start.sh dev || exit 1
  58. elif test -f $path/main.py; then
  59. check $path/main.py || exit 1
  60. fi
  61. if pytest -q --collect-only $path >/dev/null 2>&1; then
  62. echo "running tests for $path"
  63. pytest $path || exit 1
  64. fi
  65. done
  66. exit 0