Skip to content

Commit 11384dd

Browse files
committed
experimental: markdown lint in CI
Signed-off-by: Frederic BIDON <[email protected]>
1 parent 470ae20 commit 11384dd

File tree

3 files changed

+191
-0
lines changed

3 files changed

+191
-0
lines changed

.github/.markdownlint.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# See rules documentation: https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md
2+
3+
# Default state for all rules
4+
default: true
5+
6+
# ul-style # default: consistent
7+
MD004: consistent
8+
9+
# hard-tabs
10+
MD010: false
11+
12+
# line-length
13+
MD013: false
14+
15+
# no-duplicate-header
16+
MD024:
17+
siblings_only: true
18+
19+
#single-title
20+
MD025: true
21+
22+
# ol-prefix
23+
MD029:
24+
style: one_or_ordered
25+
26+
# no-inline-html
27+
MD033: false
28+
29+
# fenced-code-language
30+
MD040: false

.github/workflows/TODO.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Evaluate:
2+
3+
* markdownlint
4+
* assessment: go
5+
* used by opentelemetry/opentelemetry-go
6+
* packaged as github action
7+
* misspell
8+
* spellcheck
9+
* govulncheck
10+
* [x] godoc-lint:
11+
* assessment: no go
12+
* too simplistic: no real value added
13+
* not integrated into golangci's suite of linters
14+
* no packaged github action

.github/workflows/markdown.yml

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
name: Markdown
2+
3+
on:
4+
pull_request_target:
5+
paths:
6+
- '**/*.md'
7+
8+
permissions:
9+
pull-requests: write
10+
contents: read
11+
12+
env:
13+
comment-title: Markdown linter
14+
15+
jobs:
16+
markdown-changed:
17+
runs-on: ubuntu-latest
18+
outputs:
19+
proceed: ${{ steps.changed-markdown-files.outputs.any_changed }}
20+
all_changed_files: ${{ steps.changed-markdown-files.outputs.all_changed_files }}
21+
steps:
22+
- name: Checkout Repo
23+
uses: actions/checkout@v4
24+
25+
- name: Get changed markdown files
26+
id: changed-markdown-files
27+
uses: tj-actions/changed-files@v45
28+
with:
29+
files: '**/*.md'
30+
31+
- name: Notify
32+
run: |
33+
echo "::notice::Detected some changed markdown files"
34+
echo "${{ steps.changed-markdown-files.outputs.all_changed_files }}"
35+
36+
lint-markdown:
37+
needs: markdown-changed
38+
if: needs.markdown-changed.outputs.proceed == 'true'
39+
runs-on: ubuntu-latest
40+
env:
41+
lintreport: './markdownlint-report.txt'
42+
outputs:
43+
proceed: ${{ steps.report-exists.outputs.proceed }}
44+
report: ${{ steps.report-exists.outputs.report }}
45+
46+
steps:
47+
- name: Checkout Repo
48+
uses: actions/checkout@v4
49+
50+
- name: Run markdown linter
51+
continue-on-error: true
52+
id: markdownlint
53+
uses: docker://avtodev/markdown-lint:v1.5
54+
with:
55+
config: ./.github/.markdownlint.yml
56+
args: ${{ needs.markdown-changed.outputs.all_changed_files }}
57+
output: '${{ env.lintreport }}'
58+
59+
- name: Find previous PR comment
60+
if: steps.markdownlint.outcome == 'success'
61+
uses: peter-evans/find-comment@v3
62+
id: findcomment
63+
with:
64+
issue-number: ${{ github.event.pull_request.number }}
65+
body-includes: ${{ env.comment-title }}
66+
direction: last
67+
68+
- name: Comment on success
69+
if: steps.markdownlint.outcome == 'success'
70+
id: congrats
71+
uses: peter-evans/create-or-update-comment@v4
72+
with:
73+
issue-number: ${{ github.event.pull_request.number }}
74+
comment-id: ${{ steps.findcomment.outputs.comment-id }}
75+
reactions: hooray
76+
reactions-edit-mode: replace
77+
body: |
78+
### ${{ env.comment-title }}
79+
Markdown looks good to me. Congrats!
80+
81+
- name: Check lint report exists
82+
if: ${{ steps.markdownlint.outcome != 'success' && hashFiles(env.lintreport) != '' }}
83+
id: report-exists
84+
run: |
85+
echo 'report<<EOF' >> $GITHUB_OUTPUT
86+
cat ${{ env.lintreport }}|sed -e '$a\' >> $GITHUB_OUTPUT
87+
echo 'EOF' >> $GITHUB_OUTPUT
88+
89+
if [[ "$(cat ${{ env.lintreport }}|wc -l)" != "0" ]] ; then
90+
echo "proceed=true" >> $GITHUB_OUTPUT
91+
echo "::notice::Detected some linting issues with changed markdown"
92+
cat ${{ env.lintreport }}|sed -e '$a\'
93+
else
94+
echo "proceed=false" >> $GITHUB_OUTPUT
95+
echo "::notice::No linting issues with changed markdown"
96+
fi
97+
98+
- name: Other linter errors
99+
if: ${{ steps.markdownlint.outcome != 'success' && hashFiles(env.lintreport) == '' }}
100+
run: |
101+
echo "::error::markdown linter encountered an error"
102+
exit 1
103+
104+
pr-comment:
105+
needs: lint-markdown
106+
if: needs.lint-markdown.outputs.proceed == 'true'
107+
runs-on: ubuntu-latest
108+
109+
steps:
110+
- name: Format PR comment
111+
id: commentformatter
112+
uses: skills/action-text-variables@v1
113+
with:
114+
template-vars: |
115+
text='${{ needs.lint-markdown.outputs.report }}'
116+
template-text: |
117+
### ${{ env.comment-title }}
118+
Some markdown linting issues were detected in modified .md files.
119+
120+
This check is advisory only and not blocking. Please adopt a nice markdown style.
121+
122+
Markdown formatting rules are documented [here](https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md).
123+
<br>
124+
{{ text }}
125+
126+
- name: Find previous PR comment
127+
uses: peter-evans/find-comment@v3
128+
id: findcomment
129+
with:
130+
issue-number: ${{ github.event.pull_request.number }}
131+
body-includes: ${{ env.comment-title }}
132+
direction: last
133+
134+
- name: Create or update PR comment
135+
uses: peter-evans/create-or-update-comment@v4
136+
with:
137+
issue-number: ${{ github.event.pull_request.number }}
138+
comment-id: ${{ steps.findcomment.outputs.comment-id }}
139+
reactions: confused
140+
reactions-edit-mode: replace
141+
body: ${{ steps.commentformatter.outputs.updated-text }}
142+
edit-mode: replace
143+
144+
- name: Notify
145+
run: |
146+
echo "::notice::Commented pull request ${{ github.event.pull_request.number }}"
147+
echo "::debug::${{ steps.commentformatter.outputs.updated-text }}"

0 commit comments

Comments
 (0)