-
Notifications
You must be signed in to change notification settings - Fork 0
249 lines (229 loc) · 8.04 KB
/
docs-validation.yml
File metadata and controls
249 lines (229 loc) · 8.04 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
name: Reusable Documentation Validation
on:
workflow_call:
inputs:
docs-path:
description: 'Path to the docs directory (e.g. "docs")'
required: false
type: string
default: 'docs'
vitepress-path:
description: 'Path to the .vitepress directory (e.g. ".vitepress" or "docs/.vitepress")'
required: false
type: string
default: '.vitepress'
enable-toc-check:
description: 'Enable TOC link validation (requires .vitepress/toc_*.json)'
required: false
type: boolean
default: false
enable-config-js-check:
description: 'Enable .vitepress/config.js syntax check'
required: false
type: boolean
default: false
enable-json-lint:
description: 'Enable TOC JSON file validation'
required: false
type: boolean
default: false
enable-spell-check:
description: 'Enable spell checking'
required: false
type: boolean
default: true
enable-markdown-lint:
description: 'Enable markdown linting'
required: false
type: boolean
default: true
enable-link-check:
description: 'Enable internal link checking'
required: false
type: boolean
default: true
cspell-config:
description: 'Path to cspell config file (relative to caller repo). Leave empty to use shared default.'
required: false
type: string
default: ''
markdownlint-config:
description: 'Path to markdownlint config file (relative to caller repo). Leave empty to use shared default.'
required: false
type: string
default: ''
linkchecker-baseline:
description: 'Path to link checker baseline JSON (relative to caller repo). Leave empty for no baseline.'
required: false
type: string
default: ''
tools-ref:
description: 'Branch/tag of cakephp/.github to use for shared validation tools and default configs'
required: false
type: string
default: 'main'
jobs:
js-lint:
name: Validate config.js
runs-on: ubuntu-latest
if: ${{ inputs.enable-config-js-check }}
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Validate config.js syntax
run: node --check "${{ inputs.vitepress-path }}/config.js"
json-lint:
name: Validate JSON Files
runs-on: ubuntu-latest
if: ${{ inputs.enable-json-lint }}
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Validate JSON syntax
run: |
shopt -s nullglob
files=("${{ inputs.vitepress-path }}"/toc_*.json)
if [ ${#files[@]} -eq 0 ]; then
echo "No ${{ inputs.vitepress-path }}/toc_*.json files found"
exit 1
fi
for file in "${files[@]}"; do
if ! jq empty "$file" 2>/dev/null; then
echo "Invalid JSON: $file"
exit 1
fi
echo "Valid: $file"
done
toc-link-check:
name: Validate TOC Links
runs-on: ubuntu-latest
if: ${{ inputs.enable-toc-check }}
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Checkout shared validation tools
uses: actions/checkout@v6
with:
repository: cakephp/.github
ref: ${{ inputs.tools-ref }}
path: .docs-tools
sparse-checkout: |
docs-validation/check-toc-links.cjs
- name: Check TOC links exist
run: node .docs-tools/docs-validation/check-toc-links.cjs --vitepress-path "${{ inputs.vitepress-path }}" --docs-path "${{ inputs.docs-path }}"
markdown-lint:
name: Lint Markdown
runs-on: ubuntu-latest
if: ${{ inputs.enable-markdown-lint }}
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Checkout shared validation tools
uses: actions/checkout@v6
with:
repository: cakephp/.github
ref: ${{ inputs.tools-ref }}
path: .docs-tools
sparse-checkout: |
docs-validation/.markdownlint-cli2.jsonc
docs-validation/markdownlint-rules
- name: Determine config path
id: config
run: |
if [ -n "${{ inputs.markdownlint-config }}" ]; then
if [ -f "${{ inputs.markdownlint-config }}" ]; then
echo "path=${{ inputs.markdownlint-config }}" >> $GITHUB_OUTPUT
else
echo "Error: markdownlint config '${{ inputs.markdownlint-config }}' does not exist." >&2
exit 1
fi
else
echo "path=.docs-tools/docs-validation/.markdownlint-cli2.jsonc" >> $GITHUB_OUTPUT
fi
- name: Lint markdown files
uses: DavidAnson/markdownlint-cli2-action@v23
with:
config: ${{ steps.config.outputs.path }}
globs: '${{ inputs.docs-path }}/**/*.md'
spell-check:
name: Spell Check
runs-on: ubuntu-latest
if: ${{ inputs.enable-spell-check }}
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Checkout shared validation tools
uses: actions/checkout@v6
with:
repository: cakephp/.github
ref: ${{ inputs.tools-ref }}
path: .docs-tools
sparse-checkout: |
docs-validation/cspell.json
- name: Determine config path
id: config
run: |
if [ -n "${{ inputs.cspell-config }}" ]; then
if [ -f "${{ inputs.cspell-config }}" ]; then
echo "path=${{ inputs.cspell-config }}" >> $GITHUB_OUTPUT
else
echo "Error: cspell config '${{ inputs.cspell-config }}' does not exist." >&2
exit 1
fi
else
echo "path=.docs-tools/docs-validation/cspell.json" >> $GITHUB_OUTPUT
fi
- name: Check spelling
uses: streetsidesoftware/cspell-action@v8
with:
files: '${{ inputs.docs-path }}/**/*.md'
config: ${{ steps.config.outputs.path }}
incremental_files_only: true
link-check:
name: Check Internal Links
runs-on: ubuntu-latest
if: ${{ inputs.enable-link-check }}
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Checkout shared validation tools
uses: actions/checkout@v6
with:
repository: cakephp/.github
ref: ${{ inputs.tools-ref }}
path: .docs-tools
sparse-checkout: |
docs-validation/check-links.cjs
- name: Get changed markdown files
id: changed-files
run: |
DOCS_PATH="${{ inputs.docs-path }}"
if [ "${{ github.event_name }}" == "pull_request" ]; then
BASE_SHA="${{ github.event.pull_request.base.sha }}"
if [ -z "$BASE_SHA" ]; then
git fetch origin "${{ github.base_ref }}" --depth=1 2>/dev/null || true
BASE_SHA="origin/${{ github.base_ref }}"
fi
FILES=$(git diff --name-only --diff-filter=d "${BASE_SHA}"...HEAD | grep "^${DOCS_PATH}/.*\.md$" || true)
if [ -z "$FILES" ]; then
echo "No markdown files changed in ${DOCS_PATH}/"
echo "files=" >> $GITHUB_OUTPUT
else
echo "files=$(echo $FILES | tr '\n' ' ')" >> $GITHUB_OUTPUT
echo "Checking files:"
echo "$FILES"
fi
else
echo "files=${DOCS_PATH}/**/*.md" >> $GITHUB_OUTPUT
echo "Checking all files: ${DOCS_PATH}/**/*.md"
fi
- name: Check internal links
if: steps.changed-files.outputs.files != ''
run: |
BASELINE_ARG=""
if [ -n "${{ inputs.linkchecker-baseline }}" ] && [ -f "${{ inputs.linkchecker-baseline }}" ]; then
BASELINE_ARG="--baseline ${{ inputs.linkchecker-baseline }}"
fi
node .docs-tools/docs-validation/check-links.cjs $BASELINE_ARG ${{ steps.changed-files.outputs.files }}