Skip to content

Commit 524d074

Browse files
committed
github action mdformat
Ensure all markdown files are formatted in compliance with CommonMark using the mdformat tool.
1 parent b495549 commit 524d074

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

.cspell/project-words.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ gitspell
33
shellcheck
44
shfmt
55
yamlfix
6+
mdformat

.github/actions/mdformat/action.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
name: mdformat
3+
description: Checks CommonMark formatting of md files with mdformat
4+
runs:
5+
using: composite
6+
steps:
7+
- run: pip install mdformat
8+
shell: bash
9+
- run: echo "::add-matcher::.github/matchers/fmt.json"
10+
shell: bash
11+
- run: ./scripts/mdformat.sh
12+
shell: bash

.github/workflows/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,8 @@ jobs:
6060
steps:
6161
- uses: actions/checkout@v4
6262
- uses: ./.github/actions/yamlfix
63+
mdformat:
64+
runs-on: ubuntu-latest
65+
steps:
66+
- uses: actions/checkout@v4
67+
- uses: ./.github/actions/mdformat

scripts/mdformat.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
mdformat --version
3+
EXIT_CODE=0
4+
FILES=$(find . -name "*.md")
5+
for FILE in $FILES; do
6+
if [ "$1" == "--diff" ]; then
7+
cp "$FILE" "$FILE.temp"
8+
mdformat "$FILE.temp"
9+
if ! diff --unified "$FILE" "$FILE.temp"; then
10+
EXIT_CODE=1
11+
fi
12+
rm "$FILE.temp"
13+
elif [ "$1" == "--apply" ]; then
14+
mdformat "$FILE"
15+
else
16+
if ! mdformat --check "$FILE" 2>/dev/null; then
17+
printf "%s;; \`mdformat\` would format this file. It should comply with CommonMark. Use \`./scripts/mdformat.sh --diff\` to see the changes it would make and \`./scripts/mdformat.sh --apply\` to apply them.\n" "$FILE"
18+
EXIT_CODE=1
19+
fi
20+
fi
21+
done
22+
23+
exit "$EXIT_CODE"

0 commit comments

Comments
 (0)