diff --git a/.github/workflows/changed.yml b/.github/workflows/changed.yml new file mode 100644 index 0000000..84f6b39 --- /dev/null +++ b/.github/workflows/changed.yml @@ -0,0 +1,18 @@ +on: [push, pull_request] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 2 + - uses: tj-actions/changed-files@v24 + id: changed-files + with: + files: '**/*.md' + separator: "\n" + - uses: DavidAnson/markdownlint-cli2-action@v6 + if: steps.changed-files.outputs.any_changed == 'true' + with: + globs: ${{ steps.changed-files.outputs.all_changed_files }} diff --git a/README.md b/README.md index 7b557b5..ed4d4e4 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,11 @@ To prevent linting issues from failing the workflow run: See [`example.yml`][example-yml] for a simple GitHub workflow that uses `markdownlint-cli2-action`. +See [`changed.yml`][changed-yml] for a GitHub workflow that lints only the +Markdown files that changed in the most recent commit (useful for Pull +Requests and/or gradually introducing linting rules to a new repository). + +[changed-yml]: .github/workflows/changed.yml [command-line]: https://github.com/DavidAnson/markdownlint-cli2#command-line [commonmark]: https://commonmark.org/ [example-yml]: .github/workflows/example.yml