-
Notifications
You must be signed in to change notification settings - Fork 15
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
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bce9b1a
feat: added spell check workflow
mgandharva 321a1a3
fix: updated the spell-check
mgandharva 3ab6e29
updated the names
mgandharva 2491882
fix: added new line
mgandharva 678ac31
Merge branch 'main' into spell-check-workflow
mgandharva 4f1f42f
Merge branch 'main' of https://github.com/dell/csm-docs into spell-ch…
mgandharva ee3ec61
Merge branch 'spell-check-workflow' of https://github.com/dell/csm-do…
mgandharva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
VAs | ||
IAM | ||
MKE | ||
master |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
codespell |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
name: Automatic Spell Check and Correction | ||
shaynafinocchiaro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
on: | ||
workflow_dispatch: | ||
repository_dispatch: | ||
shaynafinocchiaro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
types: [trigger-spell-check-autofix] | ||
|
||
jobs: | ||
codespell: | ||
name: Perform Spell Check and Apply Fixes | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [3.8] # Define the Python version here | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Import GPG Key | ||
shaynafinocchiaro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
uses: crazy-max/ghaction-import-gpg@v6 | ||
with: | ||
gpg_private_key: ${{ secrets.CSM_GPG_PRIVATE_KEY }} | ||
git_user_signingkey: true | ||
git_commit_gpgsign: true | ||
git_tag_gpgsign: true | ||
git_config_global: true | ||
|
||
- name: Set Up Python Environment | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install Codespell | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install codespell | ||
|
||
- name: Run Codespell Autofix | ||
run: | | ||
chmod +x .github/workflows/autofix-scripts/codespell-autofix.sh | ||
./.github/workflows/autofix-scripts/codespell-autofix.sh | ||
|
||
- name: Check for Uncommitted Changes | ||
shaynafinocchiaro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
id: check_changes | ||
run: | | ||
git status | ||
if [ -n "$(git status --porcelain)" ]; then | ||
echo "CHANGES_DETECTED=true" >> $GITHUB_ENV | ||
else | ||
echo "CHANGES_DETECTED=false" >> $GITHUB_ENV | ||
fi | ||
|
||
- name: Print Changes Detected | ||
shaynafinocchiaro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
run: | | ||
echo "Changes detected: ${{ env.CHANGES_DETECTED }}" | ||
|
||
- name: Commit and Push Changes | ||
shaynafinocchiaro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if: env.CHANGES_DETECTED == 'true' | ||
run: | | ||
git add . | ||
git commit -m "Autofix spelling issues" | ||
|
||
- name: Generate GitHub App Token | ||
uses: actions/[email protected] | ||
id: generate-token | ||
if: env.CHANGES_DETECTED == 'true' | ||
with: | ||
app-id: ${{ vars.CSM_RELEASE_APP_ID }} | ||
private-key: ${{ secrets.CSM_RELEASE_APP_PRIVATE_KEY }} | ||
|
||
- name: Create Pull Request with Autofixes | ||
shaynafinocchiaro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if: env.CHANGES_DETECTED == 'true' | ||
uses: peter-evans/create-pull-request@v5 | ||
with: | ||
token: ${{ steps.generate-token.outputs.token }} | ||
branch: spellcheck-fixes | ||
title: 'Automated Spelling Corrections Applied' | ||
body: | | ||
This pull request was created automatically by a GitHub Action that fixes spelling errors across multiple files. | ||
|
||
**Summary of changes:** | ||
- Identified and corrected common spelling mistakes | ||
- Ensured consistency and accuracy in documentation files | ||
|
||
Please review the changes to confirm their accuracy and approve the PR. | ||
sign-commits: true | ||
delete-branch: true |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add copyright header