verify-bundles.sh 1.2 KB

1234567891011121314151617181920212223242526272829
  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, added, or deleted files. Because bundle output should not change given
  4. # the same source input, the bundle process shouldn't produce any changes. If it does, it's an
  5. # indication that the dist files have been altered, or that dist files were not committed. In
  6. # either case, tests should fail.
  7. set -euo pipefail
  8. cd "$(dirname "$0")/../netbox/project-static"
  9. echo "Bundling static assets..."
  10. if ! npm run --silent build; then
  11. echo "Error bundling static assets"
  12. exit 1
  13. fi
  14. # See if any files have been changed, deleted, or added. Compare against the index rather than HEAD,
  15. # so that changes already staged for commit pass when this runs as a pre-commit hook.
  16. changes="$(git diff --name-status -- dist; git ls-files --others --exclude-standard -- dist | awk '{ print "?\t" $0 }')"
  17. if [[ -n "$changes" ]]; then
  18. echo "$changes"
  19. echo "The static assets in dist/ do not match a fresh build of the current source files"
  20. echo "Run 'npm run build' in netbox/project-static/ and commit the contents of dist/"
  21. exit 1
  22. fi
  23. echo "Static asset check passed"