github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/scripts/check_deps.sh (about) 1 #!/bin/bash 2 3 # Copyright hechain All Rights Reserved. 4 # 5 # SPDX-License-Identifier: Apache-2.0 6 7 set -euo pipefail 8 9 # create temporary directory for go.mod and clean it 10 # up when the script exists. 11 dep_tempdir="$(mktemp -d "$(basename "$0")"-XXXXX)" 12 trap 'rm -rf "$dep_tempdir"' EXIT 13 14 # copy go.mod and go.sum to the temporary directory we created 15 fabric_dir="$(cd "$(dirname "$0")/.." && pwd)" 16 cp "${fabric_dir}/go.mod" "${dep_tempdir}/" 17 cp "${fabric_dir}/go.sum" "${dep_tempdir}/" 18 19 # check if we have unused requirements 20 go mod tidy -modfile="${dep_tempdir}/go.mod" 21 22 for f in go.mod go.sum; do 23 if ! diff -q "${fabric_dir}/$f" "${dep_tempdir}/$f"; then 24 echo "It appears $f is stale. Please run 'go mod tidy' and 'go mod vendor'." 25 diff -u "${fabric_dir}/$f" "${dep_tempdir}/$f" 26 exit 1 27 fi 28 done