-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·74 lines (58 loc) · 1.43 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
#!/bin/sh
set -e
# ------------------------
# Args
# ------------------------
FILE=$1
OUTPUT=$2
POLICY=$3
TRACE=$4
UPDATE=$5
COMMENT=$6
GITHUB_TOKEN=$7
# ------------------------
# Vars
# ------------------------
SUCCESS=0
GIT_COMMENT=""
# ------------------------
# Main
# ------------------------
cd ${GITHUB_WORKSPACE}/${WORKING_DIR}
set +e
if [ "${UPDATE}" != "" ]; then
# Use "/.policy" for download directory (ignore user setting)
POLICY="/.policy"
# Add --update args
UPDATE="--update ${UPDATE}"
fi
# exec conftest
CMD="/usr/local/bin/conftest test --no-color -p ${POLICY} -o ${OUTPUT} --trace=${TRACE} ${UPDATE} ${FILE}"
OUTPUT=$(sh -c "${CMD}" 2>&1)
SUCCESS=$?
set -e
# let's log command
echo "--- file ---"
ls -l ${FILE}
echo "------"
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="## ⚠ [conftest] Validation Failed
<details><summary><code>detail</code></summary>
\`\`\`
$(echo "${OUTPUT}")
\`\`\`
</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}