Skip to content

Commit dc9ef24

Browse files
committed
address reviews
1 parent 8c4bf31 commit dc9ef24

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

.github/workflows/docs-validation-reusable.yml

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@ on:
44
workflow_call:
55
inputs:
66
docs-path:
7-
description: 'Path to the docs directory (e.g. "docs/")'
7+
description: 'Path to the docs directory (e.g. "docs")'
88
required: false
99
type: string
10-
default: 'docs/'
11-
markdown-glob:
12-
description: 'Glob pattern for markdown files'
13-
required: false
14-
type: string
15-
default: 'docs/**/*.md'
10+
default: 'docs'
1611
enable-toc-check:
1712
description: 'Enable TOC link validation (requires .vitepress/toc_*.json)'
1813
required: false
@@ -86,7 +81,13 @@ jobs:
8681

8782
- name: Validate JSON syntax
8883
run: |
89-
for file in .vitepress/toc_*.json; do
84+
shopt -s nullglob
85+
files=(.vitepress/toc_*.json)
86+
if [ ${#files[@]} -eq 0 ]; then
87+
echo "No .vitepress/toc_*.json files found"
88+
exit 1
89+
fi
90+
for file in "${files[@]}"; do
9091
if ! jq empty "$file" 2>/dev/null; then
9192
echo "Invalid JSON: $file"
9293
exit 1
@@ -135,8 +136,13 @@ jobs:
135136
- name: Determine config path
136137
id: config
137138
run: |
138-
if [ -n "${{ inputs.markdownlint-config }}" ] && [ -f "${{ inputs.markdownlint-config }}" ]; then
139-
echo "path=${{ inputs.markdownlint-config }}" >> $GITHUB_OUTPUT
139+
if [ -n "${{ inputs.markdownlint-config }}" ]; then
140+
if [ -f "${{ inputs.markdownlint-config }}" ]; then
141+
echo "path=${{ inputs.markdownlint-config }}" >> $GITHUB_OUTPUT
142+
else
143+
echo "Error: markdownlint config '${{ inputs.markdownlint-config }}' does not exist." >&2
144+
exit 1
145+
fi
140146
else
141147
echo "path=.docs-tools/.github/.markdownlint-cli2.jsonc" >> $GITHUB_OUTPUT
142148
fi
@@ -145,7 +151,7 @@ jobs:
145151
uses: DavidAnson/markdownlint-cli2-action@v23
146152
with:
147153
config: ${{ steps.config.outputs.path }}
148-
globs: ${{ inputs.markdown-glob }}
154+
globs: '${{ inputs.docs-path }}/**/*.md'
149155

150156
spell-check:
151157
name: Spell Check
@@ -167,16 +173,21 @@ jobs:
167173
- name: Determine config path
168174
id: config
169175
run: |
170-
if [ -n "${{ inputs.cspell-config }}" ] && [ -f "${{ inputs.cspell-config }}" ]; then
171-
echo "path=${{ inputs.cspell-config }}" >> $GITHUB_OUTPUT
176+
if [ -n "${{ inputs.cspell-config }}" ]; then
177+
if [ -f "${{ inputs.cspell-config }}" ]; then
178+
echo "path=${{ inputs.cspell-config }}" >> $GITHUB_OUTPUT
179+
else
180+
echo "Error: cspell config '${{ inputs.cspell-config }}' does not exist." >&2
181+
exit 1
182+
fi
172183
else
173184
echo "path=.docs-tools/.github/cspell.json" >> $GITHUB_OUTPUT
174185
fi
175186
176187
- name: Check spelling
177188
uses: streetsidesoftware/cspell-action@v8
178189
with:
179-
files: ${{ inputs.markdown-glob }}
190+
files: '${{ inputs.docs-path }}/**/*.md'
180191
config: ${{ steps.config.outputs.path }}
181192
incremental_files_only: true
182193

@@ -202,19 +213,25 @@ jobs:
202213
- name: Get changed markdown files
203214
id: changed-files
204215
run: |
216+
DOCS_PATH="${{ inputs.docs-path }}"
205217
if [ "${{ github.event_name }}" == "pull_request" ]; then
206-
FILES=$(git diff --name-only --diff-filter=d origin/${{ github.base_ref }}...HEAD | grep '\.md$' || true)
218+
BASE_SHA="${{ github.event.pull_request.base.sha }}"
219+
if [ -z "$BASE_SHA" ]; then
220+
git fetch origin "${{ github.base_ref }}" --depth=1 2>/dev/null || true
221+
BASE_SHA="origin/${{ github.base_ref }}"
222+
fi
223+
FILES=$(git diff --name-only --diff-filter=d "${BASE_SHA}"...HEAD | grep "^${DOCS_PATH}/.*\.md$" || true)
207224
if [ -z "$FILES" ]; then
208-
echo "No markdown files changed"
225+
echo "No markdown files changed in ${DOCS_PATH}/"
209226
echo "files=" >> $GITHUB_OUTPUT
210227
else
211228
echo "files=$(echo $FILES | tr '\n' ' ')" >> $GITHUB_OUTPUT
212229
echo "Checking files:"
213230
echo "$FILES"
214231
fi
215232
else
216-
echo "files=${{ inputs.markdown-glob }}" >> $GITHUB_OUTPUT
217-
echo "Checking all files: ${{ inputs.markdown-glob }}"
233+
echo "files=${DOCS_PATH}/**/*.md" >> $GITHUB_OUTPUT
234+
echo "Checking all files: ${DOCS_PATH}/**/*.md"
218235
fi
219236
220237
- name: Check internal links

.github/workflows/docs-validation.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
# TODO: Change back to @5.x after merging this PR
2424
uses: cakephp/docs/.github/workflows/docs-validation-reusable.yml@reusable-validation-workflow
2525
with:
26+
docs-path: 'docs'
2627
enable-config-js-check: true
2728
enable-json-lint: true
2829
enable-toc-check: true

0 commit comments

Comments
 (0)