Skip to content

Commit 5b78865

Browse files
committed
check ripgrep installed
1 parent 5f7a274 commit 5b78865

2 files changed

Lines changed: 43 additions & 27 deletions

File tree

ci/check_all_exposed_funs_tested.roc

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import pf.File
66
import pf.Cmd
77
import pf.Env
88
import pf.Path
9+
import pf.Sleep
910

1011
# This script performs the following tasks:
1112
# 1. Reads the file platform/main.roc and extracts the exposes list.
@@ -72,7 +73,10 @@ main! = |_args|
7273
|function_name|
7374
Stdout.line!(function_name),
7475
)?
75-
Err(Exit(1, "I found untested functions, see above."))?
76+
77+
# Sleep to fix print order
78+
Sleep.millis!(1000)
79+
Err(Exit(1, "I found untested functions, see above."))
7680
7781
is_function_unused! : Str, Str => Result Bool _
7882
is_function_unused! = |module_name, function_name|
@@ -101,32 +105,42 @@ is_function_unused! = |module_name, function_name|
101105
err_s("Error checking directory '${search_dir}': ${Inspect.to_str(err)}")
102106
)?
103107

104-
unused_in_dir =
105-
search_dirs
106-
|> List.map_try!( |search_dir|
107-
# Skip searching if directory doesn't exist
108-
dir_exists = File.is_dir!(search_dir)?
109-
if !dir_exists then
110-
Ok(Bool.true) # Consider unused if we can't search
111-
else
112-
# Use ripgrep to search for the function pattern
113-
cmd =
114-
Cmd.new("rg")
115-
|> Cmd.arg("-q") # Quiet mode - we only care about exit code
116-
|> Cmd.arg(function_pattern)
117-
|> Cmd.arg(search_dir)
118-
119-
status_res = Cmd.status!(cmd)
120-
121-
# ripgrep returns status 0 if matches were found, 1 if no matches
122-
when status_res is
123-
Ok(0) -> Ok(Bool.false) # Function is used (not unused)
124-
_ -> Ok(Bool.true)
125-
)?
108+
# Check if ripgrep is installed
109+
rg_check_cmd = Cmd.new("rg") |> Cmd.arg("--version")
110+
rg_check_output = Cmd.output!(rg_check_cmd)
111+
112+
when rg_check_output.status is
113+
Ok(0) ->
114+
unused_in_dir =
115+
search_dirs
116+
|> List.map_try!( |search_dir|
117+
# Skip searching if directory doesn't exist
118+
dir_exists = File.is_dir!(search_dir)?
119+
if !dir_exists then
120+
Ok(Bool.true) # Consider unused if we can't search
121+
else
122+
# Use ripgrep to search for the function pattern
123+
cmd =
124+
Cmd.new("rg")
125+
|> Cmd.arg("-q") # Quiet mode - we only care about exit code
126+
|> Cmd.arg(function_pattern)
127+
|> Cmd.arg(search_dir)
128+
129+
status_res = Cmd.status!(cmd)
130+
131+
# ripgrep returns status 0 if matches were found, 1 if no matches
132+
when status_res is
133+
Ok(0) -> Ok(Bool.false) # Function is used (not unused)
134+
_ -> Ok(Bool.true)
135+
)?
136+
137+
unused_in_dir
138+
|> List.walk!(Bool.true, |state, is_unused_res| state && is_unused_res)
139+
|> Ok
140+
_ ->
141+
err_s("Error: ripgrep (rg) is not installed or not available in PATH. Please install ripgrep to use this script. Full output: ${Inspect.to_str(rg_check_output)}")
142+
126143

127-
unused_in_dir
128-
|> List.walk!(Bool.true, |state, is_unused_res| state && is_unused_res)
129-
|> Ok
130144

131145
process_module! : Str => Result { module_name : Str, exposed_functions : List Str } _
132146
process_module! = |module_name|

platform/main.roc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ main_for_host! = |raw_args|
4747
Err(msg) ->
4848
help_msg =
4949
"""
50+
5051
Program exited with error:
51-
${Inspect.to_str(msg)}
52+
53+
❌ ${Inspect.to_str(msg)}
5254
5355
Tip: If you do not want to exit on this error, use `Result.map_err` to handle the error. Docs for `Result.map_err`: <https://www.roc-lang.org/builtins/Result#map_err>
5456
"""

0 commit comments

Comments
 (0)