Skip to content

Commit

Permalink
Use a problem matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
nosborn committed Dec 20, 2021
1 parent 5d39164 commit 89b70e8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 35 deletions.
24 changes: 24 additions & 0 deletions .github/markdownlint-problem-matcher.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"problemMatcher": [
{
"owner": "markdownlint",
"pattern": [
{
"code": 3,
"file": 1,
"line": 2,
"message": 4,
"regexp": "^(.+):(\\d+) (MD\\d+)/(.+)$"
},
{
"code": 4,
"column": 3,
"file": 1,
"line": 2,
"message": 5,
"regexp": "^(.+):(\\d+):(\\d+) (MD\\d+)/(.+)$"
}
]
}
]
}
41 changes: 6 additions & 35 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,12 @@ 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 '::add-matcher::.github/markdownlint-problem-matcher.json'

\`\`\`
$(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}")
# shellcheck disable=SC2086
${MARKDOWNLINT} ${INPUT_FILES}
readonly RC=$?

curl -sS \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H 'Content-Type: application/json' \
-d "${PAYLOAD}" \
"${COMMENTS_URL}" >/dev/null
fi
echo '::remove-matcher owner=markdownlint::'

exit ${SUCCESS}
exit ${RC}

0 comments on commit 89b70e8

Please sign in to comment.