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 b5f9765 commit 7b698a3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 37 deletions.
16 changes: 16 additions & 0 deletions .github/markdownlint-problem-matcher.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"problemMatcher": [
{
"owner": "markdownlint",
"pattern": [
{
"code": 3,
"file": 1,
"line": 2,
"message": 4,
"regexp": "^(.+):(\\d+)(?:\\d+)? (\\S+) (.+)$"
}
]
}
]
}
19 changes: 17 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,30 @@ 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: .
ignore_files: examples/ignore/*
rules: examples/rules/custom.js
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: ./
- name: Test ignore_path
uses: ./
with:
config_file: .markdownlintrc
files: .
Expand Down
41 changes: 6 additions & 35 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}<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 7b698a3

Please sign in to comment.