-
Notifications
You must be signed in to change notification settings - Fork 29
/
entrypoint.sh
executable file
·65 lines (53 loc) · 2 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
62
63
64
65
#!/bin/sh
export RELATIVE=
export ANDROID=
export BASELINE=
export CUSTOM_RULE_PATH=
if [ "$INPUT_KTLINT_VERSION" = "latest" ]; then
curl -sSLO https://github.com/pinterest/ktlint/releases/latest/download/ktlint &&
chmod a+x ktlint &&
mv ktlint /usr/local/bin/
else
curl -sSLO https://github.com/pinterest/ktlint/releases/download/"${INPUT_KTLINT_VERSION}"/ktlint &&
chmod a+x ktlint &&
mv ktlint /usr/local/bin/
fi
if [ "$INPUT_RELATIVE" = true ]; then
export RELATIVE=--relative
fi
if [ ! -z "$INPUT_BASELINE" ]; then
export BASELINE="--baseline=${INPUT_BASELINE}"
fi
if [ "$INPUT_CUSTOM_RULE_PATH" ]; then
export CUSTOM_RULE_PATH="--ruleset=${INPUT_CUSTOM_RULE_PATH}"
fi
cd "$GITHUB_WORKSPACE"
git config --global --add safe.directory $GITHUB_WORKSPACE
export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}"
ktlint_version=$(ktlint --version)
# In newer ktlint versions, the command `ktlint --version` returns "ktlint version x.y.z" and we need to remove "ktlint version " from the string
ktlint_version=${ktlint_version#"ktlint version "}
echo "ktlint version: $ktlint_version"
# ktlint_version > 0.49.1
if [ "$(printf '%s\n' "0.49.1" "$ktlint_version" | sort -V | head -n1)" = "0.49.1" ]; then
# --code-style is deprecated since 1.0.1 and .editorconfig needs to be used: https://pinterest.github.io/ktlint/latest/rules/code-styles/
# ktlint_version <= 1.0.0
if [ "$(printf '%s\n' "1.0.0" "$ktlint_version" | sort -V | tail -n1)" = "1.0.0" ]; then
if [ "$INPUT_ANDROID" = true ]; then
export ANDROID="--code-style=android_studio"
else
export ANDROID="--code-style=intellij_idea"
fi
fi
else
if [ "$INPUT_ANDROID" = true ]; then
export ANDROID=--android
fi
fi
ktlint --reporter=checkstyle $CUSTOM_RULE_PATH $RELATIVE $ANDROID $BASELINE $INPUT_FILE_GLOB |
reviewdog -f=checkstyle \
-name="${INPUT_NAME}" \
-reporter="${INPUT_REPORTER}" \
-level="${INPUT_LEVEL}" \
-filter-mode="${INPUT_FILTER_MODE}" \
-fail-on-error="${INPUT_FAIL_ON_ERROR}"