From 4c23a9c1d494d666ac82ab6e1d0ab0961e41bbad Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 19 Dec 2021 21:12:32 +0300 Subject: feat(depotfmt): run formatting checks in CI 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 Reviewed-by: tazjin Tested-by: BuildkiteCI Autosubmit: tazjin --- tools/depotfmt.nix | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'tools/depotfmt.nix') diff --git a/tools/depotfmt.nix b/tools/depotfmt.nix index 8a72149203..d1a1cb425a 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; } -- cgit 1.4.1