Mark staging go module files as generated, add script to lint dependencies

This commit is contained in:
Jordan Liggitt
2019-04-05 09:57:31 -04:00
parent 20cece67b5
commit fdd241a858
3 changed files with 97 additions and 1 deletions

View File

@@ -35,7 +35,7 @@ export GOPATH=
export GOFLAGS=
# Detect problematic GOPROXY settings that prevent lookup of dependencies
if [[ "${GOPROXY:-}" == "off" ]]; then
kube::log::error "Cannot run hack/pin-dependency.sh with \$GOPROXY=off"
kube::log::error "Cannot run with \$GOPROXY=off"
exit 1
fi
@@ -54,12 +54,37 @@ if [[ -z "${dep}" || -z "${sha}" ]]; then
exit 1
fi
_tmp="${KUBE_ROOT}/_tmp"
cleanup() {
rm -rf "${_tmp}"
}
trap "cleanup" EXIT SIGINT
cleanup
mkdir -p "${_tmp}"
# Add the require directive
echo "Running: go get ${dep}@${sha}"
go get -d "${dep}@${sha}"
# Find the resolved version
rev=$(go mod edit -json | jq -r ".Require[] | select(.Path == \"${dep}\") | .Version")
# No entry in go.mod, we must be using the natural version indirectly
if [[ -z "${rev}" ]]; then
# backup the go.mod file, since go list modifies it
cp go.mod "${_tmp}/go.mod.bak"
# find the revision
rev=$(go list -m -json "${dep}" | jq -r .Version)
# restore the go.mod file
mv "${_tmp}/go.mod.bak" go.mod
fi
# No entry found
if [[ -z "${rev}" ]]; then
echo "Could not resolve ${sha}"
exit 1
fi
echo "Resolved to ${dep}@${rev}"
# Add the replace directive