From cc8936f1b9a06f93c16d6488ee9b8044d5982b77 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Fri, 25 Oct 2024 20:25:33 +0900 Subject: [PATCH 1/3] Auto-update cspell dictionary --- .github/workflows/ci.yml | 31 +++++++++++++++++++++ tools/spell-check.sh | 60 ++++++++++++++++++++++++++++++---------- 2 files changed, 76 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68caf53..a16c85c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,8 @@ name: CI +permissions: + contents: read + on: push: branches: [main] @@ -114,6 +117,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 "taiki@smilerobotics.com" + 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' diff --git a/tools/spell-check.sh b/tools/spell-check.sh index 89ef6ad..17e9a02 100755 --- a/tools/spell-check.sh +++ b/tools/spell-check.sh @@ -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='' @@ -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. @@ -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 From 354b7d3d4c175e006cac9ea6d6fdd0612f2a3d11 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Fri, 25 Oct 2024 20:25:40 +0900 Subject: [PATCH 2/3] Revert "Disable dependabot update for Github Actions" This reverts commit 07269b7b6fc4340dbc71a3a759d1f70cf237e000. --- .github/dependabot.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 496bfe0..92e8285 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -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: [] From dea4e52bdf7ed797de87189d8af395608315e81b Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Fri, 25 Oct 2024 20:25:45 +0900 Subject: [PATCH 3/3] Pin rustc to 1.81 for wasm --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a16c85c..ff6fc4c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -83,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