From c7116d6d3d0b1cf5de8cea51aaa52229f574f308 Mon Sep 17 00:00:00 2001 From: mgandharva <124261698+mgandharva@users.noreply.github.com> Date: Tue, 4 Feb 2025 16:31:07 +0530 Subject: [PATCH 1/2] feat: added act for local pr check (#1437) --- Makefile | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000..15bf17a9fc --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +.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 " + @echo "" + @echo "Where '' 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" \ No newline at end of file From f2e130f641b3d3d2e35ac95e491cb56de74ff7f5 Mon Sep 17 00:00:00 2001 From: mgandharva <124261698+mgandharva@users.noreply.github.com> Date: Tue, 4 Feb 2025 16:36:33 +0530 Subject: [PATCH 2/2] Add Automated Spell Check (#1432) * feat: added spell check workflow * fix: updated the spell-check * updated the names * fix: added new line --- .../spell-check-autofix/codespell-autofix.sh | 43 +++++++++++++++++++ .github/spell-check-autofix/codespell.txt | 4 ++ .github/spell-check-autofix/requirements.txt | 1 + .github/workflows/spellcheck.yaml | 43 +++++++++++++++++++ Makefile | 12 +++++- 5 files changed, 102 insertions(+), 1 deletion(-) create mode 100755 .github/spell-check-autofix/codespell-autofix.sh create mode 100644 .github/spell-check-autofix/codespell.txt create mode 100644 .github/spell-check-autofix/requirements.txt create mode 100644 .github/workflows/spellcheck.yaml diff --git a/.github/spell-check-autofix/codespell-autofix.sh b/.github/spell-check-autofix/codespell-autofix.sh new file mode 100755 index 0000000000..2a2fd8fc95 --- /dev/null +++ b/.github/spell-check-autofix/codespell-autofix.sh @@ -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 diff --git a/.github/spell-check-autofix/codespell.txt b/.github/spell-check-autofix/codespell.txt new file mode 100644 index 0000000000..2e44bf28bb --- /dev/null +++ b/.github/spell-check-autofix/codespell.txt @@ -0,0 +1,4 @@ +VAs +IAM +MKE +master diff --git a/.github/spell-check-autofix/requirements.txt b/.github/spell-check-autofix/requirements.txt new file mode 100644 index 0000000000..e3da9e4b09 --- /dev/null +++ b/.github/spell-check-autofix/requirements.txt @@ -0,0 +1 @@ +codespell diff --git a/.github/workflows/spellcheck.yaml b/.github/workflows/spellcheck.yaml new file mode 100644 index 0000000000..ac9fa68b91 --- /dev/null +++ b/.github/workflows/spellcheck.yaml @@ -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. diff --git a/Makefile b/Makefile index 15bf17a9fc..3380f14141 100644 --- a/Makefile +++ b/Makefile @@ -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..." @@ -13,4 +23,4 @@ action-help: ## Echo instructions to run one specific workflow locally @echo "Where '' 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" \ No newline at end of file + @echo "NOTE: if act is not installed, it can be downloaded from https://github.com/nektos/act"