Skip to content

Commit

Permalink
Run crate-ci/typos in CI (JuliaLang#51704)
Browse files Browse the repository at this point in the history
Co-authored-by: Dilum Aluthge <[email protected]>
  • Loading branch information
LilithHafner and DilumAluthge committed Oct 24, 2023
1 parent a6d9df7 commit 2d8325b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/Typos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Typos

permissions: {}

on: [pull_request]

jobs:
typos-check:
name: Check for new typos
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout the JuliaLang/julia repository
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Check spelling with typos
#uses: crate-ci/typos@master
env:
GH_TOKEN: "${{ github.token }}"
run: |
git fetch --depth=1 origin ${{ github.base_ref }}
OLD_FILES=$(git diff-index --name-only --diff-filter=ad FETCH_HEAD)
NEW_FILES=$(git diff-index --name-only --diff-filter=d FETCH_HEAD)
mkdir -p "${{ runner.temp }}/typos"
RELEASE_ASSET_URL="$(
gh api /repos/crate-ci/typos/releases/latest \
--jq '."assets"[] | select(."name" | test("^typos-.+-x86_64-unknown-linux-musl\\.tar\\.gz$")) | ."browser_download_url"'
)"
wget --secure-protocol=TLSv1_3 --max-redirect=1 --retry-on-host-error --retry-connrefused --tries=3 \
--quiet --output-document=- "${RELEASE_ASSET_URL}" \
| tar -xz -C "${{ runner.temp }}/typos" ./typos
"${{ runner.temp }}/typos/typos" --version
echo -n $NEW_FILES | xargs "${{ runner.temp }}/typos/typos" --format json >> ${{ runner.temp }}/new_typos.jsonl || true
git checkout FETCH_HEAD -- $OLD_FILES
echo -n $OLD_FILES | xargs "${{ runner.temp }}/typos/typos" --format json >> ${{ runner.temp }}/old_typos.jsonl || true
python -c '
import sys, json
old = set()
with open(sys.argv[1]) as old_file:
for line in old_file:
old.add(json.loads(line)["typo"])
clean = True
with open(sys.argv[2]) as new_file:
for line in new_file:
new = json.loads(line)
if new["typo"] not in old:
if len(new["typo"]) > 6: # Short typos might be false positives. Long are probably real.
clean = False
print("::warning file={},line={},col={}::perhaps \"{}\" should be \"{}\".".format(
new["path"], new["line_num"], new["byte_offset"],
new["typo"], " or ".join(new["corrections"])))
sys.exit(1 if not clean else 0)' "${{ runner.temp }}/old_typos.jsonl" "${{ runner.temp }}/new_typos.jsonl"
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,8 @@ External dependencies
Tooling Improvements
--------------------

* CI now performs limited automatic typo detection on all PRs. If you merge a PR with a
failing typo CI check, then the reported typos will be automatically ignored in future CI
runs on PRs that edit those same files. ([#51704])

<!--- generated by NEWS-update.jl: -->
2 changes: 2 additions & 0 deletions typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[default]
extend-ignore-words-re = ["^[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?$"]

0 comments on commit 2d8325b

Please sign in to comment.