verify-bundles.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env bash
  2. # This script verifies the integrity of *bundled* static assets by re-running the bundling process
  3. # and checking for changed files. Because bundle output should not change given the same source
  4. # input, the bundle process shouldn't produce any changes. If they do, it's an indication that
  5. # the dist files have been altered, or that dist files were not committed. In either case, tests
  6. # should fail.
  7. PROJECT_STATIC="$PWD/netbox/project-static"
  8. DIST="$PROJECT_STATIC/dist/"
  9. # Bundle static assets.
  10. bundle() {
  11. echo "Bundling static assets..."
  12. yarn --cwd $PROJECT_STATIC bundle >/dev/null 2>&1
  13. if [[ $? != 0 ]]; then
  14. echo "Error bundling static assets"
  15. exit 1
  16. fi
  17. }
  18. # See if any files have changed.
  19. check_dist() {
  20. local diff=$(git --no-pager diff $DIST)
  21. if [[ $diff != "" ]]; then
  22. local SHA=$(git rev-parse HEAD)
  23. echo "Commit '$SHA' produced different static assets than were committed"
  24. echo $diff
  25. echo $(git diff $DIST)
  26. exit 1
  27. fi
  28. }
  29. bundle
  30. check_dist
  31. if [[ $? = 0 ]]; then
  32. echo "Static asset check passed"
  33. exit 0
  34. else
  35. echo "Error checking static asset integrity"
  36. exit 1
  37. fi