3
3
set -eux
4
4
5
5
TMP_DIR=" $( mktemp -d) "
6
- ROOT_DIR=" ${1:- ./ clusters} " # Default to ./clusters if no argument is provided
6
+ # Allow root directory to be set via environment variable or command line argument
7
+ ROOT_DIR=" ${INPUT_ROOT_DIR:- ${1:- ./ kustomize} } " # First check env var, then argument, then default
7
8
DEBUG=" ${DEBUG:- true} "
8
9
9
10
function debug_log() {
@@ -12,6 +13,13 @@ function debug_log() {
12
13
fi
13
14
}
14
15
16
+ function validate_root_dir() {
17
+ if [ ! -d " $ROOT_DIR " ]; then
18
+ echo " Error: Root directory '$ROOT_DIR ' does not exist"
19
+ exit 1
20
+ fi
21
+ }
22
+
15
23
function get_targets {
16
24
find " $ROOT_DIR " -maxdepth 4 -name kustomization.yaml -exec dirname {} \;
17
25
}
@@ -36,15 +44,13 @@ function build {
36
44
local output_file=" $TMP_DIR /$safe_ref /${safe_path} .yaml"
37
45
echo " Running kustomize for $envpath "
38
46
kustomize build " $envpath " -o " $output_file "
39
-
40
- # debug_log "Contents of $output_file:"
41
- # debug_log "$(cat "$output_file")"
42
- # debug_log "End of $output_file"
43
- # debug_log "------------------------------------"
44
47
done
45
48
}
46
49
47
50
function main {
51
+ # Validate root directory before proceeding
52
+ validate_root_dir
53
+
48
54
git config --global --add safe.directory " $GITHUB_WORKSPACE "
49
55
local diff escaped_output output
50
56
build " $INPUT_HEAD_REF "
@@ -60,7 +66,7 @@ function main {
60
66
debug_log " $diff "
61
67
debug_log " End of git diff output"
62
68
debug_log " ------------------------------------"
63
-
69
+
64
70
if [[ -z " $diff " ]]; then
65
71
output=" No differences found between $INPUT_BASE_REF and $INPUT_HEAD_REF "
66
72
else
@@ -80,11 +86,10 @@ function main {
80
86
printf " \n\nOutput: %s\n" " $escaped_output "
81
87
}
82
88
83
- # Check if a directory is provided as an argument
84
- if [ $# -ge 1 ]; then
85
- ROOT_DIR=" $1 "
86
- fi
87
-
88
- echo " Using root directory: $ROOT_DIR "
89
+ # Print initial configuration
90
+ echo " Configuration:"
91
+ echo " ROOT_DIR: $ROOT_DIR "
92
+ echo " DEBUG: $DEBUG "
89
93
debug_log " Debug mode is enabled"
90
- main
94
+
95
+ main
0 commit comments