verify-bundles.sh 1.1 KB

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