-
Notifications
You must be signed in to change notification settings - Fork 94
89 lines (78 loc) · 2.88 KB
/
spell-check.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: 🥢 Spell check
on:
pull_request:
branches:
- main
jobs:
typo_check:
name: 🥢 Spell check
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
env:
TYPOS: ""
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 2
- name: Install aspell
run: sudo apt-get update && sudo apt-get install -y aspell
- name: Find and check typos in Markdown files
id: find_typos
run: |
echo "Checking for typos..."
# https://unix.stackexchange.com/a/9500
IFS=$'\n'
set -f
for file in $(find . -name "*.md" ); do
output="$(aspell --lang=en_US --mode=markdown --home-dir=. --personal=wordlist.txt --ignore-case=true --camel-case list <$file)"
echo "$output"
# Exit if aspell has errors
if [ $? -ne 0 ]; then
exit 1
fi
if [[ -n "$output" ]]; then
# Format output.
output=$(echo "$output" | sed 's/^/ 1. /')
TYPOS+="- 📄 $file:"
TYPOS+=$'\n'
TYPOS+="$output"
TYPOS+=$'\n'
fi
done
{
echo 'TYPOS<<EOF'
echo "$TYPOS"
echo EOF
} >> "$GITHUB_ENV"
- name: Comment on pull request
if: env.TYPOS != ''
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const author = '${{github.event.pull_request.user.login}}';
const typos = `${{ env.TYPOS }}`;
const body = `
Hi @${author},
Following typos were found in the pull request:
${typos}
## ℹ️ Here's how to fix them:
- **Fix typos:** Open the relevant files and fix any identified typos.
- **Update wordlist:** If a flagged word is actually a project-specific term add it to \`wordlist.txt\` in the project root.
Each word should be listed on a separate line. [Learn more.](http://aspell.net/man-html/Format-of-the-Personal-and-Replacement-Dictionaries.html)
- **🚧 Remember:**
- When adding new words it MUST NOT have any spaces or special characters within or around it.
- \`wordlist\` is NOT case sensitive.
- Use backticks to quote code variables so as to not bloat the \`wordlist\`.
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
core.setFailed('🥢 Spell check: Typos found in docs. Please fix them.');