-
Notifications
You must be signed in to change notification settings - Fork 19
86 lines (78 loc) · 2.93 KB
/
Copy pathspellcheck.yml
File metadata and controls
86 lines (78 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: Spell Check
on:
push:
branches: [main]
paths:
- '**.md'
- '**.yml'
- '**.yaml'
- '.typos.toml'
pull_request:
paths:
- '**.md'
- '**.yml'
- '**.yaml'
- '.typos.toml'
permissions:
contents: read
jobs:
typos:
runs-on: ubuntu-26.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Run typos
env:
TYPOS_VERSION: "1.44.0"
run: |
set -o pipefail
case "$(uname -m)" in
x86_64|amd64) target="x86_64-unknown-linux-musl" ;;
aarch64|arm64) target="aarch64-unknown-linux-musl" ;;
*)
echo "Unsupported architecture: $(uname -m)"
exit 1
;;
esac
install_dir="$(mktemp -d)"
curl -fsSL "https://github.com/crate-ci/typos/releases/download/v${TYPOS_VERSION}/typos-v${TYPOS_VERSION}-${target}.tar.gz" -o /tmp/typos.tar.gz
tar -xzf /tmp/typos.tar.gz -C "$install_dir" --strip-components=1 --no-same-owner --no-same-permissions
typos="$install_dir/typos"
# 1) Check markdown files directly
find . -type f -name '*.md' -not -path './.git/*' \
| "$typos" --config .typos.toml --file-list - --force-exclude
# 2) Check only comments in YAML files.
# Extract comment text (full-line and inline) preserving line numbers.
# Non-comment lines become empty so typos reports correct positions.
comment_dir="$(mktemp -d)"
find . -type f \( -name '*.yml' -o -name '*.yaml' \) \
-not -path './.git/*' | while IFS= read -r f; do
dest="$comment_dir/$f"
mkdir -p "$(dirname "$dest")"
awk '{
# Full-line comment (most common)
if (/^[[:space:]]*#/) {
sub(/^[[:space:]]*#[[:space:]]?/, ""); print; next
}
# Inline comment: walk line tracking quotes, find " #" outside strings
n = length($0); dq = 0; sq = 0; cs = 0
for (j = 1; j <= n; j++) {
c = substr($0, j, 1)
if (c == "\"" && !sq) dq = !dq
else if (c == "\047" && !dq) sq = !sq
else if (c == "#" && !dq && !sq && j > 1 && substr($0, j-1, 1) == " ") {
cs = j; break
}
}
if (cs) { s = substr($0, cs + 1); sub(/^[[:space:]]?/, "", s); print s }
else print ""
}' "$f" > "$dest"
done
# Run from inside comment_dir so paths are repo-relative,
# matching extend-exclude patterns in .typos.toml.
(
cd "$comment_dir"
find . -type f \( -name '*.yml' -o -name '*.yaml' \) \
| "$typos" --config "$GITHUB_WORKSPACE/.typos.toml" --file-list - --force-exclude
)