Skip to content

Commit 0ba222c

Browse files
committed
ci: Auto-update cspell dictionary
1 parent fc3ef98 commit 0ba222c

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ concurrency:
3434
jobs:
3535
tidy:
3636
uses: taiki-e/github-actions/.github/workflows/tidy.yml@main
37+
permissions:
38+
contents: read
39+
pull-requests: write # for gh pr edit --add-assignee
40+
repository-projects: read # for gh pr edit --add-assignee
41+
secrets: inherit
3742

3843
test:
3944
needs: tidy

tools/tidy.sh

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,10 @@ EOF
418418
if [[ -n "${dependencies_words:-}" ]]; then
419419
echo $'\n'"${dependencies_words}" >>.github/.cspell/rust-dependencies.txt
420420
fi
421-
check_diff .github/.cspell/rust-dependencies.txt
422-
if ! grep -Eq "^\.github/\.cspell/rust-dependencies.txt linguist-generated" .gitattributes; then
421+
if [[ -z "${REMOVE_UNUSED_WORDS:-}" ]]; then
422+
check_diff .github/.cspell/rust-dependencies.txt
423+
fi
424+
if ! grep -Fq '.github/.cspell/rust-dependencies.txt linguist-generated' .gitattributes; then
423425
error "you may want to mark .github/.cspell/rust-dependencies.txt linguist-generated"
424426
fi
425427

@@ -443,17 +445,31 @@ EOF
443445
done
444446

445447
# Make sure the project-specific dictionary does not contain unused words.
446-
unused=''
447-
for word in $(grep -v '//.*' "${project_dictionary}" || true); do
448-
if ! grep <<<"${all_words}" -Eq -i "^${word}$"; then
449-
unused+="${word}"$'\n'
448+
if [[ -n "${REMOVE_UNUSED_WORDS:-}" ]]; then
449+
grep_args=()
450+
for word in $(grep -Ev '^//.*' "${project_dictionary}" || true); do
451+
if ! grep -Eqi "^${word}$" <<<"${all_words}"; then
452+
grep_args+=(-e "^${word}$")
453+
fi
454+
done
455+
if [[ ${#grep_args[@]} -gt 0 ]]; then
456+
info "removing unused words from ${project_dictionary}"
457+
res=$(grep -Ev "${grep_args[@]}" "${project_dictionary}")
458+
printf '%s\n' "${res}" >|"${project_dictionary}"
459+
fi
460+
else
461+
unused=''
462+
for word in $(grep -Ev '^//.*' "${project_dictionary}" || true); do
463+
if ! grep -Eqi "^${word}$" <<<"${all_words}"; then
464+
unused+="${word}"$'\n'
465+
fi
466+
done
467+
if [[ -n "${unused}" ]]; then
468+
error "unused words in dictionaries; please remove the following words from ${project_dictionary} or run ${0##*/} with REMOVE_UNUSED_WORDS=1"
469+
printf '=======================================\n'
470+
printf '%s' "${unused}"
471+
printf '=======================================\n'
450472
fi
451-
done
452-
if [[ -n "${unused}" ]]; then
453-
error "unused words in dictionaries; please remove the following words from ${project_dictionary}"
454-
echo "======================================="
455-
echo -n "${unused}"
456-
echo "======================================="
457473
fi
458474
fi
459475
fi

0 commit comments

Comments
 (0)