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

CSpell Action #75

Merged
merged 13 commits into from
Sep 5, 2023
114 changes: 94 additions & 20 deletions spellings/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,102 @@ name: 'spellings'
description: 'CI spellings check'
inputs:
path:
description: 'Path to repository folder to check spellings in.'
description: 'Path to repository folder to run formatting check for.'
required: false
default: ./
exclude-files:
description: 'List of comma-separated files to exclude from trailing whitespace check. Eg file1,file2'
required: false
default: ''
exclude-dirs:
description: 'List of comma-separated directories to exclude from trailing whitespace formatting check. Eg docs,build'
required: false
default: ''
include-extensions:
description: 'List of comma-separated file endings to include into the spell check. Eg md, dox, build'
required: false
default: ''

runs:
using: "composite"
steps:
- name: Install spell
run: |
sudo apt-get install spell
sudo apt-get install util-linux
shell: bash
- name: Check spelling
working-directory: ${{ inputs.path }}
run: |
PATH=$PATH:$GITHUB_ACTION_PATH/tools
for lexfile in `find ./ -name lexicon.txt`
do dir=${lexfile%/lexicon.txt}
echo $dir
find-unknown-comment-words --directory $dir
if [ $? -ne "0" ]
then
exit 1
fi
done
shell: bash
- env:
stepName: Install Spell
bashPass: \033[32;1mPASSED -
bashInfo: \033[33;1mINFO -
bashFail: \033[31;1mFAILED -
bashEnd: \033[0m
name: ${{ env.stepName }}
id: spell-checker-setup
shell: bash
run: |
# ${{ env.stepName }}
echo "::group::${{ env.stepName }}"
sudo apt-get install spell -y
sudo apt-get install util-linux -y
sudo apt-get install fd-find -y

# This is a 1000+ line log for the install
# Wrap it in an echo group
echo "::group::NPM Install"
sudo apt-get install npm -y
sudo npm install -g cspell
echo "::endgroup::"

echo "$GITHUB_ACTION_PATH" >> $GITHUB_PATH
export PATH="$PATH:$GITHUB_ACTION_PATH"

# cp has an error code if it's asked to copy to the same file
# Wrap it in a set +e in case the input path is the working directory
set +e
cp $GITHUB_ACTION_PATH/cspell.config.yaml ${{ inputs.path }}
set -e
echo "::endgroup::"

# Make sure we have all the commands we need.
echo -e "${{ env.bashInfo }} which getFiles ${{ env.bashEnd }}"
echo -e "${{ env.bashInfo }} fdfind --version ${{ env.bashEnd }}"
echo -e "${{ env.bashInfo }} cspell --version ${{ env.bashEnd }}"

# Only get to here if everything above passes
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"

- env:
bashPass: \033[32;1mPASSED -
bashInfo: \033[33;1mINFO -
bashFail: \033[31;1mFAILED -
bashEnd: \033[0m
stepName: Check Spelling
name: ${{ env.stepName}}
id: run-spell-checker
working-directory: ${{ inputs.path }}
shell: bash
run: |
# ${{ env.stepName }}
echo "::group::${{ env.stepName }}"

# Add helper script to path
export PATH="$PATH:$GITHUB_ACTION_PATH"

# Get all files
files=$(getFiles --exclude-dirs="${{ inputs.exclude-dirs }}" --exclude-files="${{ inputs.exclude-files }}" --include-extensions="${{ inputs.include-extensions}}")

# Wrap the check in set +e so it runs against all files
set +e
exitStatus=0
for file in ${files[@]}; do
cspell --language-id C --color -c cspell.config.yaml --show-suggestions --show-context "$file"
if ! [ $? -eq 0 ]; then
exitStatus=1
fi
done
set -e

echo "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
Skptak marked this conversation as resolved.
Show resolved Hide resolved
else
echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1
fi

22 changes: 22 additions & 0 deletions spellings/cspell.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
$schema: https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json
version: '0.2'
# Allows things like stringLength
allowCompoundWords: true
useGitignore: true
# Could split this up? And do a dictionary for each repo?
# But feel like if this isn't super slow
# That having just one single dictionary might be nicer?
dictionaryDefinitions:
- name: freertos-words
path: '.cSpellWords.txt'
Skptak marked this conversation as resolved.
Show resolved Hide resolved
addWords: true
dictionaries:
- freertos-words
ignorePaths:
- 'node_modules'
- '.cSpellWords.txt'
- 'dependency'
- 'docs'
- 'ThirdParty'

122 changes: 122 additions & 0 deletions spellings/getFiles
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/bin/bash
bashPass="\033[32;1mPASSED -"
bashInfo="\033[33;1mINFO -"
bashFail="\033[31;1mFAILED -"
bashEnd="\033[0m"

# Check number of arguments
files=""
file=""
excludeDirs=""
excludeFiles=""
includeExtensions=""

# Make the assumption that Mac users will be using FreeBSD Get Opt
if [[ "$OSTYPE" == "darwin"* ]]; then
while [ $# -gt 0 ]; do
case "$1" in
-ed= | --exclude-dirs=* )
excludeDirs="-E $(echo "${1#*=}" | sed -E 's/,/ -E /g')"
shift
;;
-ef= | --exclude-files=* )
excludeFiles="-E $(echo "${1#*=}" | sed -E 's/,/ -E /g')"
shift
;;
-ie= | --include-extensions=* )
includeExtensions="-e $(echo "${1#*=}" | sed -E 's/,/ -e /g')"
shift
;;
-h | --help )
echo -e "$bashInfo Find all .c and .h files with the Amazon copyright in them $bashEnd"
Skptak marked this conversation as resolved.
Show resolved Hide resolved
echo -e "$bashInfo It exports this to a bash array variable called \"files\" $bashEnd"
echo -e "$bashInfo This script can take in two optional arguments $bashEnd"
echo -e "$bashInfo -ef= | --exclude-files=: A comma seperated list of files to exclude $bashEnd"
echo -e "$bashInfo -ed= | --exclude-dir=: A comma seperated list of directories to exclude $bashEnd"
echo -e "$bashInfo -ie= | --include-extensions=: Any additional exstensions to search for $bashEnd"
exit 0
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
# For FreeBSD (default MacOS shell) assume that you have fd
# By default only grab the c and h files. Only grab the files with amazon copyright
# Put all the files in an array. Uncomment the following line to see the command run.
# echo "fd -e c -e h "$excludeDirs" "$excludeFiles" "$includeExtensions" --exec grep -lie \"copyright (.*) 20[0-9]{2} amazon.com\" "
# Need this in a set +/- e so it doesn't return an error on files that fail the grep
set +e
files=$(fd -e c -e h $excludeDirs $excludeFiles $includeExtensions --exec grep -lie "copyright (.*) 20\d\d amazon.com")
set -e

# Making the assumption that anybody else running this is a gnu getopt user
Skptak marked this conversation as resolved.
Show resolved Hide resolved
else
VALID_ARGS=$(getopt -o h,ed:,ef:,if: --long help,exclude-dirs:,exclude-files:,include-extensions: -- "$@")
eval set -- "$VALID_ARGS"
while [ $# -gt 0 ]; do
case "$1" in
ed | --exclude-dirs )
# $2 Holds the argument passed after --exclude-files or --ed
# Use sed to replace the commas with the exclude flag
if ! [ -z "$2" ]; then
excludeDirs="-E $(echo "$2" | sed -r 's/,/ -E /g' )"
fi
shift 2
;;

ef | --exclude-files )
# $2 Holds the argument passed after --exclude-files or --ed
# Use sed to replace the commas with the exclude flag
if ! [ -z "$2" ]; then
excludeFiles="-E $( echo "$2" | sed -r 's/,/ -E /g' )"
fi
shift 2
;;

if | --include-extensions )
# $2 Holds the argument passed after --exclude-files or --ed
# Use sed to replace the commas with the exclude flag
if ! [ -z "$2" ]; then
includeExtensions="-e $( echo "$2" | sed -r 's/,/ -E /g' )"
fi
shift 2
;;

h | --help )
echo -e "$bashInfo Find all .c and .h files with the Amazon copyright in them $bashEnd"
echo -e "$bashInfo It exports this to a bash array variable called \"files\" $bashEnd"
echo -e "$bashInfo This script can take in two optional arguments $bashEnd"
echo -e "$bashInfo --exclude-files: A comma seperated list of files to exclude $bashEnd"
echo -e "$bashInfo --exclude-dir: A comma seperated list of directories to exclude $bashEnd"
echo -e "$bashInfo --include-extensions: Any additional exstensions to search for $bashEnd"
exit 0
;;
-- )
shift
break
;;
esac
done
# Make the assumption that gnu getopt means you're going to use fdfind vs fd
# By default only grab the c and h files. Only grab the files with amazon copyright
# Put all the files in an array. Uncomment the following line to see the command run.
# echo "fdfind -e c -e h "$excludeDirs" "$excludeFiles" "$includeExtensions" --exec grep -liE \"copyright (.*) 20[0-9]{2} amazon.com\" "
# Need this in a set +/- e so it doesn't return an error on files that fail the grep
set +e
files=$(fdfind -e c -e h $excludeDirs $excludeFiles $includeExtensions --exec grep -liE "copyright (.*) 20[0-9]{2} amazon.com" )
set -e
fi

# For future FreeBSD users:
# By default if you try and capture this output like you see on the github workflows
# By doing something like files=$(getFiles <ARGS>) it will look like it doesn't work
# This is because on a Mac's default shell this will expand to a single variable
# But on ubuntu's default shell it will expand to an array that can be iterated over
# My recommendation would be to uncomment the fd command above and capture that
for file in ${files[@]}; do
if ! [ -z "$file" ]; then
echo "$file"
fi
done
30 changes: 0 additions & 30 deletions spellings/tools/README.md

This file was deleted.

88 changes: 0 additions & 88 deletions spellings/tools/ablexicon

This file was deleted.

Loading