|
1 | 1 | name: 'spellings'
|
2 |
| -description: 'CI spellings check' |
| 2 | +description: 'cSpell CI spelling check' |
3 | 3 | inputs:
|
4 | 4 | path:
|
5 | 5 | description: 'Path to repository folder to check spellings in.'
|
6 | 6 | required: false
|
7 | 7 | 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 | + |
8 | 19 | runs:
|
9 | 20 | using: "composite"
|
10 | 21 | 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 |
0 commit comments