Skip to content

Commit b8f9093

Browse files
authored
Merge pull request #12 from arduino/scerza/markdown-check
Add CI workflow to check Markdown files for problems
2 parents 3c03747 + dfe6045 commit b8f9093

File tree

4 files changed

+193
-0
lines changed

4 files changed

+193
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-markdown-task.md
2+
name: Check Markdown
3+
4+
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
5+
on:
6+
push:
7+
paths:
8+
- ".github/workflows/check-markdown-task.ya?ml"
9+
- ".markdown-link-check.json"
10+
- "Taskfile.ya?ml"
11+
- "**/.markdownlint*"
12+
- "**.mdx?"
13+
- "**.mkdn"
14+
- "**.mdown"
15+
- "**.markdown"
16+
pull_request:
17+
paths:
18+
- ".github/workflows/check-markdown-task.ya?ml"
19+
- ".markdown-link-check.json"
20+
- "Taskfile.ya?ml"
21+
- "**/.markdownlint*"
22+
- "**.mdx?"
23+
- "**.mkdn"
24+
- "**.mdown"
25+
- "**.markdown"
26+
schedule:
27+
# Run every Tuesday at 8 AM UTC to catch breakage caused by external changes.
28+
- cron: "0 8 * * TUE"
29+
workflow_dispatch:
30+
repository_dispatch:
31+
32+
jobs:
33+
lint:
34+
runs-on: ubuntu-latest
35+
36+
steps:
37+
- name: Checkout repository
38+
uses: actions/checkout@v2
39+
40+
- name: Initialize markdownlint-cli problem matcher
41+
uses: xt0rted/markdownlint-problem-matcher@v1
42+
43+
- name: Install Task
44+
uses: arduino/setup-task@v1
45+
with:
46+
repo-token: ${{ secrets.GITHUB_TOKEN }}
47+
version: 3.x
48+
49+
- name: Lint
50+
run: task markdown:lint
51+
52+
links:
53+
runs-on: ubuntu-latest
54+
55+
steps:
56+
- name: Checkout repository
57+
uses: actions/checkout@v2
58+
59+
- name: Install Task
60+
uses: arduino/setup-task@v1
61+
with:
62+
repo-token: ${{ secrets.GITHUB_TOKEN }}
63+
version: 3.x
64+
65+
- name: Check links
66+
run: task --silent markdown:check-links

.markdown-link-check.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"retryOn429": true,
3+
"retryCount": 3,
4+
"aliveStatusCodes": [200, 206]
5+
}

.markdownlint.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown/.markdownlint.yml
2+
# See: https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md
3+
# The code style defined in this file is the official standardized style to be used in all Arduino projects and should
4+
# not be modified.
5+
# Note: Rules disabled solely because they are redundant to Prettier are marked with a "Prettier" comment.
6+
7+
default: false
8+
MD001: false
9+
MD002: false
10+
MD003: false # Prettier
11+
MD004: false # Prettier
12+
MD005: false # Prettier
13+
MD006: false # Prettier
14+
MD007: false # Prettier
15+
MD008: false # Prettier
16+
MD009:
17+
br_spaces: 0
18+
strict: true
19+
list_item_empty_lines: false # Prettier
20+
MD010: false # Prettier
21+
MD011: true
22+
MD012: false # Prettier
23+
MD013: false
24+
MD014: false
25+
MD018: true
26+
MD019: false # Prettier
27+
MD020: true
28+
MD021: false # Prettier
29+
MD022: false # Prettier
30+
MD023: false # Prettier
31+
MD024: false
32+
MD025:
33+
level: 1
34+
front_matter_title: '^\s*"?title"?\s*[:=]'
35+
MD026: false
36+
MD027: false # Prettier
37+
MD028: false
38+
MD029:
39+
style: one
40+
MD030:
41+
ul_single: 1
42+
ol_single: 1
43+
ul_multi: 1
44+
ol_multi: 1
45+
MD031: false # Prettier
46+
MD032: false # Prettier
47+
MD033: false
48+
MD034: false
49+
MD035: false # Prettier
50+
MD036: false
51+
MD037: true
52+
MD038: true
53+
MD039: true
54+
MD040: false
55+
MD041: false
56+
MD042: true
57+
MD043: false
58+
MD044: false
59+
MD045: true
60+
MD046:
61+
style: fenced
62+
MD047: false # Prettier

Taskfile.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,63 @@ tasks:
6969
desc: Format all supported files with Prettier
7070
cmds:
7171
- npx prettier --write .
72+
73+
docs:generate:
74+
desc: Create all generated documentation content
75+
# This is an "umbrella" task used to call any documentation generation processes the project has.
76+
# It can be left empty if there are none.
77+
78+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
79+
markdown:lint:
80+
desc: Check for problems in Markdown files
81+
cmds:
82+
- npx markdownlint-cli "**/*.md"
83+
84+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
85+
markdown:fix:
86+
desc: Automatically correct linting violations in Markdown files where possible
87+
cmds:
88+
- npx markdownlint-cli --fix "**/*.md"
89+
90+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
91+
markdown:check-links:
92+
desc: Check for broken links
93+
deps:
94+
- task: docs:generate
95+
cmds:
96+
- |
97+
if [[ "{{.OS}}" == "Windows_NT" ]]; then
98+
# npx --call uses the native shell, which makes it too difficult to use npx for this application on Windows,
99+
# so the Windows user is required to have markdown-link-check installed and in PATH.
100+
if ! which markdown-link-check &>/dev/null; then
101+
echo "markdown-link-check not found or not in PATH. Please install: https://github.com/tcort/markdown-link-check#readme"
102+
exit 1
103+
fi
104+
# Default behavior of the task on Windows is to exit the task when the first broken link causes a non-zero
105+
# exit status, but it's better to check all links before exiting.
106+
set +o errexit
107+
STATUS=0
108+
# Using -regex instead of -name to avoid Task's behavior of globbing even when quoted on Windows
109+
# The odd method for escaping . in the regex is required for windows compatibility because mvdan.cc/sh gives
110+
# \ characters special treatment on Windows in an attempt to support them as path separators.
111+
for file in $(find . -regex ".*[.]md"); do
112+
markdown-link-check \
113+
--quiet \
114+
--config "./.markdown-link-check.json" \
115+
"$file"
116+
STATUS=$(( $STATUS + $? ))
117+
done
118+
exit $STATUS
119+
else
120+
npx --package=markdown-link-check --call='
121+
STATUS=0
122+
for file in $(find . -regex ".*[.]md"); do
123+
markdown-link-check \
124+
--quiet \
125+
--config "./.markdown-link-check.json" \
126+
"$file"
127+
STATUS=$(( $STATUS + $? ))
128+
done
129+
exit $STATUS
130+
'
131+
fi

0 commit comments

Comments
 (0)