Skip to content

Commit df466a8

Browse files
committed
pre-processed spellcheck output
Signed-off-by: Frederic BIDON <[email protected]>
1 parent e5d8f1c commit df466a8

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

.github/workflows/doc-update.yml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ name: doc update check
2525
# * [ ] should be able to retrieve config files and dictionary from the called ref, not master.
2626
# * [ ] should be able to merge config files and dictionary with local definitions on target repo.
2727
# * [ ] should be able to work on diff
28+
# * [ ] should format the output of spellcheck report
2829

2930
on:
3031
workflow_call:
@@ -122,6 +123,7 @@ jobs:
122123
if: ${{ steps.markdownlint.outcome != 'success' && hashFiles(env.lintreport) != '' }}
123124
id: report-exists
124125
run: |
126+
# summarizes a bit the output from spellcheck
125127
echo 'report<<EOF' >> $GITHUB_OUTPUT
126128
cat ${{ env.lintreport }}|sed -e '$a\' >> $GITHUB_OUTPUT
127129
echo 'EOF' >> $GITHUB_OUTPUT
@@ -423,13 +425,33 @@ jobs:
423425
reactions: ${{ steps.notify_spelling_report.outputs.reactions }}
424426
runs-on: ubuntu-latest
425427
steps:
428+
- name: Pre-process spellcheck report
429+
id: preprocess
430+
env:
431+
MSG: ${{ needs.markdown-spelling.outputs.report }}
432+
SED_CMD: .github/workflows/filter.sed # a sed script to parse and reformat the spellcheck report
433+
JQ_CMD: .github/workflows/merge.jq # a jq script to dedupe spellcheck reports by file
434+
TMPFILE: /tmp/spellcheck-report.txt
435+
run: |
436+
export MSG
437+
printenv MSG > "${TMPFILE}"
438+
# produces a JSON object:
439+
# {
440+
# "file.md": [ mispelled word [, ...]]
441+
# }
442+
cat "${TMPFILE}" | sed -n -f "${SED_CMD}" | jq -s "${JQ_CMD}" > /tmp/preprocessed.txt
443+
444+
echo 'report<<EOF' >> $GITHUB_OUTPUT
445+
cat /tmp/preprocessed.txt|sed -e '$a\' >> $GITHUB_OUTPUT
446+
echo 'EOF' >> $GITHUB_OUTPUT
447+
426448
- name: Format PR comment
427449
id: comment_formatter
428450
uses: skills/action-text-variables@v3
429451
with:
430452
template-vars: >
431453
{
432-
"text": ${{ toJSON(needs.markdown-spelling.outputs.report) }}
454+
"text": ${{ steps.preprocess.outputs.report) }}
433455
}
434456
template-text: |
435457
### ${{ env.spellcheck_comment_title }}
@@ -442,6 +464,7 @@ jobs:
442464
<br>
443465
444466
```
467+
### TODO: range json
445468
{{ text }}
446469
```
447470

.github/workflows/filter.sed

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
:scan_input {
2+
# main scanner loop, looking for "Misspelled words:" entries
3+
/^Misspelled words:/,/^-\{5,\}/ {
4+
/^&lt;html\(attribute\|content\)&gt\;/ {
5+
# Extract the file name
6+
# TODO: be less strict here
7+
s/^&lt;html\(attribute\|content\)&gt\;\s\+\(.\+\.md\):.*$/"\2": [/
8+
h
9+
n # skip current match
10+
n # skip next line
11+
12+
# go decode a section of single words, enclosed between "=====..." lines
13+
b parse_section
14+
}
15+
16+
n
17+
18+
b scan_input
19+
}
20+
}
21+
22+
# Back to main loop (cycles)
23+
d
24+
25+
:parse_section {
26+
:word /^[^-]/ {
27+
# Append words to the previous line
28+
# Trim space around words
29+
s/\s\+//g
30+
# Quote word
31+
s/^/"/
32+
s/$/"/
33+
34+
# Add comma separator
35+
s/$/, /
36+
H
37+
n
38+
39+
b word
40+
}
41+
42+
/^-\{5,\}$/ {
43+
# Print the collected words as a comma-separated array of words
44+
x
45+
46+
s/^/{/g
47+
s/\n/ /g
48+
s/\s\+/ /g
49+
s/\s\+$//g
50+
s/\(,\s*\)\?$/ ]/
51+
s/$/}/g
52+
53+
p
54+
55+
# Start a new cycle
56+
d
57+
}
58+
}
59+
60+
d

.github/workflows/merge.jq

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
reduce (.[] | to_entries | .[]) as {$key, $value} (
2+
{} ;
3+
.[$key] += $value
4+
) | .[] |= unique

0 commit comments

Comments
 (0)