cibuild.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/bash
  2. # Exit code starts at 0 but is modified if any checks fail
  3. EXIT=0
  4. # Output a line prefixed with a timestamp
  5. info()
  6. {
  7. echo "$(date +'%F %T') |"
  8. }
  9. # Track number of seconds required to run script
  10. START=$(date +%s)
  11. echo "$(info) starting build checks."
  12. # Syntax check all python source files
  13. SYNTAX=$(find . -name "*.py" -type f -exec python -m py_compile {} \; 2>&1)
  14. if [[ ! -z $SYNTAX ]]; then
  15. echo -e "$SYNTAX"
  16. echo -e "\n$(info) detected one or more syntax errors, failing build."
  17. EXIT=1
  18. fi
  19. # Check all python source files for PEP 8 compliance, but explicitly
  20. # ignore:
  21. # - W504: line break after binary operator
  22. # - E501: line greater than 80 characters in length
  23. pycodestyle \
  24. --ignore=W504,E501 \
  25. netbox/
  26. RC=$?
  27. if [[ $RC != 0 ]]; then
  28. echo -e "\n$(info) one or more PEP 8 errors detected, failing build."
  29. EXIT=$RC
  30. fi
  31. # Point to the testing configuration file for use in CI
  32. ln -s configuration.testing.py netbox/netbox/configuration.py
  33. # Run NetBox tests
  34. coverage run --source="netbox/" netbox/manage.py test netbox/
  35. RC=$?
  36. if [[ $RC != 0 ]]; then
  37. echo -e "\n$(info) one or more tests failed, failing build."
  38. EXIT=$RC
  39. fi
  40. # Show code coverage report
  41. coverage report --skip-covered --omit *migrations*
  42. RC=$?
  43. if [[ $RC != 0 ]]; then
  44. echo -e "\n$(info) failed to generate code coverage report."
  45. EXIT=$RC
  46. fi
  47. # Show build duration
  48. END=$(date +%s)
  49. echo "$(info) exiting with code $EXIT after $(($END - $START)) seconds."
  50. exit $EXIT