2
0

verify-bundles.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. exit 1
  25. fi
  26. }
  27. bundle
  28. check_dist
  29. if [[ $? = 0 ]]; then
  30. echo "Static asset check passed"
  31. exit 0
  32. else
  33. echo "Error checking static asset integrity"
  34. exit 1
  35. fi