From f2a76fbb25adf832263add178d634b6694dda37f Mon Sep 17 00:00:00 2001
From: STEVAN Antoine <antoine.stevan@isae-supaero.fr>
Date: Tue, 26 Nov 2024 10:36:21 +0000
Subject: [PATCH] check Nushell files in the CI (dragoon/komodo!137)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

in order to help catch issues with the various Nushell scripts and modules in the source base, i propose to add a CI script that will check them all.

below is an example error, e.g. when introducing a syntax error in `.env.nu`:
```
Error:   × Failed to parse content:
  │     file: .env.nu
  │     err:  Expected keyword.
```
---
 Makefile                       |  1 +
 scripts/check-nushell-files.nu | 22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+)
 create mode 100644 scripts/check-nushell-files.nu

diff --git a/Makefile b/Makefile
index aac6952f..79b06bb6 100644
--- a/Makefile
+++ b/Makefile
@@ -9,6 +9,7 @@ fmt:
 	cargo fmt --all
 
 check:
+	nu scripts/check-nushell-files.nu
 	cargo check --workspace --all-targets
 	cargo check --workspace --all-targets --features kzg
 	cargo check --workspace --all-targets --features aplonk
diff --git a/scripts/check-nushell-files.nu b/scripts/check-nushell-files.nu
new file mode 100644
index 00000000..024c6554
--- /dev/null
+++ b/scripts/check-nushell-files.nu
@@ -0,0 +1,22 @@
+let files = ^git lf | lines | where { ($in | path parse).extension == "nu" }
+
+for f in $files {
+    let path = $env.FILE_PWD | path dirname | path join $f
+
+    try {
+        nu-check $path --debug
+    } catch { |e|
+        let err = $e.debug
+            | ansi strip
+            | parse --regex '(.*)msg: "Found : (?<msg>.*)", span: (?<span>.*)'
+            | into record
+
+        error make --unspanned {
+            msg: ([
+                $"(ansi red_bold)($e.msg)(ansi reset):",
+                $"    file: (ansi purple)($f)(ansi reset)",
+                $"    err:  ($err.msg)",
+            ] | str join "\n")
+        }
+    }
+}
-- 
GitLab