clean_go_build_cache.sh 548 B

12345678910111213141516171819
  1. #!/bin/sh
  2. # Cleaning the Go cache only makes sense if we actually have Go installed... or
  3. # if Go is actually callable. This does not hold true during deb packaging, so
  4. # we need an explicit check to avoid build failures.
  5. if ! command -v go > /dev/null; then
  6. exit
  7. fi
  8. version_gt() {
  9. test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"
  10. }
  11. golang_version=$(go version |cut -d' ' -f3 |sed 's/go//')
  12. # Clean go build cache when go version is greater than or equal to 1.10
  13. if !(version_gt 1.10 $golang_version); then
  14. go clean -cache
  15. fi