-
Notifications
You must be signed in to change notification settings - Fork 3
142 lines (118 loc) · 4.31 KB
/
markdown-lint.yaml
File metadata and controls
142 lines (118 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: Markdown Lint
on:
workflow_dispatch:
pull_request:
branches:
- main
- "release/**"
push:
branches:
- main
jobs:
markdown-lint:
name: Markdown Lint Check
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Cache markdownlint-cli2
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-markdownlint-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-markdownlint-
- name: Install markdownlint-cli2
run: npm install -g markdownlint-cli2
- name: Get changed files
id: changed-files
if: github.event_name == 'pull_request'
uses: tj-actions/changed-files@v46
with:
files: |
**.md
**.mdx
separator: " "
- name: Run markdownlint on changed files (PR)
if: github.event_name == 'pull_request' && steps.changed-files.outputs.any_changed == 'true'
run: |
echo "Running markdownlint on changed files:"
echo "${{ steps.changed-files.outputs.all_changed_files }}"
FILTERED_FILES=""
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
if [[ -f "$file" ]]; then
FILTERED_FILES="$FILTERED_FILES $file"
fi
done
if [[ -n "$FILTERED_FILES" ]]; then
echo "Linting files: $FILTERED_FILES"
markdownlint-cli2 $FILTERED_FILES
else
echo "No markdown files to lint after filtering"
echo "no_files_to_lint=true" >> $GITHUB_ENV
exit 0
fi
- name: Comment success on PR (no files to lint)
if: github.event_name == 'pull_request' && env.no_files_to_lint == 'true'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: markdown-lint
message: |
## ✅ Markdown Lint Passed
No markdown files needed linting in this PR! 🎉
- name: Run markdownlint on all files (push to main)
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
run: |
echo "Running markdownlint on all markdown files"
markdownlint-cli2 "**/*.{md,mdx}"
- name: Upload markdownlint results
if: failure()
uses: actions/upload-artifact@v4
with:
name: markdownlint-results
path: |
.markdownlint-cli2.jsonc
markdownlint-results.txt
retention-days: 5
- name: Comment on PR with markdown issues
if: failure() && github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: markdown-lint
message: |
## ❌ Markdown Lint Issues Found
Markdownlint found issues in the changed markdown files. Please review and fix them:
### Files checked:
${{ steps.changed-files.outputs.all_changed_files }}
### To fix locally:
1. Install markdownlint-cli2:
```bash
npm install -g markdownlint-cli2
```
2. Run on specific files:
```bash
markdownlint-cli2 path/to/your/file.md
```
3. Or run on all files:
```bash
markdownlint-cli2 "**/*.{md,mdx}" --config .markdownlint.jsonc
```
See the [markdownlint rules documentation](https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md) for details on each rule.
- name: Comment success on PR
if: success() && github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: markdown-lint
message: |
## ✅ Markdown Lint Passed
All markdown files meet the linting standards! 🎉