spellcheck.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. # ensure dir
  4. cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")/../.."
  5. PROJ_ROOT="$(pwd)"
  6. NUM_JOBS=10
  7. while getopts "j:" FLAG; do
  8. case "$FLAG" in
  9. j)
  10. NUM_JOBS="${OPTARG}"
  11. ;;
  12. *)
  13. echo "unknown flag: $FLAG"
  14. ;;
  15. esac
  16. done
  17. shift $((OPTIND-1))
  18. if [ -z "${1:-}" ]; then
  19. SCHEMA="${PROJ_ROOT}/_build/docgen/emqx/schema-en.json"
  20. else
  21. SCHEMA="$(realpath "$1")"
  22. fi
  23. if ! [ -f "$SCHEMA" ]; then
  24. echo "Schema file $SCHEMA does not exist; did you forget to run 'make emqx{,-enterprise}' ?"
  25. exit 1
  26. fi
  27. if [[ -t 1 ]];
  28. then
  29. DOCKER_TERMINAL_OPT="-t"
  30. else
  31. DOCKER_TERMINAL_OPT=""
  32. fi
  33. set +e
  34. # shellcheck disable=SC2086
  35. docker run --rm -i ${DOCKER_TERMINAL_OPT} --name spellcheck \
  36. -v "${PROJ_ROOT}"/scripts/spellcheck/dicts:/dicts \
  37. -v "$SCHEMA":/schema.json \
  38. ghcr.io/emqx/emqx-schema-validate:0.5.1 -j "${NUM_JOBS}" /schema.json
  39. result="$?"
  40. if [ "$result" -eq 0 ]; then
  41. echo "Spellcheck OK"
  42. exit 0
  43. fi
  44. echo "If this script finds a false positive (e.g. when it thinks that a protocol name is a typo),"
  45. echo "Add the word to dictionary in scripts/spellcheck/dicts"
  46. exit $result