chore: 🤖 spell checker file normalisation #57
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 🧐 Spell checker (Grammar) | |
on: | |
pull_request: | |
jobs: | |
spellcheck: | |
runs-on: ubuntu-latest | |
env: | |
MAX_NUMBER_OF_TYPOS: 5 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- uses: oven-sh/setup-bun@v1 | |
with: | |
bun-version: latest | |
- name: Install Hunspell | |
run: | | |
sudo apt-get update | |
# Hunspell along with the English (US) dictionary | |
sudo apt-get install -y hunspell hunspell-en-us | |
- name: Spell check (Markdown) | |
run: | | |
base_branch=${{ github.base_ref }} | |
diff=$(git diff --name-only origin/$base_branch | grep -E '\.mdx?$' || true) | |
if [[ -n "$diff" ]]; then | |
echo "🧐 Going to spell check the following files:" | |
echo "$diff" | |
echo | |
for file in $diff; do | |
normalizedFile=$(mktemp) | |
./scripts/markdown-normalizer.ts "$file" > "$normalizedFile" | |
output=$(hunspell -l -d en_US -p .github/actions/spell-checker/ignore_words.txt "$normalizedFile") | |
typos_count=$(echo "$output" | wc -l) | |
rm "$normalizedFile" | |
if [[ -n "$output" ]]; then | |
echo "🤓 Found the following typos in $file" | |
echo | |
echo "$output" | |
echo | |
echo "👆 If there are false positives, help us improve by adding the word to the ignore list in the location .github/actions/spell-checker/ignore_words.txt, please!" | |
fi | |
if [[ "$typos_count" -gt "$MAX_NUMBER_OF_TYPOS" ]]; then | |
echo "👹 Oops! The number of typos found exceed the maximum allowed count of $MAX_NUMBER_OF_TYPOS" | |
exit 1 | |
fi | |
done | |
else | |
echo "🦖Oh-No! No markdown files were found to be modified, so no spell check happened." | |
fi |