-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·89 lines (70 loc) · 1.97 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
set -e
# ------------------------
# Args
# ------------------------
FILES=$1
VERSION=$2
STRICT=$3
OPENSHIFT=$4
IGNORE_MISSING_SCHEMAS=$5
IGNORED_FILENAME_PATTERNS=$6
IGNORED_LOGS_WORDS=$7
COMMENT=$8
GITHUB_TOKEN=$9
# ------------------------
# 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} --ignored-filename-patterns=\"${IGNORED_FILENAME_PATTERNS}\" --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
IFS=','
read -r -a ARRAY_OF_BLACKLISTED_SUBSTRING <<< "$IGNORED_LOGS_WORDS"
GREP_PARAM=""
for i in ${ARRAY_OF_BLACKLISTED_SUBSTRING[@]}
do
GREP_PARAM="$GREP_PARAM | grep -v \"$(echo $i | xargs)\""
done
CMD="echo \"${OUTPUT}\" | grep -v \"^PASS\" ${GREP_PARAM}"
echo "running filter with : $CMD"
# We want to exit 0 later if grep command return empty result.
# That's mean there is no important issues
set +e
FILTERED_ERROR=`eval ${CMD}`
set -e
if [ "${FILTERED_ERROR}" = "" ]; 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>
\`\`\`
${FILTERED_ERROR}
\`\`\`
</details>
"
# comment to github
if [ "${COMMENT}" = "true" ];then
echo "Comment PR is activated"
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}