Skip to content

Commit a418b2b

Browse files
authored
CSpell Action (#75)
* Update the spell check action to use cSpell, add in exclude dirs and files directly, update tests to account for it, move the .cSpellWords.txt file to live in .github * Changes to the cspell action to account for running in a different directory, updating the config file as well
1 parent 56a27af commit a418b2b

File tree

7 files changed

+190
-335
lines changed

7 files changed

+190
-335
lines changed

.github/workflows/test.yml

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,58 @@ jobs:
8383
test-spell-check:
8484
runs-on: ubuntu-latest
8585
steps:
86-
- uses: actions/checkout@v2
87-
- uses: actions/checkout@v2
86+
- uses: actions/checkout@v3
87+
88+
- uses: actions/checkout@v3
8889
with:
89-
repository: FreeRTOS/coreMQTT
90-
ref: main
90+
repository: skptak/coreMQTT
91+
ref: CI-CD-Updates
9192
path: coreMQTT
93+
9294
- name: Test spell check action
9395
uses: ./spellings
9496
with:
9597
path: coreMQTT
9698

99+
test-spell-checker-find-mistake:
100+
runs-on: ubuntu-latest
101+
steps:
102+
- uses: actions/checkout@v3
103+
104+
- uses: actions/checkout@v3
105+
with:
106+
repository: skptak/coreMQTT
107+
ref: CI-CD-Updates
108+
path: coreMQTT
109+
110+
- name: Empty the lexicon
111+
shell: bash
112+
working-directory: coreMQTT
113+
run: file=$(find . -name .cSpellWords.txt); readlink -f "$file" ; > "$file"
114+
115+
- name: Test Spell Check Fails on Misspelled Word
116+
continue-on-error: true
117+
id: test-spellings-find-mistake
118+
uses: ./spellings
119+
with:
120+
path: coreMQTT
121+
122+
- env:
123+
stepName: Check Failure Test Case
124+
name: ${{ env.stepName }}
125+
id: check-failure-test-cases
126+
shell: bash
127+
run: |
128+
# ${{ env.stepName }}
129+
exitStatus=0
130+
if [ "${{ steps.test-spellings-find-mistake.outcome}}" = "failure" ]; then
131+
echo -e "${{ env.bashPass }} Functional | Failure | Fail on Misspelled Word | Had Expected "failure" ${{ env.bashEnd }}"
132+
else
133+
echo -e "${{ env.bashFail }} Functional | Failure | Fail on Misspelled Word | Had Unexpected "success" ${{ env.bashEnd }}"
134+
exitStatus=1
135+
fi
136+
exit $exitStatus
137+
97138
test-coverage-cop:
98139
runs-on: ubuntu-latest
99140
steps:

spellings/action.yml

Lines changed: 114 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,123 @@
11
name: 'spellings'
2-
description: 'CI spellings check'
2+
description: 'cSpell CI spelling check'
33
inputs:
44
path:
55
description: 'Path to repository folder to check spellings in.'
66
required: false
77
default: ./
8+
exclude-dirs:
9+
description: "Comma separated list of directories to not spell check"
10+
required: false
11+
exclude-files:
12+
description: "Comma separated list of files to not spell check"
13+
required: false
14+
include-extensions:
15+
description: "Comma separated list of files to match to regex"
16+
required: false
17+
18+
819
runs:
920
using: "composite"
1021
steps:
11-
- name: Install spell
12-
run: |
13-
sudo apt-get install spell
14-
sudo apt-get install util-linux
15-
shell: bash
16-
- name: Check spelling
17-
working-directory: ${{ inputs.path }}
18-
run: |
19-
PATH=$PATH:$GITHUB_ACTION_PATH/tools
20-
for lexfile in `find ./ -name lexicon.txt`
21-
do dir=${lexfile%/lexicon.txt}
22-
echo $dir
23-
find-unknown-comment-words --directory $dir
24-
if [ $? -ne "0" ]
25-
then
26-
exit 1
27-
fi
28-
done
29-
shell: bash
22+
- env:
23+
bashPass: \033[32;1mPASSED -
24+
bashInfo: \033[33;1mINFO -
25+
bashFail: \033[31;1mFAILED -
26+
bashEnd: \033[0m
27+
stepName: Set-Up The Spell Checker
28+
name: ${{ env.stepName }}
29+
id: spell-checker-setup
30+
shell: bash
31+
run: |
32+
# ${{ env.stepName }}
33+
echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}"
34+
35+
# Install the Dependencies we need to run the spell-checker
36+
sudo apt-get install util-linux -y
37+
sudo apt-get install fd-find -y
38+
sudo apt-get install npm -y
39+
sudo npm install -g cspell
40+
echo -e "::endgroup::"
41+
42+
# Add the Github Action Path to PATH
43+
export PATH="$GITHUB_ACTION_PATH:$PATH"
44+
45+
# Account for starting with an alternate path in a repository
46+
# Do this by copying the cspell config and wordlist to the desired path
47+
# Wrap in a set +e so Github doesn't throw an error if the file or
48+
# directory already exists.
49+
set +e
50+
cp cspell.config.yaml ${{ inputs.path }}
51+
mkdir ${{ inputs.path }}/.github
52+
cp .github/.cSpellWords.txt ${{ inputs.path }}/.github
53+
cd ${{ inputs.path }}
54+
set -e
55+
56+
# Make sure we have all the commands we need.
57+
echo -e "${{ env.bashInfo }} fdfind --version $(fdfind --version) ${{ env.bashEnd }}"
58+
echo -e "${{ env.bashInfo }} cspell --version $(cspell --version) ${{ env.bashEnd }}"
59+
60+
# Only reach this line if no errors were hit above
61+
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
62+
63+
- env:
64+
bashPass: \033[32;1mPASSED -
65+
bashInfo: \033[33;1mINFO -
66+
bashFail: \033[31;1mFAILED -
67+
bashEnd: \033[0m
68+
stepName: Spell Checker
69+
name: ${{ env.stepName }}
70+
id: run-spell-checker
71+
working-directory: ${{ inputs.path }}
72+
shell: bash
73+
run: |
74+
# ${{ env.stepName }}
75+
#echo -e "::group::${{ env.stepName }}"
76+
export PATH="$GITHUB_ACTION_PATH:$PATH"
77+
exitStatus=0
78+
79+
# Parse the optional inputs
80+
args=""
81+
82+
# fd-find uses -E to exclude a file or directory
83+
if [ -n "${{ inputs.exclude-dirs }}" ]; then
84+
dirs=" -E "
85+
dirs+="${{ inputs.exclude-dirs }}"
86+
dirs="${dirs//,/ -E }"
87+
args+=" ${dirs}"
88+
fi
89+
90+
# fd-find uses -E to exclude a file or directory
91+
if [ -n "${{ inputs.exclude-files }}" ]; then
92+
files=" -E "
93+
files+="${{ inputs.exclude-files }}"
94+
files="${files//,/ -E }"
95+
args+=" ${files}"
96+
fi
97+
98+
# fd-find uses -e to exclude a file extension
99+
if [ -n "${{ inputs.include-file-types }}" ]; then
100+
file_types=" -e "
101+
file_types+="${{ inputs.include-file-types }}"
102+
file_types="${file_types//,/ -e }"
103+
args+=" ${file_types}"
104+
fi
105+
106+
echo -e "${{ env.bashInfo }} Running: fdfind -e c -e h -e md -e txt -e readme ${args} --exec cspell lint --language-id C --color --show-context --show-suggestions --no-must-find-files -c cspell.config.yaml ${{ env.bashEnd }}"
107+
108+
# Wrap in a set +e so Github doesn't stop the spell check from running
109+
set +e
110+
111+
# Find all relevant files, then check them for spelling mistakes
112+
fdfind -e c -e h -e md -e txt -e readme ${args} --exec-batch \
113+
cspell lint --language-id C --color --show-context --show-suggestions --no-must-find-files -c cspell.config.yaml
114+
exitStatus=$?
115+
set -e
116+
117+
echo -e "::endgroup::"
118+
if [ $exitStatus -eq 0 ]; then
119+
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
120+
else
121+
echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
122+
fi
123+
exit $exitStatus

spellings/cspell.config.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
$schema: https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json
3+
version: '0.2'
4+
# Allows things like stringLength
5+
allowCompoundWords: true
6+
7+
# Read files not to spell check from the git ignore
8+
useGitignore: true
9+
10+
# Language settings for C
11+
languageSettings:
12+
- caseSensitive: false
13+
enabled: true
14+
languageId: c
15+
locale: "*"
16+
17+
# Add a dictionary, and the path to the word list
18+
dictionaryDefinitions:
19+
- name: freertos-words
20+
path: '.github/.cSpellWords.txt'
21+
addWords: true
22+
23+
dictionaries:
24+
- freertos-words
25+
26+
# Paths and files to ignore
27+
ignorePaths:
28+
- 'dependency'
29+
- 'docs'
30+
- 'ThirdParty'
31+
- 'History.txt'

spellings/tools/README.md

Lines changed: 0 additions & 30 deletions
This file was deleted.

spellings/tools/ablexicon

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)