diff --git a/.github/problem-matcher.json b/.github/problem-matcher.json new file mode 100644 index 0000000..f0741f6 --- /dev/null +++ b/.github/problem-matcher.json @@ -0,0 +1,17 @@ +{ + "problemMatcher": [ + { + "owner": "markdownlint", + "pattern": [ + { + "regexp": "^([^:]*):(\\d+):?(\\d+)?\\s([\\w-\\/]*)\\s(.*)$", + "file": 1, + "line": 2, + "column": 3, + "code": 4, + "message": 5 + } + ] + } + ] +} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..22bf1d2 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,15 @@ +name: Main + +on: + push: + branches: + - main + pull_request: + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: shellcheck entrypoint.sh + - uses: ./ diff --git a/.markdownlint.json b/.markdownlint.json new file mode 100644 index 0000000..64ddbaa --- /dev/null +++ b/.markdownlint.json @@ -0,0 +1,20 @@ +{ + "default": true, + "MD003": { + "style": "atx" + }, + "MD004": { + "style": "asterisk" + }, + "MD013": { + "code_blocks": false, + "tables": false + }, + "MD033": { + "allowed_elements": [ + "details", + "summary" + ] + }, + "MD046": false +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a7b77af --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM node:lts-alpine + +COPY entrypoint.sh .github/problem-matcher.json .markdownlint.json / + +RUN npm install --global --production markdownlint-cli + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..8e7547d --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# markdownlint action + +This action lints your Markdown files with [markdownlint-cli](https://github.com/igorshubovych/markdownlint-cli). + +## Usage + +Including the action without any defaults will find a local markdownlint config +file (`.markdownlint.{yaml,yml,json}`) or use our included default and scan all +files with the `md` or `markdown` extension. + +```yaml +- uses: articulate/actions-markdownlint@main +``` + +You can set the config file, the files it scans, or files/directories to ignore. + +```yaml +- uses: articulate/actions-markdownlint@main + with: + config: markdownlint-config.json + files: 'docs/**/*.md' + ignore: node_modules +``` diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..488667b --- /dev/null +++ b/action.yml @@ -0,0 +1,23 @@ +name: 'markdownlint' +author: 'Articulate' +description: 'Lint your markdown' +inputs: + config: + description: 'markdownlint config file' + required: false + files: + description: 'Markdown files to scan' + required: false + default: '**/*.{md,markdown}' + ignore: + description: 'Files or directories to ignore' + required: false + fix: + description: 'Try to fix basic errors' + required: false +runs: + using: 'docker' + image: 'Dockerfile' +branding: + color: 'blue' + icon: 'check-circle' diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..73fd049 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +# Copy the matcher to a shared volume with the host; otherwise "add-matcher" +# can't find it. +cp /problem-matcher.json "${HOME}/markdownlint-problem-matcher.json" +echo "::add-matcher::${HOME}/markdownlint-problem-matcher.json" + +MARKDOWNLINT= + +if [ -z "$INPUT_CONFIG" ]; then + echo "::debug::no config given, finding suitable config" + INPUT_CONFIG=/.markdownlint.json + for cfg in .markdownlint.yaml .markdownlint.yml .markdownlint.json .markdown-lint.yml .markdown-lint.json; do + if [ -f "$cfg" ]; then + INPUT_CONFIG="$cfg" + continue + fi + done +fi + +echo "::debug::using config ${INPUT_CONFIG}" +MARKDOWNLINT="${MARKDOWNLINT} --config ${INPUT_CONFIG}" + +if [ -n "$INPUT_IGNORE" ]; then + echo "::debug::ignoring ${INPUT_IGNORE}" + MARKDOWNLINT="${MARKDOWNLINT} --ignore ${INPUT_IGNORE}" +fi + +if [ -n "$INPUT_FIX" ]; then + echo "::debug::attempting to fix input" + MARKDOWNLINT="${MARKDOWNLINT} --fix" +fi + +echo "::debug::linting ${INPUT_FILES}" +# shellcheck disable=SC2086 +markdownlint ${MARKDOWNLINT} ${INPUT_FILES}