vendor 987 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env bash
  2. set -eu
  3. TYP=$1
  4. usage() {
  5. echo "usage: ./scripts/vendor <init|update|validate|outdated>"
  6. exit 1
  7. }
  8. if [ -z "$TYP" ]; then
  9. usage
  10. fi
  11. update() {
  12. (set -x ; go mod tidy -modfile=vendor.mod; go mod vendor -modfile=vendor.mod)
  13. }
  14. validate() {
  15. diff=$(git status --porcelain -- vendor.mod vendor.sum vendor)
  16. if [ -n "$diff" ]; then
  17. echo >&2 'ERROR: Vendor result differs. Vendor your package with "make -f docker.Makefile vendor"'
  18. echo "$diff"
  19. exit 1
  20. fi
  21. }
  22. outdated() {
  23. if [ ! -x "$(command -v go-mod-outdated)" ]; then
  24. echo "go-mod-outdated not found. Install with 'go install github.com/psampaz/go-mod-outdated@v0.8.0'"
  25. exit 1
  26. fi
  27. (set -x ; go list -mod=vendor -mod=readonly -modfile=vendor.mod -u -m -json all | go-mod-outdated -update -direct)
  28. }
  29. case $TYP in
  30. "update")
  31. update
  32. ;;
  33. "validate")
  34. update
  35. validate
  36. ;;
  37. "outdated")
  38. outdated
  39. ;;
  40. *)
  41. echo >&2 "Unknown type $TYP"
  42. exit 1
  43. ;;
  44. esac