forked from apache/fesod
-
Notifications
You must be signed in to change notification settings - Fork 1
59 lines (54 loc) · 2.09 KB
/
markdownlint.yml
File metadata and controls
59 lines (54 loc) · 2.09 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
name: Markdown Lint
on:
pull_request:
paths:
- '**/*.md'
push:
paths:
- '**/*.md'
jobs:
markdownlint:
if: github.event_name == 'push' || github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install markdownlint-cli2
run: npm install -g markdownlint-cli2
- name: Run markdownlint
id: lint
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
CHANGED_MD=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }}...${{ github.event.pull_request.head.ref }} | grep -E '\.md$' || true)
else
CHANGED_MD=$(git diff-tree --no-commit-id --name-only -r ${{ github.sha }} | grep -E '\.md$' || true)
fi
if [ -n "$CHANGED_MD" ]; then
markdownlint-cli2 "$CHANGED_MD" --config website/.markdownlint-cli2.jsonc > lint-result.txt || true
if [ -s lint-result.txt ]; then
echo "Lint failed."
# Output non-compliant file contents to comment-body.txt
for file in $CHANGED_MD; do
echo "\n---\n**$file Content:**\n" >> comment-body.txt
echo '\n```markdown' >> comment-body.txt
cat "$file" >> comment-body.txt
echo '\n```' >> comment-body.txt
done
echo "\n---\n**Lint Results:**\n" >> comment-body.txt
cat lint-result.txt >> comment-body.txt
exit 1
fi
else
echo "No markdown files changed, skipping lint."
fi
- name: Create PR comment with lint result
if: failure() && steps.lint.conclusion == 'failure' && github.event_name == 'pull_request'
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body-file: comment-body.txt