Automatically prune unused Go dependencies
The way gazelle was set up meant that it would never prune any
dependencies from go_deps.bzl. I'm not exactly sure _why_, but that's
the way it behaved.
The new approach here in this patch is to essentially null out
go_deps.bzl and have gazelle regenerate it from scratch.
Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
Change-Id: Ic94020df816afa0df798b19b16b11272579793be
diff --git a/tools/lint/run-ci.sh b/tools/lint/run-ci.sh
index 6228552..32f110a 100755
--- a/tools/lint/run-ci.sh
+++ b/tools/lint/run-ci.sh
@@ -34,6 +34,12 @@
}
update_repos() {
+ # Clear out the go_deps.bzl file so that gazelle won't hesitate to update
+ # it. Without this step gazelle would never try to remove a dependency.
+ cat > "${BUILD_WORKSPACE_DIRECTORY}"/go_deps.bzl <<EOF
+def go_dependencies():
+ pass
+EOF
./gazelle-runner.bash update-repos \
-from_file=go.mod \
-to_macro=go_deps.bzl%go_dependencies \
@@ -50,6 +56,10 @@
"${tweaker}" ./go_deps.bzl
}
+clean_up_go_mirrors() {
+ ./tools/go/mirror_go_repos --prune
+}
+
buildifier() {
./tools/lint/buildifier
}
@@ -69,6 +79,7 @@
update_repos
gazelle
tweak_gazelle_go_deps
+ clean_up_go_mirrors
buildifier
git_status_is_clean # This must the last linter.
)