ci: Add check for protobuf formatting (#50418)

Finn Evers and Anthony Eid created

This adds more checks for the protobuf files to CI

Release Notes:

- N/A

---------

Co-authored-by: Anthony Eid <anthony@zed.dev>

Change summary

.github/workflows/run_tests.yml                |  4 ++++
crates/proto/proto/buf.yaml                    | 10 ++++++++++
script/clippy                                  |  4 ++++
tooling/xtask/src/tasks/workflows/run_tests.rs | 12 +++++++++++-
4 files changed, 29 insertions(+), 1 deletion(-)

Detailed changes

.github/workflows/run_tests.yml 🔗

@@ -700,6 +700,10 @@ jobs:
       with:
         input: crates/proto/proto/
         against: https://github.com/${GITHUB_REPOSITORY}.git#branch=${BUF_BASE_BRANCH},subdir=crates/proto/proto/
+    - name: run_tests::check_postgres_and_protobuf_migrations::buf_lint
+      run: buf lint crates/proto/proto
+    - name: run_tests::check_postgres_and_protobuf_migrations::check_protobuf_formatting
+      run: buf format --diff --exit-code crates/proto/proto
     timeout-minutes: 60
   tests_pass:
     needs:

crates/proto/proto/buf.yaml 🔗

@@ -2,3 +2,13 @@ version: v1
 breaking:
   use:
     - WIRE
+lint:
+  except:
+    # Since we use post_build instead of buf this doesn't matter
+    - PACKAGE_DIRECTORY_MATCH
+    # This is internal to Zed only so we don't enforce versions
+    - PACKAGE_VERSION_SUFFIX
+    # Style rules we don't enforce
+    - ENUM_VALUE_PREFIX
+    - ENUM_VALUE_UPPER_SNAKE_CASE
+    - ENUM_ZERO_VALUE_SUFFIX

script/clippy 🔗

@@ -16,4 +16,8 @@ if [[ -z "${GITHUB_ACTIONS+x}" ]]; then
 
     which typos >/dev/null 2>&1 || exit 0
     typos --config typos.toml
+
+    which buf >/dev/null 2>&1 || exit 0
+    buf lint crates/proto/proto
+    buf format --diff --exit-code crates/proto/proto
 fi

tooling/xtask/src/tasks/workflows/run_tests.rs 🔗

@@ -533,6 +533,14 @@ pub(crate) fn check_postgres_and_protobuf_migrations() -> NamedJob {
             .add_with(("against", "https://github.com/${GITHUB_REPOSITORY}.git#branch=${BUF_BASE_BRANCH},subdir=crates/proto/proto/"))
     }
 
+    fn buf_lint() -> Step<Run> {
+        named::bash("buf lint crates/proto/proto")
+    }
+
+    fn check_protobuf_formatting() -> Step<Run> {
+        named::bash("buf format --diff --exit-code crates/proto/proto")
+    }
+
     named::job(
         release_job(&[])
             .runs_on(runners::LINUX_DEFAULT)
@@ -543,7 +551,9 @@ pub(crate) fn check_postgres_and_protobuf_migrations() -> NamedJob {
             .add_step(steps::checkout_repo().with_full_history())
             .add_step(ensure_fresh_merge())
             .add_step(bufbuild_setup_action())
-            .add_step(bufbuild_breaking_action()),
+            .add_step(bufbuild_breaking_action())
+            .add_step(buf_lint())
+            .add_step(check_protobuf_formatting()),
     )
 }