28
28
runs-on : ubuntu-latest
29
29
needs : fetch_commit_info
30
30
outputs :
31
- summary : ${{ steps.kubeval.outputs.summary }}
32
- results : ${{ steps.kubeval.outputs.results }}
31
+ summary : ${{ steps.kubeval.outputs.summary || steps.kubeval_skip.outputs.summary }}
32
+ results : ${{ steps.kubeval.outputs.results || steps.kubeval_skip.outputs.results }}
33
33
steps :
34
34
- name : Checkout code
35
35
uses : actions/checkout@v3
@@ -39,14 +39,28 @@ 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
43
+ id : detect_changes
44
+ run : |
45
+ git fetch origin ${{ github.event.before }}
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."
49
+ echo "changed=false" >> $GITHUB_OUTPUT
50
+ else
51
+ echo "$CHANGED_FILES" > changed_yamls.txt
52
+ echo "changed=true" >> $GITHUB_OUTPUT
53
+ fi
54
+
42
55
- name : Validate Kubernetes YAML
43
56
id : kubeval
57
+ if : steps.detect_changes.outputs.changed == 'true'
44
58
run : |
45
59
set +e
46
60
RESULTS=""
47
61
PASS_COUNT=0
48
62
FAIL_COUNT=0
49
- for file in $(find . -name '*.yaml' -o -name '*.yml' ); do
63
+ for file in $(cat changed_yamls.txt ); do
50
64
output=$(kubeconform -strict -verbose "$file" 2>&1)
51
65
if echo "$output" | grep -q "PASS"; then
52
66
emoji="✅"
@@ -60,10 +74,22 @@ jobs:
60
74
61
75
SUMMARY="✅ Passed: ${PASS_COUNT} | ❌ Failed: ${FAIL_COUNT}"
62
76
echo "$RESULTS" > validation_output.txt
63
- echo "::set-output name=results::$RESULTS"
64
- echo "::set-output name=summary::$SUMMARY"
77
+
78
+ echo "results<<EOF" >> $GITHUB_OUTPUT
79
+ echo "$RESULTS" >> $GITHUB_OUTPUT
80
+ echo "EOF" >> $GITHUB_OUTPUT
81
+
82
+ echo "summary=${SUMMARY}" >> $GITHUB_OUTPUT
83
+
84
+ - name : Set summary for skipped validation
85
+ if : steps.detect_changes.outputs.changed == 'false'
86
+ id : kubeval_skip
87
+ run : |
88
+ echo "summary=✅ No Kubernetes YAML files changed. Skipped validation." >> $GITHUB_OUTPUT
89
+ echo "results=" >> $GITHUB_OUTPUT
65
90
66
91
- name : Fail if any errors
92
+ if : steps.detect_changes.outputs.changed == 'true'
67
93
run : |
68
94
if grep -q "❌" validation_output.txt; then
69
95
echo "Validation failed."
@@ -75,13 +101,13 @@ jobs:
75
101
needs : [fetch_commit_info, validate_kubeconform]
76
102
if : always()
77
103
steps :
78
- - name : Comment on commit
79
- env :
80
- GITHUB_TOKEN : ${{ secrets.GH_TOKEN }}
81
- SHA : ${{ needs.fetch_commit_info.outputs.sha }}
82
- COMMIT_MSG : ${{ needs.fetch_commit_info.outputs.message }}
83
- COMMIT_TIME : ${{ needs.fetch_commit_info.outputs.timestamp }}
84
- SUMMARY : ${{ needs.validate_kubeconform.outputs.summary }}
85
- RESULTS : ${{ needs.validate_kubeconform.outputs.results }}
86
- REPO : ${{ github.repository }}
87
- run : chmod +x .github/scripts/comment-kubecheck.sh && bash .github/scripts/comment-kubecheck.sh
104
+ - name : Comment on commit
105
+ env :
106
+ GITHUB_TOKEN : ${{ secrets.GH_TOKEN }}
107
+ SHA : ${{ needs.fetch_commit_info.outputs.sha }}
108
+ COMMIT_MSG : ${{ needs.fetch_commit_info.outputs.message }}
109
+ COMMIT_TIME : ${{ needs.fetch_commit_info.outputs.timestamp }}
110
+ SUMMARY : ${{ needs.validate_kubeconform.outputs.summary }}
111
+ RESULTS : ${{ needs.validate_kubeconform.outputs.results }}
112
+ REPO : ${{ github.repository }}
113
+ run : chmod +x .github/scripts/comment-kubecheck.sh && bash .github/scripts/comment-kubecheck.sh
0 commit comments