ci: Add check for formatting of query files (#50140)

Finn Evers created

Follow-up to https://github.com/zed-industries/zed/pull/50138

I deliberately decided against adding this in a separete job because
ts_query_ls is very fast when it comes to both formatting these as well
as checking for proper formatting. Will see here how long it takes to
install and whether we might need to adjust to account for the
installation time.

Release Notes:

- N/A

Change summary

.github/workflows/run_tests.yml                | 15 +++++++++
tooling/xtask/src/tasks/workflows/run_tests.rs | 32 +++++++++++++++++++
2 files changed, 46 insertions(+), 1 deletion(-)

Detailed changes

.github/workflows/run_tests.yml 🔗

@@ -139,6 +139,21 @@ jobs:
       uses: crate-ci/typos@2d0ce569feab1f8752f1dde43cc2f2aa53236e06
       with:
         config: ./typos.toml
+    - name: run_tests::check_style::fetch_ts_query_ls
+      uses: dsaltares/fetch-gh-release-asset@aa37ae5c44d3c9820bc12fe675e8670ecd93bd1c
+      with:
+        repo: ribru17/ts_query_ls
+        version: tags/v3.15.1
+        file: ts_query_ls-x86_64-unknown-linux-gnu.tar.gz
+    - name: run_tests::check_style::run_ts_query_ls
+      run: |-
+        tar -xf ts_query_ls-x86_64-unknown-linux-gnu.tar.gz
+        ./ts_query_ls format --check . || {
+            echo "Found unformatted queries, please format them with ts_query_ls."
+            echo "For easy use, install the Tree-sitter query extension:"
+            echo "zed://extension/tree-sitter-query"
+            false
+        }
     timeout-minutes: 60
   clippy_windows:
     needs:

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

@@ -3,6 +3,7 @@ use gh_workflow::{
     Workflow,
 };
 use indexmap::IndexMap;
+use indoc::formatdoc;
 
 use crate::tasks::workflows::{
     steps::{CommonJobConditions, repository_owner_guard_expression},
@@ -267,6 +268,9 @@ pub fn tests_pass(jobs: &[NamedJob]) -> NamedJob {
     named::job(job)
 }
 
+const TS_QUERY_LS_FILE: &str = "ts_query_ls-x86_64-unknown-linux-gnu.tar.gz";
+const CI_TS_QUERY_RELEASE: &str = "tags/v3.15.1";
+
 fn check_style() -> NamedJob {
     fn check_for_typos() -> Step<Use> {
         named::uses(
@@ -276,6 +280,30 @@ fn check_style() -> NamedJob {
         ) // v1.40.0
         .with(("config", "./typos.toml"))
     }
+
+    fn fetch_ts_query_ls() -> Step<Use> {
+        named::uses(
+            "dsaltares",
+            "fetch-gh-release-asset",
+            "aa37ae5c44d3c9820bc12fe675e8670ecd93bd1c",
+        ) // v1.1.1
+        .add_with(("repo", "ribru17/ts_query_ls"))
+        .add_with(("version", CI_TS_QUERY_RELEASE))
+        .add_with(("file", TS_QUERY_LS_FILE))
+    }
+
+    fn run_ts_query_ls() -> Step<Run> {
+        named::bash(formatdoc!(
+            r#"tar -xf {TS_QUERY_LS_FILE}
+            ./ts_query_ls format --check . || {{
+                echo "Found unformatted queries, please format them with ts_query_ls."
+                echo "For easy use, install the Tree-sitter query extension:"
+                echo "zed://extension/tree-sitter-query"
+                false
+            }}"#
+        ))
+    }
+
     named::job(
         release_job(&[])
             .runs_on(runners::LINUX_MEDIUM)
@@ -286,7 +314,9 @@ fn check_style() -> NamedJob {
             .add_step(steps::cargo_fmt())
             .add_step(steps::script("./script/check-todos"))
             .add_step(steps::script("./script/check-keymaps"))
-            .add_step(check_for_typos()),
+            .add_step(check_for_typos())
+            .add_step(fetch_ts_query_ls())
+            .add_step(run_ts_query_ls()),
     )
 }