Skip to content

Commit 8315879

Browse files
committedOct 2, 2021
Add CI workflow to check Markdown files for problems
On every push and pull request that affects relevant files, and periodically, check the repository's Markdown files for problems: - Use markdownlint to check for common problems and formatting. - Use markdown-link-check to check for broken links. The Arduino tooling Markdown style is defined by the `.markdownlint.yml` file. In the event the repository contains externally maintained Markdown files, markdownlint can be configured to ignore them via a `.markdownlintignore` file: https://github.com/igorshubovych/markdownlint-cli#ignoring-files markdown-link-check is configured via the `.markdown-link-check.json` file: https://github.com/tcort/markdown-link-check#config-file-format
1 parent d42bb7e commit 8315879

File tree

4 files changed

+193
-0
lines changed

4 files changed

+193
-0
lines changed
 

Diff for: ‎.github/workflows/check-markdown-task.yml

+66
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

Diff for: ‎.markdown-link-check.json

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

Diff for: ‎.markdownlint.yml

+62
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

Diff for: ‎Taskfile.yml

+60
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ tasks:
2828
-s "{{.WORKFLOW_SCHEMA_PATH}}" \
2929
-d "{{.WORKFLOWS_DATA_PATH}}"
3030
31+
docs:generate:
32+
desc: Create all generated documentation content
33+
# This is an "umbrella" task used to call any documentation generation processes the project has.
34+
# It can be left empty if there are none.
35+
3136
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-general-formatting-task/Taskfile.yml
3237
general:check-formatting:
3338
desc: Check basic formatting style of all files
@@ -61,6 +66,61 @@ tasks:
6166
cmds:
6267
- poetry run codespell --write-changes
6368

69+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
70+
markdown:check-links:
71+
desc: Check for broken links
72+
deps:
73+
- task: docs:generate
74+
cmds:
75+
- |
76+
if [[ "{{.OS}}" == "Windows_NT" ]]; then
77+
# npx --call uses the native shell, which makes it too difficult to use npx for this application on Windows,
78+
# so the Windows user is required to have markdown-link-check installed and in PATH.
79+
if ! which markdown-link-check &>/dev/null; then
80+
echo "markdown-link-check not found or not in PATH. Please install: https://github.com/tcort/markdown-link-check#readme"
81+
exit 1
82+
fi
83+
# Default behavior of the task on Windows is to exit the task when the first broken link causes a non-zero
84+
# exit status, but it's better to check all links before exiting.
85+
set +o errexit
86+
STATUS=0
87+
# Using -regex instead of -name to avoid Task's behavior of globbing even when quoted on Windows
88+
# The odd method for escaping . in the regex is required for windows compatibility because mvdan.cc/sh gives
89+
# \ characters special treatment on Windows in an attempt to support them as path separators.
90+
for file in $(find . -regex ".*[.]md"); do
91+
markdown-link-check \
92+
--quiet \
93+
--config "./.markdown-link-check.json" \
94+
"$file"
95+
STATUS=$(( $STATUS + $? ))
96+
done
97+
exit $STATUS
98+
else
99+
npx --package=markdown-link-check --call='
100+
STATUS=0
101+
for file in $(find . -regex ".*[.]md"); do
102+
markdown-link-check \
103+
--quiet \
104+
--config "./.markdown-link-check.json" \
105+
"$file"
106+
STATUS=$(( $STATUS + $? ))
107+
done
108+
exit $STATUS
109+
'
110+
fi
111+
112+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
113+
markdown:fix:
114+
desc: Automatically correct linting violations in Markdown files where possible
115+
cmds:
116+
- npx markdownlint-cli --fix "**/*.md"
117+
118+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
119+
markdown:lint:
120+
desc: Check for problems in Markdown files
121+
cmds:
122+
- npx markdownlint-cli "**/*.md"
123+
64124
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry-task/Taskfile.yml
65125
poetry:install-deps:
66126
desc: Install dependencies managed by Poetry

0 commit comments

Comments
 (0)
Please sign in to comment.