generated from reviewdog/action-template
-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
entrypoint.sh
executable file
·61 lines (51 loc) · 1.88 KB
/
entrypoint.sh
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
#!/bin/sh
set -eo pipefail
API_ENDPOINT="${INPUT_CUSTOM_API_ENDPOINT}"
if [ -z "${INPUT_CUSTOM_API_ENDPOINT}" ]; then
API_ENDPOINT=http://localhost:8010
java -cp "/LanguageTool/languagetool-server.jar" org.languagetool.server.HTTPServer --port 8010 &
echo "Wait the server startup for ${INPUT_WAIT_SERVER_STARTUP_DURATION}s"
sleep "${INPUT_WAIT_SERVER_STARTUP_DURATION}" # Wait the server startup.
fi
echo "API ENDPOINT: ${API_ENDPOINT}" >&2
if [ -n "${GITHUB_WORKSPACE}" ]; then
cd "${GITHUB_WORKSPACE}" || exit
fi
git config --global --add safe.directory $GITHUB_WORKSPACE
# https://languagetool.org/http-api/swagger-ui/#!/default/post_check
DATA="language=${INPUT_LANGUAGE}"
if [ -n "${INPUT_ENABLED_RULES}" ]; then
DATA="$DATA&enabledRules=${INPUT_ENABLED_RULES}"
fi
if [ -n "${INPUT_DISABLED_RULES}" ]; then
DATA="$DATA&disabledRules=${INPUT_DISABLED_RULES}"
fi
if [ -n "${INPUT_ENABLED_CATEGORIES}" ]; then
DATA="$DATA&enabledCategories=${INPUT_ENABLED_CATEGORIES}"
fi
if [ -n "${INPUT_DISABLED_CATEGORIES}" ]; then
DATA="$DATA&disabledCategories=${INPUT_DISABLED_CATEGORIES}"
fi
if [ -n "${INPUT_ENABLED_ONLY}" ]; then
DATA="$DATA&enabledOnly=${INPUT_ENABLED_ONLY}"
fi
# Disable glob to handle glob patterns with ghglob command instead of with shell.
set -o noglob
FILES="$(git ls-files | ghglob ${INPUT_PATTERNS})"
set +o noglob
# To manage whitespaces in filepath
IFS=$(echo -en "\n\b")
run_langtool() {
for FILE in ${FILES}; do
echo "Checking ${FILE}..." >&2
curl --silent \
--request POST \
--data "${DATA}" \
--data-urlencode "text=$(cat "${FILE}")" \
"${API_ENDPOINT}/v2/check" | \
FILE="${FILE}" tmpl /langtool.tmpl
done
}
export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}"
run_langtool \
| reviewdog -efm="%A%f:%l:%c: %m" -efm="%C %m" -name="LanguageTool" -reporter="${INPUT_REPORTER:-github-pr-check}" -level="${INPUT_LEVEL}"