From c4eb96f4323edd49a674a718714c19a2ee25f10e Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Mon, 21 Oct 2024 03:12:56 +0900 Subject: [PATCH] ci: Auto-update cspell dictionary --- .github/workflows/ci.yml | 5 +++++ tools/tidy.sh | 40 ++++++++++++++++++++++++++++------------ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a6e4abfb..4ebe768c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: diff --git a/tools/tidy.sh b/tools/tidy.sh index 99b73f88..baeb320c 100755 --- a/tools/tidy.sh +++ b/tools/tidy.sh @@ -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 @@ -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