Skip to content

Commit b7d33b6

Browse files
committed
fix: allowing root directory to be specified.
1 parent 0aaaf99 commit b7d33b6

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ inputs:
1717
description: "Token for GitHub authentication"
1818
required: true
1919
default: ${{ github.token }}
20+
root_dir:
21+
description: "Root directory for kustomize files"
22+
required: false
23+
default: "./kustomize"
2024
outputs:
2125
diff:
2226
description: "Diff between kustomize built head and base"

kustdiff

+19-14
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
set -eux
44

55
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
78
DEBUG="${DEBUG:-true}"
89

910
function debug_log() {
@@ -12,6 +13,13 @@ function debug_log() {
1213
fi
1314
}
1415

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+
1523
function get_targets {
1624
find "$ROOT_DIR" -maxdepth 4 -name kustomization.yaml -exec dirname {} \;
1725
}
@@ -36,15 +44,13 @@ function build {
3644
local output_file="$TMP_DIR/$safe_ref/${safe_path}.yaml"
3745
echo "Running kustomize for $envpath"
3846
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 "------------------------------------"
4447
done
4548
}
4649

4750
function main {
51+
# Validate root directory before proceeding
52+
validate_root_dir
53+
4854
git config --global --add safe.directory "$GITHUB_WORKSPACE"
4955
local diff escaped_output output
5056
build "$INPUT_HEAD_REF"
@@ -60,7 +66,7 @@ function main {
6066
debug_log "$diff"
6167
debug_log "End of git diff output"
6268
debug_log "------------------------------------"
63-
69+
6470
if [[ -z "$diff" ]]; then
6571
output="No differences found between $INPUT_BASE_REF and $INPUT_HEAD_REF"
6672
else
@@ -80,11 +86,10 @@ function main {
8086
printf "\n\nOutput: %s\n" "$escaped_output"
8187
}
8288

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"
8993
debug_log "Debug mode is enabled"
90-
main
94+
95+
main

0 commit comments

Comments
 (0)