From b36cfa65da55abd7ffc04247b03bd9c4f4adc864 Mon Sep 17 00:00:00 2001
From: Josh <josh.t.richards@gmail.com>
Date: Fri, 18 Apr 2025 09:12:44 -0400
Subject: [PATCH] fix(hooks): make the output more uniform and delineated
 (#2343)

* fix(hooks): Consistent logging + skip when empty too

- Use "Searching for scripts [...] located in [...]" consistently (i.e. for each hook_folder_path instead of only for some / under some conditions)
- Skip early if a given hook folder is empty too (not just nonexistent)
- Add feature name (hooks) to all messaging for clarity

Signed-off-by: Josh <josh.t.richards@gmail.com>

* fix(hooks): Clear state delineation / consistent output

Signed-off-by: Josh <josh.t.richards@gmail.com>

---------

Signed-off-by: Josh <josh.t.richards@gmail.com>
---
 docker-entrypoint.sh | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh
index c571d8d4..e3b88f14 100755
--- a/docker-entrypoint.sh
+++ b/docker-entrypoint.sh
@@ -23,32 +23,39 @@ run_as() {
 run_path() {
     local hook_folder_path="/docker-entrypoint-hooks.d/$1"
     local return_code=0
+    local found=0
 
-    if ! [ -d "${hook_folder_path}" ]; then
-        echo "=> Skipping the folder \"${hook_folder_path}\", because it doesn't exist"
+    echo "=> Searching for hook scripts (*.sh) to run, located in the folder \"${hook_folder_path}\""
+
+    if ! [ -d "${hook_folder_path}" ] || directory_empty "${hook_folder_path}"; then
+        echo "==> Skipped: the \"$1\" folder is empty (or does not exist)"
         return 0
     fi
 
-    echo "=> Searching for scripts (*.sh) to run, located in the folder: ${hook_folder_path}"
-
-    (
-        find "${hook_folder_path}" -maxdepth 1 -iname '*.sh' '(' -type f -o -type l ')' -print | sort | while read -r script_file_path; do
+    find "${hook_folder_path}" -maxdepth 1 -iname '*.sh' '(' -type f -o -type l ')' -print | sort | (
+        while read -r script_file_path; do
             if ! [ -x "${script_file_path}" ]; then
-                echo "==> The script \"${script_file_path}\" was skipped, because it didn't have the executable flag"
+                echo "==> The script \"${script_file_path}\" was skipped, because it lacks the executable flag"
+                found=$((found-1))
                 continue
             fi
 
             echo "==> Running the script (cwd: $(pwd)): \"${script_file_path}\""
-
+            found=$((found+1))
             run_as "${script_file_path}" || return_code="$?"
 
             if [ "${return_code}" -ne "0" ]; then
-                echo "==> Failed at executing \"${script_file_path}\". Exit code: ${return_code}"
+                echo "==> Failed at executing script \"${script_file_path}\". Exit code: ${return_code}"
                 exit 1
             fi
 
-            echo "==> Finished the script: \"${script_file_path}\""
+            echo "==> Finished executing the script: \"${script_file_path}\""
         done
+        if [ "$found" -lt "1" ]; then
+            echo "==> Skipped: the \"$1\" folder does not contain any valid scripts"
+        else
+            echo "=> Completed executing scripts in the \"$1\" folder"
+        fi
     )
 }
 
-- 
GitLab