cibuild.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. CONFIG="netbox/netbox/configuration.py"
  33. ln -s netbox/netbox/configuration.testing.py $CONFIG
  34. # Run NetBox tests
  35. coverage run --source="netbox/" netbox/manage.py test netbox/
  36. RC=$?
  37. if [[ $RC != 0 ]]; then
  38. echo -e "\n$(info) one or more tests failed, failing build."
  39. EXIT=$RC
  40. fi
  41. # Show code coverage report
  42. coverage report --skip-covered --omit *migrations*
  43. RC=$?
  44. if [[ $RC != 0 ]]; then
  45. echo -e "\n$(info) failed to generate code coverage report."
  46. EXIT=$RC
  47. fi
  48. # Show build duration
  49. END=$(date +%s)
  50. echo "$(info) exiting with code $EXIT after $(($END - $START)) seconds."
  51. exit $EXIT