Skip to content

Commit 672afa2

Browse files
alaahongCopilot
andauthored
chore: add markdown lint check for markdown files on push and pull request (#497)
* chore: add markdown lint check for markdown files on push and pull request * Update .github/workflows/markdownlint.yml Co-authored-by: Copilot <[email protected]> * Update .github/workflows/markdownlint.yml Co-authored-by: Copilot <[email protected]> * Update .github/workflows/markdownlint.yml Co-authored-by: Copilot <[email protected]> * Update .github/workflows/markdownlint.yml Co-authored-by: Copilot <[email protected]> * Update .github/workflows/markdownlint.yml Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent a6567b0 commit 672afa2

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

.github/workflows/markdownlint.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Markdown Lint
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '**/*.md'
7+
push:
8+
paths:
9+
- '**/*.md'
10+
11+
jobs:
12+
markdownlint:
13+
if: github.event_name == 'push' || github.event_name == 'pull_request'
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '20'
23+
24+
- name: Install markdownlint-cli2
25+
run: npm install -g markdownlint-cli2
26+
27+
- name: Run markdownlint
28+
id: lint
29+
run: |
30+
if [ "${{ github.event_name }}" = "pull_request" ]; then
31+
CHANGED_MD=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }}...${{ github.event.pull_request.head.ref }} | grep -E '\.md$' || true)
32+
else
33+
CHANGED_MD=$(git diff-tree --no-commit-id --name-only -r ${{ github.sha }} | grep -E '\.md$' || true)
34+
fi
35+
if [ -n "$CHANGED_MD" ]; then
36+
markdownlint-cli2 "$CHANGED_MD" --config website/.markdownlint-cli2.jsonc > lint-result.txt || true
37+
if [ -s lint-result.txt ]; then
38+
echo "Lint failed."
39+
# Output non-compliant file contents to comment-body.txt
40+
for file in $CHANGED_MD; do
41+
echo "\n---\n**$file Content:**\n" >> comment-body.txt
42+
echo '\n```markdown' >> comment-body.txt
43+
cat "$file" >> comment-body.txt
44+
echo '\n```' >> comment-body.txt
45+
done
46+
echo "\n---\n**Lint Results:**\n" >> comment-body.txt
47+
cat lint-result.txt >> comment-body.txt
48+
exit 1
49+
fi
50+
else
51+
echo "No markdown files changed, skipping lint."
52+
fi
53+
- name: Create PR comment with lint result
54+
if: failure() && steps.lint.conclusion == 'failure' && github.event_name == 'pull_request'
55+
uses: peter-evans/create-or-update-comment@v4
56+
with:
57+
token: ${{ secrets.GITHUB_TOKEN }}
58+
issue-number: ${{ github.event.pull_request.number }}
59+
body-file: comment-body.txt

0 commit comments

Comments
 (0)