This GitHub Action runs the markdownlint-cli2 pre-commit hook on a
ref range and reports:
- Suggested fixes (as a diff review)
- Diagnostics (inline comments on the PR)
via reviewdog.
Add the markdownlint-cli2 hook to your .pre-commit-config.yaml:
repos:
- repo: https://github.com/DavidAnson/markdownlint-cli2
rev: v0.19.1
hooks:
- id: markdownlint-cli2You also need:
- GitHub Actions enabled on the repository
secrets.GITHUB_TOKENavailable (default on GitHub-hosted runners)actions/checkoutfetching enough history to include bothfrom-refandto-ref, for example:
- uses: actions/checkout@v4
with:
fetch-depth: 0| Name | Required | Description |
|---|---|---|
from-ref |
✅ | Base git ref (e.g. PR base SHA) |
to-ref |
✅ | Head git ref (e.g. PR head SHA) |
github-token |
✅ | GitHub token for reviewdog (secrets.GITHUB_TOKEN) |
| Name | Description |
|---|---|
exitcode |
Exit code returned by the markdownlint-cli2 hook |
Example workflow for pull requests:
name: Lint Markdown with markdownlint-cli2
on:
pull_request:
jobs:
markdownlint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run markdownlint-cli2 via pre-commit + reviewdog
uses: leinardi/gha-pre-commit-markdownlint-cli2-reviewdog@v1
with:
from-ref: ${{ github.event.pull_request.base.sha }}
to-ref: ${{ github.event.pull_request.head.sha }}
github-token: ${{ secrets.GITHUB_TOKEN }}This will:
- Run
markdownlint-cli2on files changed betweenfrom-refandto-ref. - Post a review with suggested fixes (based on the generated diff).
- Post another review with inline diagnostics.
- Fail the job if violations are found.
It’s recommended to pin to the major version:
uses: leinardi/gha-pre-commit-markdownlint-cli2-reviewdog@v1For fully reproducible behavior, pin to an exact tag:
uses: leinardi/[email protected]