From 174a7a52f073ec632d4a3a42b2b1de1f1769d819 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 | 16 +++++++++ .github/workflows/ci.yml | 19 +++++++++-- entrypoint.sh | 41 ++++------------------- 3 files changed, 39 insertions(+), 37 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..22ecf68 --- /dev/null +++ b/.github/markdownlint-problem-matcher.json @@ -0,0 +1,16 @@ +{ + "problemMatcher": [ + { + "owner": "markdownlint", + "pattern": [ + { + "code": 3, + "file": 1, + "line": 2, + "message": 4, + "regexp": "^(.+):(\\d+)(?:\\d+)? (\\S+) (.+)$" + } + ] + } + ] +} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index feb7a3c..4caa8ff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,21 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2.4.0 - - uses: ./ + - name: Test problem matcher + id: expect-failure + uses: ./ + with: + config_file: .markdownlintrc + files: . + rules: examples/rules/custom.js + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + continue-on-error: true + - if: ${{ steps.expect-failure.outcome != 'failure' }} + run: | + exit 1 + - name: Test ignore_files + uses: ./ with: config_file: .markdownlintrc files: . @@ -34,7 +48,8 @@ jobs: rules: examples/rules/custom.js env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - uses: ./ + - name: Test ignore_path + uses: ./ with: config_file: .markdownlintrc files: . diff --git a/entrypoint.sh b/entrypoint.sh index 6902a4c..7419411 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -6,41 +6,12 @@ MARKDOWNLINT="${MARKDOWNLINT}${INPUT_IGNORE_FILES:+ -i ${INPUT_IGNORE_FILES}}" MARKDOWNLINT="${MARKDOWNLINT}${INPUT_IGNORE_PATH:+ -p ${INPUT_IGNORE_PATH}}" 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::.github/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}