Skip to content

Commit

Permalink
Supporting max depth.
Browse files Browse the repository at this point in the history
  • Loading branch information
swade1987 committed Jan 17, 2025
1 parent 61783cf commit 95d837f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
uses: swade1987/github-action-kustomize-diff@master
with:
root_dir: "./my-custom-path"
max_depth: "2"
- id: comment
uses: unsplash/comment-on-pr@master
env:
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ inputs:
description: "Root directory for kustomize files"
required: false
default: "./kustomize"
max_depth:
description: "Maximum depth to search for kustomization files"
required: false
default: "2"
outputs:
diff:
description: "Diff between kustomize built head and base"
Expand Down
20 changes: 17 additions & 3 deletions kustdiff
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
set -eux

TMP_DIR="$(mktemp -d)"
# Allow root directory to be set via environment variable or command line argument
ROOT_DIR="${INPUT_ROOT_DIR:-${1:-./kustomize}}" # First check env var, then argument, then default
MAX_DEPTH="${INPUT_MAX_DEPTH:-2}" # Default to 2 if not specified
DEBUG="${DEBUG:-true}"

function debug_log() {
Expand All @@ -20,8 +20,15 @@ function validate_root_dir() {
fi
}

function validate_max_depth() {
if ! [[ "$MAX_DEPTH" =~ ^[0-9]+$ ]]; then
echo "Error: max_depth must be a positive integer, got: $MAX_DEPTH"
exit 1
fi
}

function get_targets {
find "$ROOT_DIR" -maxdepth 4 -name kustomization.yaml -exec dirname {} \;
find "$ROOT_DIR" -maxdepth "$MAX_DEPTH" -name kustomization.yaml -exec dirname {} \;
}

function safe_dirname() {
Expand All @@ -44,12 +51,18 @@ function build {
local output_file="$TMP_DIR/$safe_ref/${safe_path}.yaml"
echo "Running kustomize for $envpath"
kustomize build "$envpath" -o "$output_file"

# debug_log "Contents of $output_file:"
# debug_log "$(cat "$output_file")"
# debug_log "End of $output_file"
# debug_log "------------------------------------"
done
}

function main {
# Validate root directory before proceeding
# Validate inputs before proceeding
validate_root_dir
validate_max_depth

git config --global --add safe.directory "$GITHUB_WORKSPACE"
local diff escaped_output output
Expand Down Expand Up @@ -89,6 +102,7 @@ function main {
# Print initial configuration
echo "Configuration:"
echo "ROOT_DIR: $ROOT_DIR"
echo "MAX_DEPTH: $MAX_DEPTH"
echo "DEBUG: $DEBUG"
debug_log "Debug mode is enabled"

Expand Down

0 comments on commit 95d837f

Please sign in to comment.