about summary refs log tree commit diff
path: root/nix/bufCheck/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nix/bufCheck/default.nix')
-rw-r--r--nix/bufCheck/default.nix22
1 files changed, 22 insertions, 0 deletions
diff --git a/nix/bufCheck/default.nix b/nix/bufCheck/default.nix
new file mode 100644
index 000000000000..f247e6839eee
--- /dev/null
+++ b/nix/bufCheck/default.nix
@@ -0,0 +1,22 @@
+# Check protobuf syntax and breaking.
+#
+{ depot, pkgs, ... }:
+
+pkgs.writeShellScriptBin "ci-buf-check" ''
+  export PATH="$PATH:${pkgs.lib.makeBinPath [ pkgs.buf pkgs.protoc-gen-go pkgs.protoc-gen-go-grpc ]}"
+  (cd $(git rev-parse --show-toplevel) && buf lint .)
+
+  # Run buf generate, and bail out if generated files are changed.
+  (cd $(git rev-parse --show-toplevel) && buf generate --path tvix/store/protos)
+  # Check if any files have changed
+  if [[ -n "$(git status --porcelain -unormal)" ]]; then
+      echo "-----------------------------"
+      echo ".pb.go files need to be updated"
+      echo "-----------------------------"
+      git status -unormal
+      exit 1
+  fi
+
+  # Report-only
+  (cd $(git rev-parse --show-toplevel) && (buf breaking . --against "./.git#ref=HEAD~1" || true))
+''