validate_modified_files.sh 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env -S bash
  2. set -ex
  3. #############
  4. # VARIABLES #
  5. #############
  6. CODEGEN_ERR="found codegen files! please run 'make codegen' and update your PR"
  7. MOD_ERR="changes found by mod.check. You may need to run make clean"
  8. CRD_ERR="changes found by 'make crds'. please run 'make crds' locally and update your PR"
  9. BUILD_ERR="changes found by make build', please commit your go.sum or other changed files"
  10. HELM_ERR="changes found by 'make gen-rbac'. please run 'make gen-rbac' locally and update your PR"
  11. #############
  12. # FUNCTIONS #
  13. #############
  14. function validate(){
  15. git=$(git status --porcelain)
  16. for file in $git; do
  17. if [ -n "$file" ]; then
  18. echo "$1"
  19. echo "$git"
  20. git diff
  21. exit 1
  22. fi
  23. done
  24. }
  25. ########
  26. # MAIN #
  27. ########
  28. case "$1" in
  29. codegen)
  30. validate "$CODEGEN_ERR"
  31. ;;
  32. modcheck)
  33. validate "$MOD_ERR"
  34. ;;
  35. crd)
  36. validate "$CRD_ERR"
  37. ;;
  38. build)
  39. validate "$BUILD_ERR"
  40. ;;
  41. gen-rbac)
  42. validate "$HELM_ERR"
  43. ;;
  44. *)
  45. echo $"Usage: $0 {codegen|modcheck|crd|build|gen-rbac}"
  46. exit 1
  47. esac