-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathentrypoint.sh
executable file
·64 lines (49 loc) · 1.37 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/sh
set -e
# ------------------------
# Args
# ------------------------
FILES=$1
VERSION=$2
STRICT=$3
OPENSHIFT=$4
IGNORE_MISSING_SCHEMAS=$5
COMMENT=$6
GITHUB_TOKEN=$7
# ------------------------
# Vars
# ------------------------
SUCCESS=0
GIT_COMMENT=""
# ------------------------
# Main
# ------------------------
cd ${GITHUB_WORKSPACE}/${WORKING_DIR}
set +e
# exec kubeval
CMD="/kubeval --directories ${FILES} --output stdout --strict=${STRICT} --kubernetes-version=${VERSION} --openshift=${OPENSHIFT} --ignore-missing-schemas=${IGNORE_MISSING_SCHEMAS}"
OUTPUT=$(sh -c "${CMD}" 2>&1)
SUCCESS=$?
set -e
# let's log command
echo "executed: $CMD"
echo "return code: ${SUCCESS}"
if [ ${SUCCESS} -eq 0 ]; then
echo "Validate success!"
exit 0
fi
# Make validation details for the github comment (filter "PASS" line)
GIT_COMMENT="## ⚠ [kubeval] Validation Failed
<details><summary><code>detail</code></summary>
\`\`\`
$(echo "${OUTPUT}" | grep -v ^PASS | grep -v "Set to ignore missing schemas")
\`\`\`
</details>
"
# comment to github
if [ "${COMMENT}" = "true" ];then
PAYLOAD=$(echo '{}' | jq --arg body "${GIT_COMMENT}" '.body = $body')
COMMENTS_URL=$(cat ${GITHUB_EVENT_PATH} | jq -r .pull_request.comments_url)
curl -sS -H "Authorization: token ${GITHUB_TOKEN}" --header "Content-Type: application/json" --data "${PAYLOAD}" "${COMMENTS_URL}" >/dev/null
fi
exit ${SUCCESS}