@@ -9,28 +9,139 @@ permissions:
99 pull-requests : write
1010 contents : read
1111
12+ env :
13+ comment-title : Markdown linter
14+
1215jobs :
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+
1336 lint-markdown :
37+ needs : markdown-changed
38+ if : needs.markdown-changed.outputs.proceed == 'true'
1439 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+
1546 steps :
1647 - name : Checkout Repo
1748 uses : actions/checkout@v4
1849
1950 - name : Run markdown linter
51+ continue-on-error : true
2052 id : markdownlint
21- # continue-on-error: true
22- uses : docker://avtodev/markdown-lint:v1
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
2363 with :
24- config : .markdownlint.yml
25- args : ' **/*.md '
26- output : ./markdownlint.txt
64+ issue-number : ${{ github.event.pull_request.number }}
65+ body-includes : ${{ env.comment-title }}
66+ direction : last
2767
28- - name : Create PR comment
29- if : ${{ failure() && steps.markdownlint.outcome == 'failure' }}
30- # if: steps.markdownlint.outputs.exit_code != 0
68+ - name : Comment on success
69+ if : steps.markdownlint.outcome == 'success'
70+ id : congrats
3171 uses : peter-evans/create-or-update-comment@v4
3272 with :
3373 issue-number : ${{ github.event.pull_request.number }}
34- title : Markdown Lint Report
35- body-path : ./markdownlint.txt
36- labels : report, bot-generated
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