From 74a4e572f3274f8e1a0b7fe43f01f2c166e8d760 Mon Sep 17 00:00:00 2001 From: Marshall Lee <59819228+drink7036290@users.noreply.github.com> Date: Thu, 2 Jan 2025 15:48:48 +0800 Subject: [PATCH 1/2] ci: add spellcheck.dic validation (#1) --- .github/workflows/ci.yml | 29 +++++++++++++++++++++++++++-- spellcheck.dic | 3 ++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 407df8a4a54..82d2bd2acb5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1085,6 +1085,31 @@ jobs: - uses: actions/checkout@v4 - name: Make sure dictionary words are sorted and unique run: | + FILE="spellcheck.dic" + + # Verify the first line is an integer. + first_line=$(head -n 1 "$FILE") + if ! [[ "$first_line" =~ ^[0-9]+$ ]]; then + echo "Error: The first line of $FILE must be an integer, but got: '$first_line'" + exit 1 + fi + expected_count="$first_line" + + # Verify the last line is completely empty (no spaces). + last_line=$(tail -n 1 "$FILE") + if [ -n "$last_line" ]; then + echo "Error: The last line of $FILE must be empty (without spaces)." + exit 1 + fi + + # Check that the number of lines between the first and last matches the integer. + # xargs (with no arguments) will strip leading/trailing whitespace from wc's output. + actual_count=$(sed '1d;$d' "$FILE" | wc -l | xargs) + if [ "$expected_count" -ne "$actual_count" ]; then + echo "Error: The number of lines between the first and last ($actual_count) does not match $expected_count." + exit 1 + fi + # `sed` removes the first line (number of words) and # the last line (new line). # @@ -1096,10 +1121,10 @@ jobs: # environments. ( - sed '1d; $d' spellcheck.dic | LC_ALL=en_US.UTF8 sort -uc + sed '1d; $d' $FILE | LC_ALL=en_US.UTF8 sort -uc ) || { echo "Dictionary is not in sorted order. Correct order is:" - LC_ALL=en_US.UTF8 sort -u <(sed '1d; $d' spellcheck.dic) + LC_ALL=en_US.UTF8 sort -u <(sed '1d; $d' $FILE) false } - name: Run cargo-spellcheck diff --git a/spellcheck.dic b/spellcheck.dic index b9155707000..b01b1474324 100644 --- a/spellcheck.dic +++ b/spellcheck.dic @@ -1,4 +1,4 @@ -298 +299 & + < @@ -298,3 +298,4 @@ Wakers wakeup wakeups workstealing + From 18d8fea3b93c25d74799e43a6d630cfd6baab014 Mon Sep 17 00:00:00 2001 From: Marshall Lee Date: Fri, 10 Jan 2025 19:48:20 +0800 Subject: [PATCH 2/2] ci: fix double-newline issue in spellcheck.dic Remove only the first line only. Eliminate the empty line at the end of spellcheck.dic. Remove the check that enforces a trailing empty line. --- .github/workflows/ci.yml | 22 +++++++--------------- spellcheck.dic | 1 - 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 82d2bd2acb5..9f5b3aaf3fa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1095,23 +1095,15 @@ jobs: fi expected_count="$first_line" - # Verify the last line is completely empty (no spaces). - last_line=$(tail -n 1 "$FILE") - if [ -n "$last_line" ]; then - echo "Error: The last line of $FILE must be empty (without spaces)." - exit 1 - fi - - # Check that the number of lines between the first and last matches the integer. - # xargs (with no arguments) will strip leading/trailing whitespace from wc's output. - actual_count=$(sed '1d;$d' "$FILE" | wc -l | xargs) + # Check that the number of lines matches the integer. + # xargs (with no arguments) will strip leading/trailing whitespacefrom wc's output. + actual_count=$(sed '1d' "$FILE" | wc -l | xargs) if [ "$expected_count" -ne "$actual_count" ]; then - echo "Error: The number of lines between the first and last ($actual_count) does not match $expected_count." + echo "Error: The number of lines ($actual_count) does not match $expected_count." exit 1 fi - # `sed` removes the first line (number of words) and - # the last line (new line). + # `sed` removes the first line (number of words). # # `sort` makes sure everything in between is sorted # and contains no duplicates. @@ -1121,10 +1113,10 @@ jobs: # environments. ( - sed '1d; $d' $FILE | LC_ALL=en_US.UTF8 sort -uc + sed '1d' $FILE | LC_ALL=en_US.UTF8 sort -uc ) || { echo "Dictionary is not in sorted order. Correct order is:" - LC_ALL=en_US.UTF8 sort -u <(sed '1d; $d' $FILE) + LC_ALL=en_US.UTF8 sort -u <(sed '1d' $FILE) false } - name: Run cargo-spellcheck diff --git a/spellcheck.dic b/spellcheck.dic index b01b1474324..e9f7eec22f6 100644 --- a/spellcheck.dic +++ b/spellcheck.dic @@ -298,4 +298,3 @@ Wakers wakeup wakeups workstealing -