Skip to content

Commit

Permalink
ci: Auto-update cspell dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Oct 20, 2024
1 parent a3df294 commit c4eb96f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ concurrency:
jobs:
tidy:
uses: taiki-e/github-actions/.github/workflows/tidy.yml@main
permissions:
contents: read
pull-requests: write # for gh pr edit --add-assignee
repository-projects: read # for gh pr edit --add-assignee
secrets: inherit

test:
strategy:
Expand Down
40 changes: 28 additions & 12 deletions tools/tidy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,10 @@ EOF
if [[ -n "${dependencies_words:-}" ]]; then
echo $'\n'"${dependencies_words}" >>.github/.cspell/rust-dependencies.txt
fi
check_diff .github/.cspell/rust-dependencies.txt
if ! grep -Eq "^\.github/\.cspell/rust-dependencies.txt linguist-generated" .gitattributes; then
if [[ -z "${REMOVE_UNUSED_WORDS:-}" ]]; then
check_diff .github/.cspell/rust-dependencies.txt
fi
if ! grep -Fq '.github/.cspell/rust-dependencies.txt linguist-generated' .gitattributes; then
error "you may want to mark .github/.cspell/rust-dependencies.txt linguist-generated"
fi

Expand All @@ -443,17 +445,31 @@ EOF
done

# Make sure the project-specific dictionary does not contain unused words.
unused=''
for word in $(grep -v '//.*' "${project_dictionary}" || true); do
if ! grep <<<"${all_words}" -Eq -i "^${word}$"; then
unused+="${word}"$'\n'
if [[ -n "${REMOVE_UNUSED_WORDS:-}" ]]; then
grep_args=()
for word in $(grep -Ev '^//.*' "${project_dictionary}" || true); do
if ! grep -Eqi "^${word}$" <<<"${all_words}"; then
grep_args+=(-e "^${word}$")
fi
done
if [[ ${#grep_args[@]} -gt 0 ]]; then
info "removing unused words from ${project_dictionary}"
res=$(grep -Ev "${grep_args[@]}" "${project_dictionary}")
printf '%s\n' "${res}" >|"${project_dictionary}"
fi
else
unused=''
for word in $(grep -Ev '^//.*' "${project_dictionary}" || true); do
if ! grep -Eqi "^${word}$" <<<"${all_words}"; then
unused+="${word}"$'\n'
fi
done
if [[ -n "${unused}" ]]; then
error "unused words in dictionaries; please remove the following words from ${project_dictionary} or run ${0##*/} with REMOVE_UNUSED_WORDS=1"
printf '=======================================\n'
printf '%s' "${unused}"
printf '=======================================\n'
fi
done
if [[ -n "${unused}" ]]; then
error "unused words in dictionaries; please remove the following words from ${project_dictionary}"
echo "======================================="
echo -n "${unused}"
echo "======================================="
fi
fi
fi
Expand Down

0 comments on commit c4eb96f

Please sign in to comment.