with-go-mod.sh 924 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env bash
  2. #
  3. # This script is used to coerce certain commands which rely on the presence of
  4. # a go.mod into working with our repository. It works by creating a fake
  5. # go.mod, running a specified command (passed via arguments), and removing it
  6. # when the command is finished. This script should be dropped when this
  7. # repository is a proper Go module with a permanent go.mod.
  8. set -e
  9. SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  10. ROOTDIR="$(git -C "$SCRIPTDIR" rev-parse --show-toplevel)"
  11. if test -e "${ROOTDIR}/go.mod"; then
  12. {
  13. scriptname=$(basename "$0")
  14. echo "${scriptname}: WARN: go.mod exists in the repository root!"
  15. echo "${scriptname}: WARN: Using your go.mod instead of our generated version -- this may misbehave!"
  16. } >&2
  17. else
  18. set -x
  19. tee "${ROOTDIR}/go.mod" >&2 <<- EOF
  20. module github.com/docker/docker
  21. go 1.19
  22. EOF
  23. trap 'rm -f "${ROOTDIR}/go.mod"' EXIT
  24. fi
  25. GO111MODULE=on "$@"