Skip to content

Commit 2725671

Browse files
committed
Kubernetes: Update KubeCheck workflow to use actions/upload-artifact@v4 and enhance comment script error handling
Signed-off-by: NotHarshhaa <[email protected]>
1 parent ffc5212 commit 2725671

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

Diff for: .github/scripts/comment-kubecheck.sh

+23-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
#!/bin/bash
22

3-
set -e
3+
# Fail script on errors, print each command
4+
set -euo pipefail
5+
set -x # Enable command echoing for debug
46

5-
# Fallback defaults (optional safety)
7+
# Fallback defaults
68
COMMIT_TIME="${COMMIT_TIME:-Unknown}"
79
COMMIT_MSG="${COMMIT_MSG:-(no message)}"
810
SUMMARY="${SUMMARY:-No summary provided.}"
911
RESULTS="${RESULTS:-}"
12+
REPO="${REPO:-}"
13+
SHA="${SHA:-}"
1014

11-
# Format commit message to escape backticks or special chars
15+
# Format commit message to escape backticks or special characters
1216
ESCAPED_MSG=$(echo "$COMMIT_MSG" | sed 's/`/\\`/g')
1317

14-
# If no validation results, say so
18+
# If no validation results, provide a placeholder
1519
if [[ -z "$RESULTS" ]]; then
1620
RESULTS="_No files were validated in this run._"
1721
fi
1822

23+
# Construct markdown comment
1924
COMMENT="$(cat <<EOF
2025
🧪 **KubeCheck Validation Results**
2126
@@ -30,13 +35,23 @@ ${RESULTS}
3035
EOF
3136
)"
3237

33-
# Print for debug
38+
# Print comment preview for log/debugging
39+
echo "Generated comment content:"
3440
echo "$COMMENT"
3541

36-
# Escape for JSON and send
42+
# Escape for JSON
3743
jq -n --arg body "$COMMENT" '{body: $body}' > comment.json
3844

45+
# Perform the API call and capture HTTP response
46+
RESPONSE_FILE="curl_response.log"
47+
3948
curl -s -X POST "https://api.github.com/repos/${REPO}/commits/${SHA}/comments" \
40-
-H "Authorization: token ${GH_TOKEN}" \
49+
-H "Authorization: token ${GITHUB_TOKEN}" \
4150
-H "Content-Type: application/json" \
42-
--data-binary @comment.json
51+
--data-binary @comment.json \
52+
-w "\n\nHTTP Status: %{http_code}\n" \
53+
-o "$RESPONSE_FILE"
54+
55+
# Output the response content to logs
56+
echo "GitHub API response:"
57+
cat "$RESPONSE_FILE"

Diff for: .github/workflows/kubecheck.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ jobs:
9292
9393
- name: Upload validation results
9494
if: always()
95-
uses: actions/upload-artifact@v3
95+
uses: actions/upload-artifact@v4
9696
with:
9797
name: validation-results
9898
path: validation_output.txt

0 commit comments

Comments
 (0)