Skip to content

Commit 2d8325b

Browse files
Run crate-ci/typos in CI (#51704)
Co-authored-by: Dilum Aluthge <[email protected]>
1 parent a6d9df7 commit 2d8325b

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

.github/workflows/Typos.yml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Typos
2+
3+
permissions: {}
4+
5+
on: [pull_request]
6+
7+
jobs:
8+
typos-check:
9+
name: Check for new typos
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 5
12+
steps:
13+
- name: Checkout the JuliaLang/julia repository
14+
uses: actions/checkout@v4
15+
with:
16+
persist-credentials: false
17+
- name: Check spelling with typos
18+
#uses: crate-ci/typos@master
19+
env:
20+
GH_TOKEN: "${{ github.token }}"
21+
run: |
22+
git fetch --depth=1 origin ${{ github.base_ref }}
23+
OLD_FILES=$(git diff-index --name-only --diff-filter=ad FETCH_HEAD)
24+
NEW_FILES=$(git diff-index --name-only --diff-filter=d FETCH_HEAD)
25+
26+
mkdir -p "${{ runner.temp }}/typos"
27+
RELEASE_ASSET_URL="$(
28+
gh api /repos/crate-ci/typos/releases/latest \
29+
--jq '."assets"[] | select(."name" | test("^typos-.+-x86_64-unknown-linux-musl\\.tar\\.gz$")) | ."browser_download_url"'
30+
)"
31+
wget --secure-protocol=TLSv1_3 --max-redirect=1 --retry-on-host-error --retry-connrefused --tries=3 \
32+
--quiet --output-document=- "${RELEASE_ASSET_URL}" \
33+
| tar -xz -C "${{ runner.temp }}/typos" ./typos
34+
"${{ runner.temp }}/typos/typos" --version
35+
36+
echo -n $NEW_FILES | xargs "${{ runner.temp }}/typos/typos" --format json >> ${{ runner.temp }}/new_typos.jsonl || true
37+
git checkout FETCH_HEAD -- $OLD_FILES
38+
echo -n $OLD_FILES | xargs "${{ runner.temp }}/typos/typos" --format json >> ${{ runner.temp }}/old_typos.jsonl || true
39+
40+
python -c '
41+
import sys, json
42+
old = set()
43+
with open(sys.argv[1]) as old_file:
44+
for line in old_file:
45+
old.add(json.loads(line)["typo"])
46+
clean = True
47+
with open(sys.argv[2]) as new_file:
48+
for line in new_file:
49+
new = json.loads(line)
50+
if new["typo"] not in old:
51+
if len(new["typo"]) > 6: # Short typos might be false positives. Long are probably real.
52+
clean = False
53+
print("::warning file={},line={},col={}::perhaps \"{}\" should be \"{}\".".format(
54+
new["path"], new["line_num"], new["byte_offset"],
55+
new["typo"], " or ".join(new["corrections"])))
56+
sys.exit(1 if not clean else 0)' "${{ runner.temp }}/old_typos.jsonl" "${{ runner.temp }}/new_typos.jsonl"

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,8 @@ External dependencies
125125
Tooling Improvements
126126
--------------------
127127

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

129132
<!--- generated by NEWS-update.jl: -->

typos.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[default]
2+
extend-ignore-words-re = ["^[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?[a-zA-Z]?$"]

0 commit comments

Comments
 (0)