From ef0da4fc7048dd273bca1708e9e3cc8c97fcf49f Mon Sep 17 00:00:00 2001 From: k32 <10274441+k32@users.noreply.github.com> Date: Thu, 17 Feb 2022 23:19:04 +0100 Subject: [PATCH] ci: Spellcheck documentation in the CI --- .github/workflows/spelling.yml | 25 ++++ scripts/dict/.aspell.en | 246 --------------------------------- scripts/spellcheck | 87 +++--------- 3 files changed, 43 insertions(+), 315 deletions(-) create mode 100644 .github/workflows/spelling.yml delete mode 100644 scripts/dict/.aspell.en diff --git a/.github/workflows/spelling.yml b/.github/workflows/spelling.yml new file mode 100644 index 000000000..a5dd8a981 --- /dev/null +++ b/.github/workflows/spelling.yml @@ -0,0 +1,25 @@ +name: Spellcheck + +on: + workflow_run: + workflows: [Build slim packages] + types: + - completed + +jobs: + spellcheck_schema: + runs-on: ubuntu-latest + + strategy: + fail-fast: true + + steps: + - uses: actions/checkout@v2 + - uses: actions/download-artifact@v2 + with: + name: emqx-24.1.5-4-ubuntu20.04 + path: . + - name: Run spellcheck + run: | + tar zxf *.tar.gz + find . -name schema.json -exec scripts/spellcheck \{\} \; diff --git a/scripts/dict/.aspell.en b/scripts/dict/.aspell.en deleted file mode 100644 index 84a57c975..000000000 --- a/scripts/dict/.aspell.en +++ /dev/null @@ -1,246 +0,0 @@ -personal_ws-1.1 en 254 -ACL -AES -APIs -BPAPI -BSON -Backplane -CHACHA -CLI -CMD -CN -CONNACK -CoAP -Cygwin -DES -DN -DNS -DTLS -DevOps -Dialyzer -Diffie -EIP -EMQ -EPMD -ERL -ETS -FIXME -GCM -Gw -HOCON -HTTPS -JSON -Kubernetes -LwM -MQTT -Makefile -MitM -Multicast -NIF -OTP -PEM -PINGREQ -PSK -PUBREL -QoS -RESTful -ROADMAP -RSA -Req -Riak -SHA -SMS -Struct -TCP -TLS -TTL -UDP -URI -XMLs -acceptors -ack -acked -addr -api -apiserver -arg -args -async -attr -auth -authenticator -authenticators -authn -authz -autoclean -autoheal -backend -backends -backoff -backplane -backtrace -badarg -badkey -bcrypt -behaviour -bhvr -boolean -bytesize -cacert -cacertfile -certfile -ci -clientid -clientinfo -cmake -coap -conf -config -configs -confirmable -conn -connectionless -cors -cpu -ctx -customizable -desc -dir -dns -downlink -downlink -dtls -ekka -emqx -enablement -enqueue -enqueued -env -eof -epmd -erl -erts -escript -etcd -eval -exe -executables -exhook -exproto -extensibility -formatter -gRPC -github -goto -grpcbox -hocon -hoconsc -hostname -hrl -http -https -iface -img -impl -inet -inflight -ini -init -ip -ipv -jenkins -jq -kb -keepalive -libcoap -lifecycle -localhost -lwm -mnesia -mountpoint -mqueue -mria -msg -multicalls -multicasts -namespace -natively -nodelay -nodetool -nullable -num -os -params -peerhost -peername -perf -powershell -procmem -procs -progname -prometheus -proto -ps -psk -pubsub -qlen -qmode -qos -quic -ratelimit -rebar -recbuf -relup -replayq -replicant -repo -reuseaddr -rh -rlog -rootdir -rpc -runtime -sc -scalable -seg -setcookie -sharded -shareload -sn -sndbuf -sockname -sql -src -ssl -statsd -structs -subprotocol -subprotocols -superset -sys -sysmem -sysmon -tcp -ticktime -tlog -tls -tlsv -travis -trie -ttl -typerefl -udp -uid -unsub -uplink -url -utc -util -ver -vm -vsn -wakaama -websocket -ws -wss -xml diff --git a/scripts/spellcheck b/scripts/spellcheck index 37d72281f..7bf999fbd 100755 --- a/scripts/spellcheck +++ b/scripts/spellcheck @@ -1,72 +1,21 @@ #!/bin/bash -# shellcheck disable=SC2015 -set -euo pipefail +set -uo pipefail -aspell -v > /dev/null && [ "$#" -eq 1 ] || { - echo "Usage: - $(basename "$0") check -or - $(basename "$0") fix - -Note: this script needs aspell to run" - exit 1 -} - -action=$1 - -dict_dir="$(git rev-parse --show-toplevel)/$(dirname "$0")/dict" -echo "${dict_dir}" -dict="${dict_dir}/.aspell.en" - -export fail=0 - -aspellcmd() { - local mode - mode="${1}" - shift - aspell --mode "${mode}" --camel-case --add-filter html --add-html-skip code -p "$dict" "$@" -} - -check() { - local mode file typos ntypos - mode="$1" - file="$2" - - echo "!! Spellchecking ${file}" - typos="$(mktemp)" - echo "!! Typos:" - aspellcmd "$mode" list < "$file" | - sort -u | - tee "$typos" - ntypos="$(wc -l "$typos")" - rm "$typos" - [ "$ntypos" = 0 ] || export fail=1 -} - -fix() { - local mode file - mode=$1 - file=$2 - - aspellcmd "$mode" check "$file" -} - -case $action in - fix) - for i in $(git ls-tree -r --name-only HEAD | grep -E '_schema.erl$'); do - fix perl "$i" - done - # for i in $(git ls-tree -r --name-only HEAD | grep -E '.md$'); do - # fix markdown $i - # done - ;; - *) - check markdown _build/emqx/lib/emqx_dashboard/priv/www/static/config.md -esac - - -if [ $fail -eq 1 ]; then - echo - echo "!! Bad spelling in the documentation. Run script in fix mode to resolve problems." - exit 1 +if [ -z "${1:-}" ]; then + SCHEMA="_build/emqx/lib/emqx_dashboard/priv/www/static/schema.json" +else + SCHEMA="$1" fi + +docker run -d --name langtool "ghcr.io/k32/emqx-schema-validate:0.1.0" + +docker exec -i langtool ./emqx_schema_validate - < "${SCHEMA}" +success="$?" + +docker kill langtool || true +docker rm langtool || true + +echo "If this script finds a false positive (e.g. when it things that a protocol name is a typo), +make a PR here: https://github.com/k32/emqx-schema-validate/blob/master/dict/en_spelling_additions.txt" + +exit "$success"