cibuild.sh 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. # Prepare configuration file for use in CI
  20. CONFIG="netbox/netbox/configuration.py"
  21. cp netbox/netbox/configuration.example.py $CONFIG
  22. sed -i -e "s/ALLOWED_HOSTS = \[\]/ALLOWED_HOSTS = \['*'\]/g" $CONFIG
  23. sed -i -e "s/SECRET_KEY = ''/SECRET_KEY = 'netboxci'/g" $CONFIG
  24. # Run NetBox tests
  25. ./netbox/manage.py test netbox/
  26. RC=$?
  27. if [[ $RC != 0 ]]; then
  28. echo -e "\n$(info) one or more tests failed, failing build."
  29. EXIT=$RC
  30. fi
  31. # Show build duration
  32. END=$(date +%s)
  33. echo "$(info) exiting with code $EXIT after $(($END - $START)) seconds."
  34. exit $EXIT