Skip to content

Commit

Permalink
ci: sync Markdownlint setup from mdn/content (#8181)
Browse files Browse the repository at this point in the history
  • Loading branch information
nschonni authored Nov 25, 2022
1 parent 331fe7b commit 5368b08
Show file tree
Hide file tree
Showing 11 changed files with 955 additions and 111 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/markdown-lint-fix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Create Markdownlint auto-fix PR

on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:

jobs:
fix:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
lang:
- es
- fr
- ja
- ko
- pt-br
- ru
- zh-cn
- zh-tw
steps:
- uses: actions/checkout@v3

- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: "16"
cache: yarn

- name: Install all yarn packages
env:
HUSKY: 0
run: |
yarn --frozen-lockfile
- name: Lint markdown files
run: |
yarn markdownlint-cli2-fix "**/${{ matrix.lang }}/**/*.md"
- name: Create PR with only fixable issues
if: success()
uses: peter-evans/create-pull-request@v4
with:
commit-message: "${{ matrix.lang }}: auto-fix Markdownlint issues"
branch: markdownlint-auto-cleanup-${{ matrix.lang }}
title: "Markdownlint auto-cleanup for ${{ matrix.lang }}"
author: mdn-bot <[email protected]>
body: |
All issues auto-fixed
- name: Create PR with notice on unfixed issues
if: failure()
uses: peter-evans/create-pull-request@v4
with:
commit-message: "${{ matrix.lang }}: auto-fix Markdownlint issues"
branch: markdownlint-auto-cleanup-${{ matrix.lang }}
title: "Markdownlint auto-cleanup for ${{ matrix.lang }}"
author: mdn-bot <[email protected]>
body: |
Auto-fix was run, but additional issues found.
Please review the run log: https://github.com/mdn/translated-content/actions/runs/${{ github.run_id }}
16 changes: 12 additions & 4 deletions .github/workflows/markdown-lint.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
name: Markdown lint (project files)
name: Markdownlint (All files)

on:
pull_request:
branches:
- main
paths:
- "*.md"
- .github/workflows/markdown-lint.yml
- .markdownlint.json
- package.json
- yarn.lock
- .github/workflows/markdown-lint.yml
- .github/workflows/markdownlint-problem-matcher.json

jobs:
docs:
Expand All @@ -20,7 +22,13 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: "16"
cache: yarn

- name: Install all yarn packages
run: |
yarn --frozen-lockfile
- name: Lint markdown files
run: |
npx markdownlint-cli '*.md' -i LICENSE.md -i CODE_OF_CONDUCT.md
echo "::add-matcher::.github/workflows/markdownlint-problem-matcher.json"
yarn lint:md
18 changes: 18 additions & 0 deletions .github/workflows/markdownlint-problem-matcher.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"problemMatcher": [
{
"owner": "markdownlint",
"severity": "warning",
"pattern": [
{
"regexp": "^([^:]*):(\\d+):?(\\d+)?\\s([\\w-\\/]*)\\s(.*)$",
"file": 1,
"line": 2,
"column": 3,
"code": 4,
"message": 5
}
]
}
]
}
38 changes: 38 additions & 0 deletions .github/workflows/pr-check_markdownlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Markdownlint (PR files)

on:
pull_request:
branches:
- main
paths:
- "**/*.md"

jobs:
docs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v34
with:
files: |
**/*.md
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: "16"
cache: yarn

- name: Install all yarn packages
run: |
yarn --frozen-lockfile
- name: Lint markdown files
run: |
echo "::add-matcher::.github/workflows/markdownlint-problem-matcher.json"
files_to_lint="${{ steps.changed-files.outputs.all_changed_files }}"
yarn markdownlint-cli2 ${files_to_lint}
5 changes: 3 additions & 2 deletions .github/workflows/system-file-changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ name: System file changes
on:
pull_request_target:
paths:
- ".github/workflows/**"
- ".github/CODEOWNERS"
- ".github/**"
- package.json
- yarn.lock

jobs:
block:
Expand Down
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
3 changes: 3 additions & 0 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"*.md": "markdownlint-cli2-fix"
}
134 changes: 134 additions & 0 deletions .markdownlint-cli2.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
{
"config": {
"default": true,
// MD001 - Heading levels should only increment by one level at a time.
// -> Disabled, as some callouts include headings.
"MD001": false,
"MD004": {
"style": "dash"
},
"MD007": {
"indent": 2
},
"MD010": {
"spaces_per_tab": 2
},
"MD013": false,
// Fixed upstream, needs PRs in this repo
"MD023": false,
// Fixed upstream with "allow_different_nesting": true
"MD024": false,
"MD025": {
"front_matter_title": "^\\s*title\\s*[:=]"
},
"MD026": false,
// Consecutive Notes/Callouts currently don't conform with this rule
"MD028": false,
// Force ordered numbering to catch accidental list ending from indenting
"MD029": {
"style": "ordered"
},
"MD033": {
"allowed_elements": [
"a",
"abbr",
"annotation",
"base",
"br",
"caption",
"code",
"col",
"colgroup",
"dd",
"details",
"dfn",
"div",
"dl",
"dt",
"em",
"h4",
"h5",
"img",
"kbd",
"li",
"math",
"menclose",
"mfenced",
"mfrac",
"mfrac",
"mi",
"mmultiscripts",
"mn",
"mo",
"mover",
"mphantom",
"mprescripts",
"mroot",
"mrow",
"ms",
"mspace",
"mspace",
"msqrt",
"mstyle",
"msub",
"msubsup",
"msup",
"mtable",
"mtd",
"mtext",
"mtr",
"munder",
"munderover",
"none",
"ol",
"p",
"pre",
"section",
"semantics",
"strong",
"sub",
"summary",
"sup",
"table",
"tbody",
"td",
"tfoot",
"th",
"thead",
"tr",
"ul",
"var",
"ruby", //Used in some Korean documents
"rp", //Used in some Korean documents
"rt", //Used in some Korean documents
"i", // French translations use this for English literal text
"q", // French translations use this for English literal text
"h2", // Not always converted currently because of live samples using English IDs
"h3", // Not always converted currently because of live samples using English IDs
"h6" // Not always converted currently because of live samples using English IDs
]
},
// Fixed upstream, needs PRs in this repo
"MD036": false,
// Upstream fixing in https://github.com/mdn/content/pull/20115
"MD037": false,
"MD040": false,
// See https://github.com/mdn/content/pull/20026, as macros currently break this
"MD042": false,
// Tracked upstream as part of https://github.com/mdn/content/pull/19334
"MD045": false,
"MD046": {
"style": "fenced"
},
// MD049 is set to underscore upstream, not yet fixed here
"MD049": false,
// MD050 is set to asterisk upstream, not yet fixed here
"MD050": false,
// MD051 - Link fragments should be valid.
// -> Disabled, as yari generates link fragments by replacing spaces with underscores, not dashes.
"MD051": false,
// Incompatible with brackets in macros like MD042
"MD052": false
},
"ignores": ["node_modules", "**/conflicting/**", "**/orphaned/**", ".github/", "files/**/web/api/window/frames/index.md"]
}
Loading

0 comments on commit 5368b08

Please sign in to comment.