Skip to content

Commit 892bf4f

Browse files
committed
fix(workflow): ensure Kyverno errors are written to PR summary and exit properly
Previously, Kyverno failures were not clearly visible in the PR summary due to missing output redirects and improper exit checks. This change captures the Kyverno exit code explicitly, appends the results to `$GITHUB_STEP_SUMMARY`, and exits with an error when validation fails.
1 parent 5412aee commit 892bf4f

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

.github/workflows/validate-claims.yaml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,18 @@ jobs:
3131
echo "" >> $GITHUB_STEP_SUMMARY
3232
echo '```' >> $GITHUB_STEP_SUMMARY
3333
34-
if kyverno apply ./kyverno --resource ./crossplane/claims | tee result.txt; then
35-
echo "✅ All policies passed." >> $GITHUB_STEP_SUMMARY
36-
else
37-
cat result.txt >> $GITHUB_STEP_SUMMARY
38-
echo '```' >> $GITHUB_STEP_SUMMARY
34+
set +e
35+
kyverno apply ./kyverno --resource ./crossplane/claims | tee result.txt
36+
KYVERNO_EXIT_CODE=${PIPESTATUS[0]}
37+
set -e
38+
39+
cat result.txt >> $GITHUB_STEP_SUMMARY
40+
echo '```' >> $GITHUB_STEP_SUMMARY
41+
42+
if [[ $KYVERNO_EXIT_CODE -ne 0 ]]; then
3943
echo "" >> $GITHUB_STEP_SUMMARY
40-
echo "❌ One or more Kyverno policies failed." >> $GITHUB_STEP_SUMMARY
44+
echo "❌ One or more Kyverno policies failed. Please fix the issues above." >> $GITHUB_STEP_SUMMARY
4145
exit 1
46+
else
47+
echo "✅ All policies passed." >> $GITHUB_STEP_SUMMARY
4248
fi
43-
44-
echo '```' >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)