From 2e7c00aa37f464b263224c62da6078c608665c99 Mon Sep 17 00:00:00 2001 From: Zahari Dichev Date: Tue, 18 Aug 2020 11:44:33 +0300 Subject: [PATCH] Diff generated code from proto files (#4863) Add a static check that ensures the generated files from the proto definitions have not changed. Fix #4669 Signed-off-by: Zahari Dichev --- .github/workflows/static_checks.yml | 11 +++++++++++ bin/protoc-diff | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100755 bin/protoc-diff diff --git a/.github/workflows/static_checks.yml b/.github/workflows/static_checks.yml index 4d9dee668..1bfc23277 100644 --- a/.github/workflows/static_checks.yml +++ b/.github/workflows/static_checks.yml @@ -30,6 +30,17 @@ jobs: uses: actions/checkout@722adc6 - name: Format run: bin/fmt + proto_diff: + name: Proto diff + runs-on: ubuntu-18.04 + container: + image: golang:1.13.4 + steps: + - name: Checkout code + # actions/checkout@v2 + uses: actions/checkout@722adc6 + - name: Diff proto files + run: bin/protoc-diff shellcheck: name: shellcheck runs-on: ubuntu-18.04 diff --git a/bin/protoc-diff b/bin/protoc-diff new file mode 100755 index 000000000..e75a0a8e0 --- /dev/null +++ b/bin/protoc-diff @@ -0,0 +1,22 @@ +#!/usr/bin/env sh + +set -eu + +# Install unzip if not already installed (Linux only) +system=$(uname -s) +if [ "$system" = Linux ] && ! [ -x "$(command -v unzip)" ]; then + apt-get update + apt-get install unzip +fi + +bin/protoc-go.sh + +dir_dirty=$(git diff HEAD) +if [ -z "$dir_dirty" ]; then + echo "Protobuf definitions match generated code" + exit 0 +else + echo "Protobuf definitions diverge from generated code:" + echo "$(git status)" + exit 64 +fi