Skip to content

Commit 95d837f

Browse files
committed
Supporting max depth.
1 parent 61783cf commit 95d837f

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
uses: swade1987/github-action-kustomize-diff@master
3636
with:
3737
root_dir: "./my-custom-path"
38+
max_depth: "2"
3839
- id: comment
3940
uses: unsplash/comment-on-pr@master
4041
env:

action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ inputs:
2121
description: "Root directory for kustomize files"
2222
required: false
2323
default: "./kustomize"
24+
max_depth:
25+
description: "Maximum depth to search for kustomization files"
26+
required: false
27+
default: "2"
2428
outputs:
2529
diff:
2630
description: "Diff between kustomize built head and base"

kustdiff

+17-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
set -eux
44

55
TMP_DIR="$(mktemp -d)"
6-
# Allow root directory to be set via environment variable or command line argument
76
ROOT_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
88
DEBUG="${DEBUG:-true}"
99

1010
function 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+
2330
function 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

2734
function 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

5062
function 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
90103
echo "Configuration:"
91104
echo "ROOT_DIR: $ROOT_DIR"
105+
echo "MAX_DEPTH: $MAX_DEPTH"
92106
echo "DEBUG: $DEBUG"
93107
debug_log "Debug mode is enabled"
94108

0 commit comments

Comments
 (0)