Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-update cspell dictionary & re-enable dependabot update for Github Actions #268

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ updates:
# These dependencies need to be updated at the same time with k.
- dependency-name: urdf-rs
labels: []
- package-ecosystem: github-actions
directory: /
schedule:
interval: daily
commit-message:
prefix: ''
labels: []
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: CI

permissions:
contents: read

on:
push:
branches: [main]
Expand Down Expand Up @@ -80,6 +83,8 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
# TODO: Pin to 1.81 due to https://github.com/webpack/webpack/issues/15566
toolchain: '1.81'
targets: wasm32-unknown-unknown
- name: Install wasm-pack
uses: taiki-e/install-action@wasm-pack
Expand Down Expand Up @@ -114,6 +119,34 @@ jobs:
spell-check:
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- run: echo "REMOVE_UNUSED_WORDS=1" >>"${GITHUB_ENV}"
if: github.repository_owner == 'openrr' && (github.event_name == 'schedule' || github.event_name == 'push' && github.ref == 'refs/heads/main')
- run: tools/spell-check.sh
- id: diff
run: |
set -euo pipefail
git config user.name "Taiki Endo"
git config user.email "[email protected]"
git add -N .github/.cspell
if ! git diff --exit-code -- .github/.cspell; then
git add .github/.cspell
git commit -m "Update cspell dictionary"
echo 'success=false' >>"${GITHUB_OUTPUT}"
fi
if: github.repository_owner == 'openrr' && (github.event_name == 'schedule' || github.event_name == 'push' && github.ref == 'refs/heads/main')
- uses: peter-evans/create-pull-request@v7
with:
title: Update cspell dictionary
body: |
Auto-generated by [create-pull-request][1]
[Please close and immediately reopen this pull request to run CI.][2]

[1]: https://github.com/peter-evans/create-pull-request
[2]: https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#workarounds-to-trigger-further-workflow-runs
branch: update-cspell-dictionary
if: github.repository_owner == 'openrr' && (github.event_name == 'schedule' || github.event_name == 'push' && github.ref == 'refs/heads/main') && steps.diff.outputs.success == 'false'
60 changes: 45 additions & 15 deletions tools/spell-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ error() {
fi
should_fail=1
}
warn() {
if [[ -n "${GITHUB_ACTIONS:-}" ]]; then
echo "::warning::$*"
else
echo >&2 "warning: $*"
fi
}

project_dictionary=.github/.cspell/project-dictionary.txt
has_rust=''
Expand Down Expand Up @@ -61,11 +68,17 @@ EOF
if [[ -n "${dependencies_words:-}" ]]; then
echo $'\n'"${dependencies_words}" >>.github/.cspell/rust-dependencies.txt
fi
check_diff .github/.cspell/rust-dependencies.txt
if [[ -z "${REMOVE_UNUSED_WORDS:-}" ]]; then
check_diff .github/.cspell/rust-dependencies.txt
fi

echo "+ npx -y cspell --no-progress --no-summary \$(git ls-files)"
if ! npx -y cspell --no-progress --no-summary $(git ls-files); then
error "spellcheck failed: please fix uses of above words or add to ${project_dictionary} if correct"
error "spellcheck failed: please fix uses of below words or add to ${project_dictionary} if correct"
echo >&2 "======================================="
(npx -y cspell --no-progress --no-summary --words-only $(git ls-files) || true) | LC_ALL=C sort -f -u >&2
echo >&2 "======================================="
echo >&2
fi

# Make sure the project-specific dictionary does not contain duplicated words.
Expand All @@ -76,24 +89,41 @@ for dictionary in .github/.cspell/*.txt; do
dup=$(sed '/^$/d' "${project_dictionary}" "${dictionary}" | LC_ALL=C sort -f | uniq -d -i | (grep -v '//.*' || true))
if [[ -n "${dup}" ]]; then
error "duplicated words in dictionaries; please remove the following words from ${project_dictionary}"
echo "======================================="
echo "${dup}"
echo "======================================="
echo >&2 "======================================="
echo >&2 "${dup}"
echo >&2 "======================================="
echo >&2
fi
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 -v '//.*' "${project_dictionary}" || true); do
if ! grep <<<"${all_words}" -Eq -i "^${word}$"; then
# TODO: single pattern with ERE: ^(word1|word2..)$
grep_args+=(-e "^${word}$")
fi
done
if [[ ${#grep_args[@]} -gt 0 ]]; then
warn "removing unused words from ${project_dictionary}"
res=$(grep -v "${grep_args[@]}" "${project_dictionary}")
echo "${res}" >"${project_dictionary}"
fi
else
unused=''
for word in $(grep -v '//.*' "${project_dictionary}" || true); do
if ! grep <<<"${all_words}" -Eq -i "^${word}$"; then
unused+="${word}"$'\n'
fi
done
if [[ -n "${unused}" ]]; then
warn "unused words in dictionaries; please remove the following words from ${project_dictionary}"
echo >&2 "======================================="
echo >&2 -n "${unused}"
echo >&2 "======================================="
echo >&2
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

if [[ -n "${should_fail:-}" ]]; then
Expand Down
Loading