diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bcc2a6288662..7d9ba7d8ed98 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -72,6 +72,11 @@ repos: description: "Runs `golangci-lint`, install https://github.com/golangci/golangci-lint" exclude: ^(proto/pkg|hpc-ard-launcher-go/launcher/) require_serial: true + - id: lock-api-state + name: "Generate buf image (lock-api-state.sh)" + entry: ./pre-commit/lock-api-state.sh + language: "script" + description: "Attempts to generate a new buf.image.bin, and fails if there are changes to commit." - repo: https://github.com/adrienverge/yamllint.git rev: v1.28.0 diff --git a/pre-commit/lock-api-state.sh b/pre-commit/lock-api-state.sh new file mode 100755 index 000000000000..a526c0069ba2 --- /dev/null +++ b/pre-commit/lock-api-state.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +# Regenerate proto/buf.image.bin +make -C proto gen-buf-image + +# If proto/buf.image.bin has been modified locally, then we have changes to +# commit, and the status check returns a 1 and fails. Otherwise, it returns a 0 +# and succeeds. +git diff --exit-code -- proto/buf.image.bin +exit $?