Import buildifier

This patch sets up buildifier to run as part of CI. It can also be run
manually via `//tools/lint:buildifier`.

As a consequence, I needed to make the whole repo conform.

Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
Change-Id: Ic41c97b17255813b6c21aef40ab2f8a216683a2c
diff --git a/tools/go/mirror_go_repos.py b/tools/go/mirror_go_repos.py
index dc160fa..52e9e26 100644
--- a/tools/go/mirror_go_repos.py
+++ b/tools/go/mirror_go_repos.py
@@ -16,7 +16,10 @@
 from typing import List, Dict
 import urllib.request
 
-import tools.go.mirror_lib
+from bazel_tools.tools.python.runfiles import runfiles
+
+# Need a fully qualified import here because @bazel_tools interferes.
+import org_frc971.tools.go.mirror_lib
 
 GO_DEPS_WWWW_DIR = "/var/www/html/files/frc971/Build-Dependencies/go_deps"
 
@@ -111,7 +114,7 @@
 
     os.chdir(os.environ["BUILD_WORKSPACE_DIRECTORY"])
 
-    repos = tools.go.mirror_lib.parse_go_repositories(args.go_deps_bzl)
+    repos = org_frc971.tools.go.mirror_lib.parse_go_repositories(args.go_deps_bzl)
 
     if args.ssh_host:
         existing_mirrored_repos = get_existing_mirrored_repos(args.ssh_host)
@@ -136,9 +139,20 @@
     with open(args.go_mirrors_bzl, "w") as file:
         file.write("# This file is auto-generated. Do not edit.\n")
         file.write("GO_MIRROR_INFO = ")
-        json.dump(cached_info, file, indent=2, sort_keys=True)
+        # Format as JSON first. It's parsable as Starlark.
+        json.dump(cached_info, file, indent=4, sort_keys=True)
         file.write("\n")
 
 
+    # Properly format the file now so that the linter doesn't complain.
+    r = runfiles.Create()
+    subprocess.run(
+        [
+            r.Rlocation("com_github_bazelbuild_buildtools/buildifier/buildifier_/buildifier"),
+            args.go_mirrors_bzl,
+        ],
+        check=True)
+
+
 if __name__ == "__main__":
     sys.exit(main(sys.argv))