about summary refs log tree commit diff
path: root/tools
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2021-12-19T18·12+0300
committertazjin <mail@tazj.in>2021-12-24T19·26+0000
commit4c23a9c1d494d666ac82ab6e1d0ab0961e41bbad (patch)
treebe0ab2230d4144a18bd2a3e9b93a2e6529b53937 /tools
parent9c61d64a11439b217fb86cd966501a079cb8b7f7 (diff)
feat(depotfmt): run formatting checks in CI r/3371
Right now this only includes Go, but more is to come.

Change-Id: Idd8fc27c0eb25e82688ef8337ba20810d834f4b6
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4504
Reviewed-by: zseri <zseri.devel@ytrizja.de>
Reviewed-by: tazjin <mail@tazj.in>
Tested-by: BuildkiteCI
Autosubmit: tazjin <mail@tazj.in>
Diffstat (limited to 'tools')
-rw-r--r--tools/depotfmt.nix25
1 files changed, 19 insertions, 6 deletions
diff --git a/tools/depotfmt.nix b/tools/depotfmt.nix
index 8a721492037e..d1a1cb425ae3 100644
--- a/tools/depotfmt.nix
+++ b/tools/depotfmt.nix
@@ -1,6 +1,6 @@
 # Builds treefmt for depot, with a hardcoded configuration that
 # includes the right paths to formatters.
-{ pkgs, ... }:
+{ depot, pkgs, ... }:
 
 let
   config = pkgs.writeText "depot-treefmt-config" ''
@@ -14,8 +14,21 @@ let
     options = [ "fmt" ]
     includes = [ "*.tf" ]
   '';
-in pkgs.writeShellScriptBin "depotfmt" ''
-  exec ${pkgs.treefmt}/bin/treefmt ''${@} \
-    --config-file ${config} \
-    --tree-root $(${pkgs.git}/bin/git rev-parse --show-toplevel)
-''
+
+  # helper tool for formatting the depot interactively
+  depotfmt = pkgs.writeShellScriptBin "depotfmt" ''
+    exec ${pkgs.treefmt}/bin/treefmt ''${@} \
+      --config-file ${config} \
+      --tree-root $(${pkgs.git}/bin/git rev-parse --show-toplevel)
+  '';
+
+  # wrapper for running formatting checks in CI
+  check = pkgs.runCommandNoCC "depotfmt-check" {} ''
+    ${pkgs.git}/bin/git clone ${depot.path.origSrc} depot
+    export HOME="$(${pkgs.coreutils}/bin/realpath .)"
+    ${pkgs.treefmt}/bin/treefmt \
+      --fail-on-change \
+      --config-file ${config} \
+      --tree-root depot && : > $out
+  '';
+in depotfmt // depot.nix.readTree.drvTargets { inherit check; }