forked from reviewdog/action-languagetool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·60 lines (51 loc) · 1.9 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
#!/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
FILES="${INPUT_PATTERNS}"
run_langtool() {
for FILE in ${FILES}; do
echo "Checking ${FILE}..." >&2
# Print file content
cat "${FILE}" >&2
curl --silent \
--request POST \
--data "${DATA}" \
--data-urlencode "text=$(cat "${FILE}")" \
--header "Content-Type: application/x-www-form-urlencoded" \
"${API_ENDPOINT}/v2/check" |
# replace .txt in file name with .md
FILE="$(echo $FILE | sed 's/\.txt/\.md/')" tmpl /langtool.tmpl
done
}
export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}"
result=$(run_langtool)
echo "${result}"
echo ${result} | reviewdog -efm="%A%f:%l:%c: %m" -efm="%C %m" -name="LanguageTool" -reporter="${INPUT_REPORTER:-github-pr-check}" -level="${INPUT_LEVEL}"