forked from nosborn/github-action-markdown-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·45 lines (34 loc) · 1.17 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
#!/bin/sh
MARKDOWNLINT=markdownlint
MARKDOWNLINT="${MARKDOWNLINT}${INPUT_CONFIG_FILE:+ -c ${INPUT_CONFIG_FILE}}"
MARKDOWNLINT="${MARKDOWNLINT}${INPUT_IGNORE_FILES:+ -i ${INPUT_IGNORE_FILES}}"
MARKDOWNLINT="${MARKDOWNLINT}${INPUT_RULES:+ -r ${INPUT_RULES}}"
# shellcheck disable=SC2086
OUTPUT=$(${MARKDOWNLINT} ${INPUT_FILES} 2>&1)
SUCCESS=$?
echo "${OUTPUT}"
if [ ${SUCCESS} -eq 0 ]; then
exit 0
fi
if [ "${GITHUB_EVENT_NAME}" = pull_request ]; then
comment=""
FILES=$(echo "${OUTPUT}" | cut -d: -f1 | sort | uniq)
for file in ${FILES}; do
comment="${comment}<details><summary><code>${file}</code></summary>
\`\`\`
$(echo "${OUTPUT}" | grep "^${file}:" | sed "s/^[^:]*:[[:space:]]*//")
\`\`\`
</details>"
done
COMMENT_BODY="#### Issues with Markdown/CommonMark files
${comment}
*Workflow: \`${GITHUB_WORKFLOW}\`, Action: \`${GITHUB_ACTION}\`*"
PAYLOAD=$(echo '{}' | jq --arg body "${COMMENT_BODY}" '.body = $body')
COMMENTS_URL=$(jq -r .pull_request.comments_url <"${GITHUB_EVENT_PATH}")
curl -sS \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H 'Content-Type: application/json' \
-d "${PAYLOAD}" \
"${COMMENTS_URL}" >/dev/null
fi
exit ${SUCCESS}