Skip to content

Commit

Permalink
build: check_deps.sh uses go mod tidy
Browse files Browse the repository at this point in the history
There aren't a lot of good options to ensure that the vendor tree
remains in sync with the module requirements in `go.mod` but we can at
least try to ensure that go.mod is not importing things that aren't used
and that we are including things that we should.

Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
  • Loading branch information
sykesm committed Apr 15, 2020
1 parent a6c1ff7 commit 756a133
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion scripts/check_deps.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
#!/bin/bash -e
#!/bin/bash

# Copyright IBM Corp All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0

set -euo pipefail

# create temporary directory for go.mod and clean it
# up when the script exists.
dep_tempdir="$(mktemp -d "$(basename "$0")"-XXXXX)"
trap 'rm -rf "$dep_tempdir"' EXIT

# copy go.mod and go.sum to the temporary directory we created
fabric_dir="$(cd "$(dirname "$0")/.." && pwd)"
cp "${fabric_dir}/go.mod" "${dep_tempdir}/"
cp "${fabric_dir}/go.sum" "${dep_tempdir}/"

# check if we have unused requirements
go mod tidy -modfile="${dep_tempdir}/go.mod"

for f in go.mod go.sum; do
if ! diff -q "${fabric_dir}/$f" "${dep_tempdir}/$f"; then
echo "It appears $f is stale. Please run 'go mod tidy' and 'go mod vendor'."
diff -u "${fabric_dir}/$f" "${dep_tempdir}/$f"
exit 1
fi
done

0 comments on commit 756a133

Please sign in to comment.