From 23a2de6b2fb4fa06ab5841d10664852209f812d3 Mon Sep 17 00:00:00 2001 From: Lilith Hafner Date: Mon, 16 Oct 2023 11:00:20 -0500 Subject: [PATCH] use set-diff (python instead of bash to get O(n)) --- .github/workflows/SpellCheck.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/SpellCheck.yml b/.github/workflows/SpellCheck.yml index a22a81d887487..82bdafe615900 100644 --- a/.github/workflows/SpellCheck.yml +++ b/.github/workflows/SpellCheck.yml @@ -30,6 +30,16 @@ jobs: --quiet --output-document=- "${RELEASE_ASSET_URL}" \ | tar -xz -C "${{ runner.temp }}/typos" ./typos "${{ runner.temp }}/typos/typos" --version - git diff-index --name-only --diff-filter=d -z FETCH_HEAD \ - | xargs -0 "${{ runner.temp }}/typos/typos" --format json \ - | jq --raw-output '"::warning file=\(.path),line=\(.line_num),col=\(.byte_offset)::perhaps \"\(.typo)\" should be \"" + (.corrections // [] | join("\" or \"") + "\".")' \ No newline at end of file + OLD_FILES=$(git diff-index --name-only --diff-filter=ad -z FETCH_HEAD) + NEW_FILES=$(git diff-index --name-only --diff-filter=d -d FETCH_HEAD) + NEW_TYPOS=$(echo -n $NEW_FILES | xargs -0 "${{ runner.temp }}/typos/typos" --format json) + git checkout FETCH_HEAD -- $OLD_FILES + OLD_TYPOS=$(echo -n $OLD_FILES | xargs -0 "${{ runner.temp }}/typos/typos" --format json) + python -c ' +import sys, json +existing = set(typo["typo"] for typo in json.loads("["+sys.argv[1].replace("\n", ",")+"]")) +for new in json.loads("["+sys.argv[2].replace("\n", ",")+"]"): + if new["typo"] not in existing: + print("::warning file={},line={},col={}::perhaps \"{}\" should be \"{}\".".format( + new["path"], new["line_num"], new["byte_offset"], + new["typo"], " or ".join(new["corrections"])))' "$OLD_TYPOS" "$NEW_TYPOS"