Produces more useful output and also makes for a good target for the upcoming extraSteps logic. Change-Id: Ifd389d433d9e27f97940a48999f4fba35646e37a Reviewed-on: https://cl.tvl.fyi/c/depot/+/4727 Tested-by: BuildkiteCI Autosubmit: tazjin <mail@tazj.in> Reviewed-by: sterni <sternenseemann@systemli.org>
		
			
				
	
	
		
			39 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			Nix
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			Nix
		
	
	
	
	
	
| # Builds treefmt for depot, with a hardcoded configuration that
 | |
| # includes the right paths to formatters.
 | |
| { depot, pkgs, ... }:
 | |
| 
 | |
| let
 | |
|   # terraform fmt can't handle multiple paths at once, but treefmt
 | |
|   # expects this
 | |
|   terraformat = pkgs.writeShellScript "terraformat" ''
 | |
|     echo "$@" | xargs -n1 ${pkgs.terraform}/bin/terraform fmt
 | |
|   '';
 | |
| 
 | |
|   config = pkgs.writeText "depot-treefmt-config" ''
 | |
|     [formatter.go]
 | |
|     command = "${pkgs.go}/bin/gofmt"
 | |
|     options = [ "-w" ]
 | |
|     includes = ["*.go"]
 | |
| 
 | |
|     [formatter.tf]
 | |
|     command = "${terraformat}"
 | |
|     includes = [ "*.tf" ]
 | |
|   '';
 | |
| 
 | |
|   # 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 script for running formatting checks in CI
 | |
|   check = pkgs.writeShellScript "depotfmt-check" ''
 | |
|     ${pkgs.treefmt}/bin/treefmt \
 | |
|       --fail-on-change \
 | |
|       --config-file ${config} \
 | |
|       --tree-root .
 | |
|   '';
 | |
| in depotfmt.overrideAttrs(_: {
 | |
|   passthru.check = check;
 | |
| })
 |