From 4873639f7f122fb5e79d724fcd287c72bf698dd9 Mon Sep 17 00:00:00 2001 From: Nick Osborn Date: Mon, 20 Dec 2021 12:02:00 +0800 Subject: [PATCH] Use a problem matcher --- .github/markdownlint-problem-matcher.json | 24 +++++++++++++ entrypoint.sh | 41 ++++------------------- 2 files changed, 30 insertions(+), 35 deletions(-) create mode 100644 .github/markdownlint-problem-matcher.json diff --git a/.github/markdownlint-problem-matcher.json b/.github/markdownlint-problem-matcher.json new file mode 100644 index 0000000..f016e03 --- /dev/null +++ b/.github/markdownlint-problem-matcher.json @@ -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+)/(.+)$" + } + ] + } + ] +} diff --git a/entrypoint.sh b/entrypoint.sh index a5e5431..ebe98e5 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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}
${file} +echo '::add-matcher::markdownlint-problem-matcher.json' -\`\`\` -$(echo "${OUTPUT}" | grep "^${file}:" | sed "s/^[^:]*:[[:space:]]*//") -\`\`\` - -
" - 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}