Skip to content

Commit 62e80d3

Browse files
committed
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 9e2f592 commit 62e80d3

8 files changed

+1311
-2
lines changed
+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-markdown-task.md
2+
name: Check Markdown
3+
4+
env:
5+
# See: https://github.com/actions/setup-node/#readme
6+
NODE_VERSION: 16.x
7+
8+
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
9+
on:
10+
create:
11+
push:
12+
paths:
13+
- ".github/workflows/check-markdown-task.ya?ml"
14+
- ".markdown-link-check.json"
15+
- "package.json"
16+
- "package-lock.json"
17+
- "Taskfile.ya?ml"
18+
- "**/.markdownlint*"
19+
- "**.mdx?"
20+
- "**.mkdn"
21+
- "**.mdown"
22+
- "**.markdown"
23+
pull_request:
24+
paths:
25+
- ".github/workflows/check-markdown-task.ya?ml"
26+
- ".markdown-link-check.json"
27+
- "package.json"
28+
- "package-lock.json"
29+
- "Taskfile.ya?ml"
30+
- "**/.markdownlint*"
31+
- "**.mdx?"
32+
- "**.mkdn"
33+
- "**.mdown"
34+
- "**.markdown"
35+
schedule:
36+
# Run every Tuesday at 8 AM UTC to catch breakage caused by external changes.
37+
- cron: "0 8 * * TUE"
38+
workflow_dispatch:
39+
repository_dispatch:
40+
41+
jobs:
42+
run-determination:
43+
runs-on: ubuntu-latest
44+
outputs:
45+
result: ${{ steps.determination.outputs.result }}
46+
steps:
47+
- name: Determine if the rest of the workflow should run
48+
id: determination
49+
run: |
50+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
51+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
52+
if [[
53+
"${{ github.event_name }}" != "create" ||
54+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
55+
]]; then
56+
# Run the other jobs.
57+
RESULT="true"
58+
else
59+
# There is no need to run the other jobs.
60+
RESULT="false"
61+
fi
62+
63+
echo "result=$RESULT" >> $GITHUB_OUTPUT
64+
65+
lint:
66+
needs: run-determination
67+
if: needs.run-determination.outputs.result == 'true'
68+
runs-on: ubuntu-latest
69+
70+
steps:
71+
- name: Checkout repository
72+
uses: actions/checkout@v3
73+
74+
- name: Setup Node.js
75+
uses: actions/setup-node@v3
76+
with:
77+
node-version: ${{ env.NODE_VERSION }}
78+
79+
- name: Initialize markdownlint-cli problem matcher
80+
uses: xt0rted/markdownlint-problem-matcher@v2
81+
82+
- name: Install Task
83+
uses: arduino/setup-task@v1
84+
with:
85+
repo-token: ${{ secrets.GITHUB_TOKEN }}
86+
version: 3.x
87+
88+
- name: Lint
89+
run: task markdown:lint
90+
91+
links:
92+
needs: run-determination
93+
if: needs.run-determination.outputs.result == 'true'
94+
runs-on: ubuntu-latest
95+
96+
steps:
97+
- name: Checkout repository
98+
uses: actions/checkout@v3
99+
100+
- name: Setup Node.js
101+
uses: actions/setup-node@v3
102+
with:
103+
node-version: ${{ env.NODE_VERSION }}
104+
105+
- name: Install Task
106+
uses: arduino/setup-task@v1
107+
with:
108+
repo-token: ${{ secrets.GITHUB_TOKEN }}
109+
version: 3.x
110+
111+
- name: Check links
112+
run: task --silent markdown:check-links

.markdown-link-check.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"httpHeaders": [
3+
{
4+
"urls": ["https://docs.github.com/"],
5+
"headers": {
6+
"Accept-Encoding": "gzip, deflate, br"
7+
}
8+
}
9+
],
10+
"retryOn429": true,
11+
"retryCount": 3,
12+
"aliveStatusCodes": [200, 206]
13+
}

.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

.markdownlintignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown/.markdownlintignore
2+
.licenses/
3+
__pycache__/
4+
node_modules/

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![Check Files status](https://github.com/arduino/compile-sketches/actions/workflows/check-files-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-files-task.yml)
55
[![Check General Formatting status](https://github.com/arduino/compile-sketches/actions/workflows/check-general-formatting-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-general-formatting-task.yml)
66
[![Check License status](https://github.com/arduino/compile-sketches/actions/workflows/check-license.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-license.ym
7+
[![Check Markdown status](https://github.com/arduino/compile-sketches/actions/workflows/check-markdown-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-markdown-task.yml)
78
[![Check Python status](https://github.com/arduino/compile-sketches/actions/workflows/check-python-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-python-task.yml)
89
[![Spell Check status](https://github.com/arduino/compile-sketches/actions/workflows/spell-check-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/spell-check-task.yml)
910
[![Sync Labels status](https://github.com/arduino/compile-sketches/actions/workflows/sync-labels-npm.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/sync-labels-npm.yml)

Taskfile.yml

+83
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ tasks:
1111
- task: action:validate
1212
- task: general:check-formatting
1313
- task: general:check-spelling
14+
- task: markdown:check-links
15+
- task: markdown:lint
1416
- task: python:lint
1517
- task: python:test
1618

1719
fix:
1820
desc: Make automated corrections to the project's files
1921
deps:
2022
- task: general:correct-spelling
23+
- task: markdown:fix
2124
- task: python:format
2225

2326
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-action-metadata-task/Taskfile.yml
@@ -42,6 +45,11 @@ tasks:
4245
-s "{{.ACTION_METADATA_SCHEMA_PATH}}" \
4346
-d "action.yml"
4447
48+
docs:generate:
49+
desc: Create all generated documentation content
50+
# This is an "umbrella" task used to call any documentation generation processes the project has.
51+
# It can be left empty if there are none.
52+
4553
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-files-task/Taskfile.yml
4654
general:check-filenames:
4755
desc: Check for non-portable filenames
@@ -171,6 +179,81 @@ tasks:
171179
cmds:
172180
- poetry run codespell --write-changes
173181

182+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
183+
markdown:check-links:
184+
desc: Check for broken links
185+
deps:
186+
- task: docs:generate
187+
- task: npm:install-deps
188+
cmds:
189+
- |
190+
if [[ "{{.OS}}" == "Windows_NT" ]]; then
191+
# npx --call uses the native shell, which makes it too difficult to use npx for this application on Windows,
192+
# so the Windows user is required to have markdown-link-check installed and in PATH.
193+
if ! which markdown-link-check &>/dev/null; then
194+
echo "markdown-link-check not found or not in PATH."
195+
echo "Please install: https://github.com/tcort/markdown-link-check#readme"
196+
exit 1
197+
fi
198+
# Default behavior of the task on Windows is to exit the task when the first broken link causes a non-zero
199+
# exit status, but it's better to check all links before exiting.
200+
set +o errexit
201+
STATUS=0
202+
# Using -regex instead of -name to avoid Task's behavior of globbing even when quoted on Windows
203+
# The odd method for escaping . in the regex is required for windows compatibility because mvdan.cc/sh gives
204+
# \ characters special treatment on Windows in an attempt to support them as path separators.
205+
for file in $(
206+
find . \
207+
-type d -name '.git' -prune -o \
208+
-type d -name '.licenses' -prune -o \
209+
-type d -name '__pycache__' -prune -o \
210+
-type d -name 'node_modules' -prune -o \
211+
-regex ".*[.]md" -print
212+
); do
213+
markdown-link-check \
214+
--quiet \
215+
--config "./.markdown-link-check.json" \
216+
"$file"
217+
STATUS=$(( $STATUS + $? ))
218+
done
219+
exit $STATUS
220+
else
221+
npx --package=markdown-link-check --call='
222+
STATUS=0
223+
for file in $(
224+
find . \
225+
-type d -name '.git' -prune -o \
226+
-type d -name '.licenses' -prune -o \
227+
-type d -name '__pycache__' -prune -o \
228+
-type d -name 'node_modules' -prune -o \
229+
-regex ".*[.]md" -print
230+
); do
231+
markdown-link-check \
232+
--quiet \
233+
--config "./.markdown-link-check.json" \
234+
"$file"
235+
STATUS=$(( $STATUS + $? ))
236+
done
237+
exit $STATUS
238+
'
239+
fi
240+
241+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
242+
markdown:fix:
243+
desc: Automatically correct linting violations in Markdown files where possible
244+
deps:
245+
- task: npm:install-deps
246+
cmds:
247+
- npx markdownlint-cli --fix "**/*.md"
248+
249+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
250+
markdown:lint:
251+
desc: Check for problems in Markdown files
252+
deps:
253+
- task: npm:install-deps
254+
cmds:
255+
- npx markdownlint-cli "**/*.md"
256+
174257
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/npm-task/Taskfile.yml
175258
npm:install-deps:
176259
desc: Install dependencies managed by npm

0 commit comments

Comments
 (0)