cibuild.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. # - E501: line greater than 80 characters in length
  22. pep8 --ignore=E501 netbox/
  23. RC=$?
  24. if [[ $RC != 0 ]]; then
  25. echo -e "\n$(info) one or more PEP 8 errors detected, failing build."
  26. EXIT=$RC
  27. fi
  28. # Prepare configuration file for use in CI
  29. CONFIG="netbox/netbox/configuration.py"
  30. cp netbox/netbox/configuration.example.py $CONFIG
  31. sed -i -e "s/ALLOWED_HOSTS = \[\]/ALLOWED_HOSTS = \['*'\]/g" $CONFIG
  32. sed -i -e "s/SECRET_KEY = ''/SECRET_KEY = 'netboxci'/g" $CONFIG
  33. # Run NetBox tests
  34. ./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 build duration
  41. END=$(date +%s)
  42. echo "$(info) exiting with code $EXIT after $(($END - $START)) seconds."
  43. exit $EXIT