From 21977f91c8ede350b6a58633b11c09bb94198e62 Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Fri, 10 Jun 2022 11:29:54 -0700 Subject: ci(fmt): add a script to check the formatting Add a script for CI to check that all the files are formatted correctly. This is done by using `treefmt' with a configuration for go and nix files (for now). Running `nix run .#ci.fmt' in the repository will check all the files, and fail if there's any problems. It will not modify any files. The pipeline in builKite needs to be updated to run that command. Change-Id: Iec91163f1ab56ceb0cfff6db8f8ce93367ebeefe Reviewed-on: https://cl.fcuny.net/c/world/+/403 Tested-by: CI Reviewed-by: Franck Cuny --- ops/ci/fmt.nix | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 ops/ci/fmt.nix (limited to 'ops/ci') diff --git a/ops/ci/fmt.nix b/ops/ci/fmt.nix new file mode 100644 index 0000000..a3d697c --- /dev/null +++ b/ops/ci/fmt.nix @@ -0,0 +1,27 @@ +{ pkgs, ... }: +let + config = pkgs.writeText "depot-treefmt-config" '' + [formatter.go] + command = "${pkgs.go}/bin/gofmt" + includes = ["*.go"] + + [formatter.nix] + command = "${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt" + options = [ "--check"] + includes = [ "*.nix" ] + ''; +in +rec { + mkFmtScript = src: + let + script = pkgs.writeScript "format" '' + set -euo pipefail + ROOT=$(${pkgs.git}/bin/git rev-parse --show-toplevel) + ${pkgs.treefmt}/bin/treefmt --clear-cache --fail-on-change --config-file ${config} --tree-root $ROOT + ''; + in + { + type = "app"; + program = "${script}"; + }; +} -- cgit 1.4.1