Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Automated Spell Check #1432

Merged
merged 7 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/spell-check-autofix/codespell-autofix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

# Determine the directory of the script
script_dir=$(dirname "$(readlink -f "$0")")
echo "Script directory: $script_dir"

# Define the target directory
target_dir=$(realpath "$script_dir/../../..")
echo "Target directory: $target_dir"

# Run codespell and capture output, targeting the test-csm-docs directory
output=$(find "$target_dir" -type f -name "*.md" -exec codespell \
--ignore-words="$script_dir/codespell.txt" --builtin clear,rare,informal \
--write-changes --quiet-level=0 {} +)

# Print each line of the output separately for readability
echo "Codespell Output:"
echo "$output" | while IFS= read -r line; do
echo "$line"
done

# Process the output and apply the first suggestion
echo "Processing changes..."
echo "$output" | while IFS= read -r line; do
if [[ $line == *" ==>"* ]]; then
# Extract file, line number, original word, and suggestion
file=$(echo "$line" | cut -d':' -f1)
error_line=$(echo "$line" | cut -d':' -f2)
original=$(echo "$line" | awk '{print $2}')
suggestion=$(echo "$line" | awk -F'[ ]+==> ' '{print $2}' | cut -d',' -f1)

# Ensure the file is inside the test-csm-docs directory
if [[ $file == $target_dir/* ]]; then
# Apply the first suggestion
if [ -n "$suggestion" ] && [ -f "$file" ]; then
sed -i "${error_line}s/\b$original\b/$suggestion/" "$file"
echo "Fixed $original to $suggestion in $file on line $error_line"
fi
else
echo "Skipping file not in target directory: $file"
fi
fi
done
4 changes: 4 additions & 0 deletions .github/spell-check-autofix/codespell.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
VAs
IAM
MKE
master
1 change: 1 addition & 0 deletions .github/spell-check-autofix/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
codespell
43 changes: 43 additions & 0 deletions .github/workflows/spellcheck.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0

name: Spell Check
mgandharva marked this conversation as resolved.
Show resolved Hide resolved

on:
pull_request: # Trigger this workflow on pull request events

jobs:
spell_check: # Job name for clarity
name: Spell Check with Codespell
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8] # Define the Python version here

steps:
- name: Checkout Repository
uses: actions/checkout@v2 # Check out the repository code

- name: Set Up Python Environment
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }} # Set up the specified Python version

- name: Install Codespell
run: |
python -m pip install --upgrade pip # Upgrade pip
pip install codespell # Install codespell

- name: Run Codespell on Markdown Files
run: |
find . -type f -name "*.md" -exec codespell \
--ignore-words=.github/spell-check-autofix/codespell.txt \
--builtin clear,rare,informal {} +
# 'find' command searches for all .md files and runs 'codespell' on them.
# The '--ignore-words' option specifies custom dictionary file.
# The '--builtin' option uses 'codespell' with built-in dictionaries: clear, rare, informal.
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Makefile

# 'spell-fix' target:
# This target runs the spell check autofix script located in the specified path.
# The script 'codespell-autofix.sh' is expected to check for spelling errors and automatically fix them.
# Ensure that the 'codespell-autofix.sh' script has executable permissions.
# chmod +x .github/Spell-check-autofix/codespell-autofix.sh
spell-fix:
./.github/spell-check-autofix/codespell-autofix.sh

.PHONY: actions action-help
actions: ## Run all GitHub Action checks that run on a pull request creation
@echo "Running all GitHub Action checks for pull request events..."
Expand All @@ -13,4 +23,4 @@ action-help: ## Echo instructions to run one specific workflow locally
@echo "Where '<jobid>' is a Job ID returned by the command:"
@echo "act -l"
@echo ""
@echo "NOTE: if act is not installed, it can be downloaded from https://github.com/nektos/act"
@echo "NOTE: if act is not installed, it can be downloaded from https://github.com/nektos/act"
Loading