Skip to content

Commit 349e72a

Browse files
committed
GH Actions: add new check with additional QA for markdown files
While MarkdownLint is absolutely great for finding formatting issues, Remark offers some additional "rules" which are useful, such as checking that links and link definitions match up, verifying all used links work and some additional formatting checks which markdownlint just doesn't offer. The rule configuration is contained in the `.remarkrc` file. Files/directories to be ignored can be listed in the `.remarkignore` file which supports glob syntax, like `.gitignore`. Note: `.`-prefixed files and directories are excluded by default. To include those in the scan, they have to be passed explicitly on the command-line. To run locally, follow the same steps as per the GitHub actions workflow. Note: the workflow contains a double-run of remark-lint to allow viewing the results both in a human readable way in the actions transscripts, as well as getting annotations for found issue in PRs. Notes about the config: * An extensive effort has been made to prevent duplication of messages between the Markdownlint and the Remark check. This includes ensuring there are no conflicting rules. * As the changelog contain a large number of links, at some point the check may run into a rate limit. Excluding contributor links should prevent that for a while. * The file name check does not allow for the file names GitHub requires for issue templates. The provided regex fixes that. * The "undefined references" check doesn't natively understand arrays in frontmatter, nor the new "callout" syntax supported by GitHub. The provided config should prevent false positives for those. Refs: * https://github.com/remarkjs/remark/tree/main/packages/remark-cli * https://github.com/remarkjs/remark-lint * https://github.com/remarkjs/remark-gfm * https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-consistent * https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-recommended * https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide Additional (external) plugins included: * https://github.com/vhf/remark-lint-heading-whitespace * https://github.com/wemake-services/remark-lint-list-item-punctuation * https://github.com/laysent/remark-lint-plugins/tree/HEAD/packages/remark-lint-match-punctuation * https://github.com/olizilla/remark-lint-no-hr-after-heading * https://github.com/remarkjs/remark-lint-no-dead-urls * https://github.com/remarkjs/remark-validate-links
1 parent b2af933 commit 349e72a

File tree

4 files changed

+131
-0
lines changed

4 files changed

+131
-0
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ scripts/ export-ignore
1111
.gitattributes export-ignore
1212
.gitignore export-ignore
1313
.markdownlint-cli2.yaml export-ignore
14+
.remarkignore export-ignore
15+
.remarkrc export-ignore
1416
.yamllint.yml export-ignore
1517
phpcs.xml.dist export-ignore
1618
phpstan.neon.dist export-ignore

.github/workflows/validate.yml

+68
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ on:
44
# Run on all pushes and on all pull requests.
55
push:
66
pull_request:
7+
# Also run this workflow every Monday at 6:00 (to make sure the broken link check runs regularly).
8+
schedule:
9+
- cron: '0 6 * * 1'
710
# Allow manually triggering the workflow.
811
workflow_dispatch:
912

@@ -94,3 +97,68 @@ jobs:
9497
# @link https://github.com/marketplace/actions/markdownlint-cli2-action
9598
- name: Check markdown with CLI2
9699
uses: DavidAnson/markdownlint-cli2-action@v16
100+
101+
remark:
102+
name: 'QA Markdown'
103+
runs-on: ubuntu-latest
104+
105+
# Don't run the cronjob in this workflow on forks.
106+
if: github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'PHPCSStandards')
107+
108+
steps:
109+
- name: Checkout code
110+
uses: actions/checkout@v4
111+
112+
- name: Set up node and enable caching of dependencies
113+
uses: actions/setup-node@v4
114+
with:
115+
node-version: "20"
116+
117+
# To make the command available on CLI, it needs to be installed globally.
118+
- name: Install Remark CLI globally
119+
run: npm install --global remark-cli --foreground-scripts true --fund false
120+
121+
# To allow for creating a custom config which references rules which are included
122+
# in the presets, without having to install all rules individually, a local install
123+
# works best (and installing the presets in the first place, of course).
124+
#
125+
# Note: the first group of packages are all part of the mono "Remark lint" repo.
126+
# The second group of packages (heading-whitespace and down) are additional
127+
# "external" rules/plugins.
128+
- name: Install Remark rules locally
129+
run: >
130+
npm install --foreground-scripts true --fund false
131+
remark-lint
132+
remark-gfm
133+
remark-preset-lint-consistent
134+
remark-preset-lint-recommended
135+
remark-preset-lint-markdown-style-guide
136+
remark-lint-checkbox-content-indent
137+
remark-lint-linebreak-style
138+
remark-lint-no-dead-urls
139+
remark-lint-no-duplicate-defined-urls
140+
remark-lint-no-empty-url
141+
remark-lint-no-heading-like-paragraph
142+
remark-lint-no-reference-like-url
143+
remark-lint-no-unneeded-full-reference-image
144+
remark-lint-no-unneeded-full-reference-link
145+
remark-lint-strikethrough-marker
146+
remark-lint-heading-whitespace
147+
remark-lint-list-item-punctuation
148+
remark-lint-match-punctuation
149+
remark-lint-no-hr-after-heading
150+
remark-lint-are-links-valid-duplicate
151+
remark-validate-links
152+
153+
- name: Run Remark-lint
154+
run: remark . --frail
155+
156+
# @link https://github.com/reviewdog/action-remark-lint
157+
- name: Show Remark-lint annotations in PR
158+
if: ${{ failure() && github.event_name == 'pull_request' }}
159+
uses: reviewdog/action-remark-lint@v5
160+
with:
161+
fail_on_error: true
162+
install_deps: false
163+
level: info
164+
reporter: github-pr-check

.remarkignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore rules for Remark.
2+
# Docs: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/ignore.md
3+
4+
/node_modules/
5+
/vendor/

.remarkrc

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"plugins": [
3+
"remark-gfm",
4+
["remark-lint-checkbox-character-style", "consistent"],
5+
["remark-lint-checkbox-content-indent", "consistent"],
6+
"remark-lint-definition-spacing",
7+
"remark-lint-file-extension",
8+
["remark-lint-linebreak-style", "unix"],
9+
["remark-lint-link-title-style", "\""],
10+
["remark-lint-ordered-list-marker-style", "."],
11+
[
12+
"remark-lint-no-dead-urls",
13+
{
14+
"skipUrlPatterns": [
15+
"^https?://github\\.com/PHPCSStandards/PHP_CodeSniffer/compare/[0-9\\.]+?\\.{3}[0-9\\.]+",
16+
"^https?://github\\.com/[A-Za-z0-9-]+"
17+
]
18+
}
19+
],
20+
"remark-lint-no-duplicate-defined-urls",
21+
"remark-lint-no-duplicate-definitions",
22+
"remark-lint-no-empty-url",
23+
"remark-lint-no-file-name-consecutive-dashes",
24+
["remark-lint-no-file-name-irregular-characters", "\\.a-zA-Z0-9-_"],
25+
"remark-lint-no-file-name-outer-dashes",
26+
"remark-lint-no-heading-like-paragraph",
27+
"remark-lint-no-literal-urls",
28+
"remark-lint-no-reference-like-url",
29+
"remark-lint-no-shortcut-reference-image",
30+
"remark-lint-no-table-indentation",
31+
[
32+
"remark-lint-no-undefined-references",
33+
{
34+
"allow": [
35+
"!NOTE",
36+
"!TIP",
37+
"!IMPORTANT",
38+
"!WARNING",
39+
"!CAUTION",
40+
"'Status: triage', 'Type: bug'",
41+
"'Status: triage', 'Type: enhancement'"
42+
]
43+
}
44+
],
45+
"remark-lint-no-unneeded-full-reference-image",
46+
"remark-lint-no-unneeded-full-reference-link",
47+
"remark-lint-no-unused-definitions",
48+
["remark-lint-strikethrough-marker", "~~"],
49+
"remark-lint-heading-whitespace",
50+
"remark-lint-list-item-punctuation",
51+
"remark-lint-match-punctuation",
52+
"remark-lint-no-hr-after-heading",
53+
"remark-lint-are-links-valid-duplicate",
54+
"remark-validate-links"
55+
]
56+
}

0 commit comments

Comments
 (0)