From cca7a1b2ff20e8a5b3fd38a1d276c9f29bdeccf8 Mon Sep 17 00:00:00 2001 From: Matthias Kay Date: Mon, 6 Jan 2025 13:09:18 +0100 Subject: [PATCH] VALIDATE-DICTIONARIES --- .../workflows/default_spelling_callable.yml | 21 ++++++++++ .../workflows/scripts/check_dictionaries.sh | 42 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100755 .github/workflows/scripts/check_dictionaries.sh diff --git a/.github/workflows/default_spelling_callable.yml b/.github/workflows/default_spelling_callable.yml index a4464ea..5f5bf15 100644 --- a/.github/workflows/default_spelling_callable.yml +++ b/.github/workflows/default_spelling_callable.yml @@ -19,3 +19,24 @@ jobs: - uses: streetsidesoftware/cspell-action@ef95dc49d631fc2a9e9ea089ae2b2127b7c4588e # v6.10.0 with: config: .config/cspell.json + + find-changes-for-shell-output: + runs-on: ubuntu-latest + steps: + - uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 + id: changes-for-shell + with: + list-files: "shell" + filters: | + markdown: + - added|modified: '.config/dictionaries/*.txt' + outputs: + dictionaries: ${{ steps.changes-for-shell.outputs.dictionaries }} + + validate-dictionaries: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - run: .github/workflows/scripts/validate-dictionaries.sh + if: needs.find-changes-for-shell-output.outputs.dictionaries == 'true' diff --git a/.github/workflows/scripts/check_dictionaries.sh b/.github/workflows/scripts/check_dictionaries.sh new file mode 100755 index 0000000..27f63c7 --- /dev/null +++ b/.github/workflows/scripts/check_dictionaries.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +set -euo pipefail + +MISSPELLED_WORDS_PATH="misspelled-words.txt" + +CSPELL_CONFIGURATION_FILE=$(find . -name "cspell.json" | head -n 1) +DICTIONARIES_PATH=".config/dictionaries" +mapfile -t DICTIONARY_FILES_TO_CHECK < <(ls .config/dictionaries/*.txt) + +# Make a list of every misspelled word without any custom dictionaries and configuration file +mv "$CSPELL_CONFIGURATION_FILE" "${CSPELL_CONFIGURATION_FILE}.temp" +npx cspell . --dot --no-progress --no-summary --unique --words-only --no-exit-code --exclude ".git/**" --exclude "$DICTIONARIES_PATH/**" | sort --ignore-case --unique > "$MISSPELLED_WORDS_PATH" + +# Check the custom dictionaries +ONE_OR_MORE_FAILURES=0 +for DICTIONARY_NAME in "${DICTIONARY_FILES_TO_CHECK[@]}"; do + # Check alphabetically sorted and unique + echo "Checking for orphaned words in dictionary: $DICTIONARY_NAME" + + # ensure the dictionary is sorted and unique + sort --ignore-case --unique --check "$DICTIONARY_NAME" + + # Check that each word in the dictionary is actually being used + while IFS= read -r line; do + line=$(echo "$line" | tr -d '\r\n') + + if ! grep "$line" "$MISSPELLED_WORDS_PATH" --ignore-case --silent ; then + echo "The following word in the $DICTIONARY_NAME dictionary is not being used: ($line)" + ONE_OR_MORE_FAILURES=1 + fi + done < "$DICTIONARY_NAME" +done + +rm -f "$MISSPELLED_WORDS_PATH" + +if [ $ONE_OR_MORE_FAILURES -ne "0" ]; then + echo "Dictionary check failed." + exit 1 +fi + +echo "All dictionaries are valid."