with-go-mod.sh 931 B

123456789101112131415161718192021222324252627282930313233
  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="$(cd "${SCRIPTDIR}/.." && pwd)"
  11. if test -e "${ROOTDIR}/go.mod"; then
  12. {
  13. scriptname=$(basename "$0")
  14. cat >&2 <<- EOF
  15. $scriptname: WARN: go.mod exists in the repository root!
  16. $scriptname: WARN: Using your go.mod instead of our generated version -- this may misbehave!
  17. EOF
  18. } >&2
  19. else
  20. set -x
  21. tee "${ROOTDIR}/go.mod" >&2 <<- EOF
  22. module github.com/docker/cli
  23. go 1.23.0
  24. EOF
  25. trap 'rm -f "${ROOTDIR}/go.mod"' EXIT
  26. fi
  27. GO111MODULE=on GOTOOLCHAIN=local "$@"