33set -eux
44
55TMP_DIR=" $( mktemp -d) "
6- # Allow root directory to be set via environment variable or command line argument
76ROOT_DIR=" ${INPUT_ROOT_DIR:- ${1:- ./ kustomize} } " # First check env var, then argument, then default
7+ MAX_DEPTH=" ${INPUT_MAX_DEPTH:- 2} " # Default to 2 if not specified
88DEBUG=" ${DEBUG:- true} "
99
1010function debug_log() {
@@ -20,8 +20,15 @@ function validate_root_dir() {
2020 fi
2121}
2222
23+ function validate_max_depth() {
24+ if ! [[ " $MAX_DEPTH " =~ ^[0-9]+$ ]]; then
25+ echo " Error: max_depth must be a positive integer, got: $MAX_DEPTH "
26+ exit 1
27+ fi
28+ }
29+
2330function get_targets {
24- find " $ROOT_DIR " -maxdepth 4 -name kustomization.yaml -exec dirname {} \;
31+ find " $ROOT_DIR " -maxdepth " $MAX_DEPTH " -name kustomization.yaml -exec dirname {} \;
2532}
2633
2734function safe_dirname() {
@@ -44,12 +51,18 @@ function build {
4451 local output_file=" $TMP_DIR /$safe_ref /${safe_path} .yaml"
4552 echo " Running kustomize for $envpath "
4653 kustomize build " $envpath " -o " $output_file "
54+
55+ # debug_log "Contents of $output_file:"
56+ # debug_log "$(cat "$output_file")"
57+ # debug_log "End of $output_file"
58+ # debug_log "------------------------------------"
4759 done
4860}
4961
5062function main {
51- # Validate root directory before proceeding
63+ # Validate inputs before proceeding
5264 validate_root_dir
65+ validate_max_depth
5366
5467 git config --global --add safe.directory " $GITHUB_WORKSPACE "
5568 local diff escaped_output output
@@ -89,6 +102,7 @@ function main {
89102# Print initial configuration
90103echo " Configuration:"
91104echo " ROOT_DIR: $ROOT_DIR "
105+ echo " MAX_DEPTH: $MAX_DEPTH "
92106echo " DEBUG: $DEBUG "
93107debug_log " Debug mode is enabled"
94108
0 commit comments