-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
117 additions
and
0 deletions.
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,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 | ||
|
||
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. |
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,26 @@ | ||
# 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..." | ||
@act -l | grep -v ^Stage | grep pull_request | grep -v image_security_scan | awk '{print $$2}' | while read WF; do \ | ||
echo "Running workflow: $${WF}"; \ | ||
act pull_request --no-cache-server --platform ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-latest --job "$${WF}"; \ | ||
done | ||
|
||
action-help: ## Echo instructions to run one specific workflow locally | ||
@echo "GitHub Workflows can be run locally with the following command:" | ||
@echo "act pull_request --no-cache-server --platform ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-latest --job <jobid>" | ||
@echo "" | ||
@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" |