Skip to content

Commit 4b30dbc

Browse files
committed
Pull in test spell checker
1 parent d13e5db commit 4b30dbc

File tree

10 files changed

+563
-6
lines changed

10 files changed

+563
-6
lines changed

.github/workflows/spelling.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ jobs:
88
steps:
99
- uses: actions/checkout@v2.0.0
1010
with:
11-
fetch-depth: 2
11+
fetch-depth: 3
1212
- uses: ./
13-
- uses: check-spelling/check-spelling@0.0.1-alpha
1413
env:
1514
bucket: ssh://git@github.com/check-spelling/examples.git
1615
project: spelling-data-lorem

Dockerfile

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@ FROM debian:9.5-slim
33
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq update < /dev/null > /dev/null
44
RUN DEBIAN_FRONTEND=noninteractive apt-get install -qq curl git jq < /dev/null > /dev/null
55
WORKDIR /app
6-
COPY debug.sh debug.sh
6+
COPY docker-setup setup
7+
COPY reporter.json reporter.json
8+
COPY reporter.pl reporter.pl
9+
COPY w spelling-unknown-word-splitter.pl
10+
RUN ./setup
11+
RUN rm setup
712

8-
ENTRYPOINT ["/app/debug.sh"]
13+
LABEL "com.github.actions.name"="Spell Checker"
14+
LABEL "com.github.actions.description"="Check repository for spelling errors"
15+
LABEL "com.github.actions.icon"="edit-3"
16+
LABEL "com.github.actions.color"="red"
17+
18+
LABEL "repository"="http://github.com/jsoref/spelling-action"
19+
LABEL "homepage"="http://github.com/jsoref/spelling-action/tree/master/README.md"
20+
LABEL "maintainer"="Josh Soref <jsoref@noreply.users.github.com>"
21+
22+
COPY test-spelling-unknown-words test-spelling-unknown-words.sh
23+
COPY exclude exclude.pl
24+
25+
RUN chmod +x test-spelling-unknown-words.sh exclude.pl spelling-unknown-word-splitter.pl
26+
ENTRYPOINT ["/app/test-spelling-unknown-words.sh"]

action.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
1-
name: 'Debug'
2-
description: 'Debug'
1+
name: 'Spell checking'
2+
description: 'Spell check commits'
33
author: 'jsoref'
4+
branding:
5+
icon: 'edit-3'
6+
color: 'red'
7+
inputs:
8+
repo-token:
9+
description: 'The GITHUB_TOKEN secret'
10+
bucket:
11+
description: 'Container for spelling exclusions and whitelist'
12+
required: true
13+
project:
14+
description: 'Folder/Branch containing exclusions/whitelist'
15+
required: true
16+
17+
debug:
18+
description: 'Debug'
419
runs:
520
using: 'docker'
621
image: 'Dockerfile'
22+
env:
23+
bucket: ${{ inputs.bucket }}
24+
project: ${{ inputs.project }}

docker-setup

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
# This CI acceptance test is based on:
3+
# https://github.com/jsoref/spelling/tree/04648bdc63723e5cdf5cbeaff2225a462807abc8
4+
# It is conceptually `f` which runs `w` (spelling-unknown-word-splitter)
5+
# plus `fchurn` which uses `dn` mostly rolled together.
6+
set -e
7+
8+
spellchecker='/app'
9+
w_location="$spellchecker/w"
10+
temp='/tmp/spelling'
11+
dict="$spellchecker/words"
12+
word_splitter="$spellchecker/spelling-unknown-word-splitter.pl"
13+
run_output="$spellchecker/unknown.words.txt"
14+
15+
wordlist=https://github.com/check-spelling/check-spelling/raw/dictionary/dict.txt
16+
17+
mkdir -p "$temp"
18+
if [ ! -e "$dict" ]; then
19+
echo "Retrieving cached $(basename "$wordlist")"
20+
# english.words is taken from rpm:
21+
# https://rpmfind.net/linux/fedora/linux/development/rawhide/Everything/aarch64/os/Packages/w/"
22+
# "words-.*.noarch.rpm"
23+
(
24+
curl -L -s "$wordlist" -o "$dict"
25+
) >/dev/null 2>/dev/null
26+
fi

exclude

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/perl
2+
# This script takes null delimited files as input
3+
# it drops paths that match the listed exclusions
4+
# output is null delimited to match input
5+
use File::Basename;
6+
my $dirname = dirname(__FILE__);
7+
8+
my @excludes;
9+
open EXCLUDES, '<', $dirname.'/excludes.txt';
10+
while (<EXCLUDES>) {
11+
s/^\s*(.*)\s*$/$1/;
12+
push @excludes, $_;
13+
}
14+
$/="\0";
15+
my $exclude = scalar @excludes ? join "|", @excludes : '^$';
16+
while (<>) {
17+
chomp;
18+
next if m{$exclude};
19+
print "$_$/";
20+
}

reporter.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"problemMatcher": [
3+
{
4+
"owner": "jsoref-spelling",
5+
"pattern": [
6+
{
7+
"regexp": "^(.+):[\\s]line\\s(\\d+),[\\s]columns\\s(\\d+)-(\\d+),\\s(Error|Warning|Info)\\s-\\s(.+)\\s\\((.+)\\)$",
8+
"file": 1,
9+
"line": 2,
10+
"column": 3,
11+
"endColumn": 4,
12+
"severity": 5,
13+
"message": 6,
14+
"code": 7
15+
}
16+
]
17+
}
18+
]
19+
}
20+

reporter.pl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env perl
2+
3+
die 'Please set $tokens' unless defined $ENV{tokens};
4+
my $tokens=$ENV{tokens};
5+
exit 0 unless $tokens =~ /\w/;
6+
$tokens=~ s/\s+/|/g;
7+
my $re = "\\b($tokens)\\b";
8+
my $blame=defined $ENV{with_blame};
9+
10+
my $previous='';
11+
my $first_line=0;
12+
while (<>) {
13+
my $line;
14+
if ($blame) {
15+
next if /^ /;
16+
s/^[0-9a-f^]+\s+(.*?)\s(\d+)\) //;
17+
($ARGV, $line) = ($1, $2);
18+
} else {
19+
if ($previous ne $ARGV) {
20+
$previous=$ARGV;
21+
$first_line = $. - 1;
22+
}
23+
$line = $. - $first_line;
24+
}
25+
if ($blame) {
26+
next if /^ /;
27+
s/^[0-9a-f^]+\s+\d+\) //;
28+
}
29+
next unless $_ =~ /$re/;
30+
while (/$re/g) {
31+
my ($start, $token) = (1 + length $`, $1);
32+
my $stop = $start + (length $token) - 1;
33+
print "$ARGV: line $line, columns $start-$stop, Warning - '$token' is not a recognized word. (unrecognized-spelling)\n";
34+
}
35+
}

0 commit comments

Comments
 (0)