@@ -15,72 +15,21 @@ jobs:
1515 markdown-lint :
1616 runs-on : ubuntu-latest
1717 steps :
18- - uses : actions/checkout@v6
19- with :
20- fetch-depth : 0 # required to resolve base.sha for PR diff comparison
21- - name : Find changed Markdown files
22- id : changed-markdown
18+ - uses : actions/checkout@v7
19+ - name : List tracked Markdown files
20+ id : tracked-markdown
2321 shell : bash
22+ # Lint git-tracked files only. This lints the canonical versioned dirs
23+ # once and skips the `_latest` symlinks (git stores them as single
24+ # symlink entries, so a filesystem glob would double-lint their targets).
25+ # It also excludes generated reference docs, which are gitignored.
2426 run : |
25- case "${GITHUB_EVENT_NAME}" in
26- pull_request)
27- base_sha="${{ github.event.pull_request.base.sha }}"
28- head_sha="${GITHUB_SHA}"
29- ;;
30- push)
31- base_sha="${{ github.event.before }}"
32- head_sha="${GITHUB_SHA}"
33- ;;
34- *)
35- # workflow_dispatch: lints only files changed in the most recent commit, not the full branch
36- # || true handles initial commits with no parent
37- base_sha="$(git rev-parse "${GITHUB_SHA}^" 2>/dev/null || true)"
38- head_sha="${GITHUB_SHA}"
39- ;;
40- esac
41-
42- if [[ -z "${base_sha}" || "${base_sha}" =~ ^0+$ ]]; then
43- base_sha="$(git rev-list --max-parents=0 "${head_sha}")"
44- fi
45-
46- git diff --name-only --diff-filter=A "${base_sha}" "${head_sha}" -- '*.md' '*.markdown' > added-markdown-files.txt
47- git diff --name-only --diff-filter=CMRT "${base_sha}" "${head_sha}" -- '*.md' '*.markdown' > modified-markdown-files.txt
48-
49- if [[ -s added-markdown-files.txt ]]; then
50- echo "has_added=true" >> "${GITHUB_OUTPUT}"
51- {
52- echo 'added_files<<EOF'
53- cat added-markdown-files.txt
54- echo 'EOF'
55- } >> "${GITHUB_OUTPUT}"
56- else
57- echo "has_added=false" >> "${GITHUB_OUTPUT}"
58- fi
59-
60- if [[ -s modified-markdown-files.txt ]]; then
61- echo "has_modified=true" >> "${GITHUB_OUTPUT}"
62- {
63- echo 'modified_files<<EOF'
64- cat modified-markdown-files.txt
65- echo 'EOF'
66- } >> "${GITHUB_OUTPUT}"
67- else
68- echo "has_modified=false" >> "${GITHUB_OUTPUT}"
69- fi
70-
71- - name : No changed Markdown files
72- if : steps.changed-markdown.outputs.has_added != 'true' && steps.changed-markdown.outputs.has_modified != 'true'
73- run : echo "No changed Markdown files to lint."
74-
75- - name : Lint new Markdown files (enforced)
76- uses : DavidAnson/markdownlint-cli2-action@v23
77- if : steps.changed-markdown.outputs.has_added == 'true'
78- with :
79- globs : ${{ steps.changed-markdown.outputs.added_files }}
80-
81- - name : Lint modified Markdown files (advisory)
82- uses : DavidAnson/markdownlint-cli2-action@v23
83- if : steps.changed-markdown.outputs.has_modified == 'true'
84- continue-on-error : true
27+ {
28+ echo 'files<<EOF'
29+ git ls-files '*.md' '*.markdown'
30+ echo 'EOF'
31+ } >> "${GITHUB_OUTPUT}"
32+ - name : Lint tracked Markdown files
33+ uses : DavidAnson/markdownlint-cli2-action@v24
8534 with :
86- globs : ${{ steps.changed -markdown.outputs.modified_files }}
35+ globs : ${{ steps.tracked -markdown.outputs.files }}
0 commit comments