@@ -39,17 +39,31 @@ jobs:
39
39
curl -L https://github.com/yannh/kubeconform/releases/latest/download/kubeconform-linux-amd64.tar.gz | tar xz
40
40
sudo mv kubeconform /usr/local/bin/
41
41
42
- - name : Detect changed YAML files
42
+ - name : Detect changed Kubernetes YAML files
43
43
id : detect_changes
44
44
run : |
45
45
git fetch origin ${{ github.event.before }}
46
46
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -E '\.ya?ml$' || true)
47
- if [ -z "$CHANGED_FILES" ]; then
48
- echo "No Kubernetes YAML changes found. Skipping validation."
47
+
48
+ echo "Detected YAML files:"
49
+ echo "$CHANGED_FILES"
50
+
51
+ # Filter for real Kubernetes manifests (contains kind + apiVersion)
52
+ VALID_KUBE_FILES=""
53
+ for file in $CHANGED_FILES; do
54
+ if [[ -f "$file" ]] && grep -q '^\s*apiVersion:' "$file" && grep -q '^\s*kind:' "$file"; then
55
+ VALID_KUBE_FILES+="$file"$'\n'
56
+ fi
57
+ done
58
+
59
+ if [[ -z "$VALID_KUBE_FILES" ]]; then
60
+ echo "No valid Kubernetes manifests found. Skipping validation."
49
61
echo "changed=false" >> $GITHUB_OUTPUT
50
62
else
51
- echo "$CHANGED_FILES " > changed_yamls.txt
63
+ echo "$VALID_KUBE_FILES " > changed_yamls.txt
52
64
echo "changed=true" >> $GITHUB_OUTPUT
65
+ echo "Files to validate:"
66
+ cat changed_yamls.txt
53
67
fi
54
68
55
69
- name : Validate Kubernetes YAML
60
74
RESULTS=""
61
75
PASS_COUNT=0
62
76
FAIL_COUNT=0
77
+
63
78
while IFS= read -r file; do
64
79
output=$(kubeconform -strict -verbose "$file" 2>&1)
65
80
if echo "$output" | grep -q "PASS"; then
@@ -80,14 +95,14 @@ jobs:
80
95
echo "EOF" >> $GITHUB_OUTPUT
81
96
82
97
echo "summary=${SUMMARY}" >> $GITHUB_OUTPUT
83
-
98
+ echo -e "$SUMMARY"
84
99
echo -e "$RESULTS"
85
100
86
101
- name : Set summary for skipped validation
87
102
if : steps.detect_changes.outputs.changed == 'false'
88
103
id : kubeval_skip
89
104
run : |
90
- echo "summary=✅ No Kubernetes YAML files changed. Skipped validation." >> $GITHUB_OUTPUT
105
+ echo "summary=✅ No valid Kubernetes YAML files changed. Skipped validation." >> $GITHUB_OUTPUT
91
106
echo "results=" >> $GITHUB_OUTPUT
92
107
93
108
- name : Upload validation results
0 commit comments