-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
script.sh
executable file
·101 lines (83 loc) · 3.07 KB
/
script.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
# shellcheck disable=SC2086,SC2089,SC2090
cd "${GITHUB_WORKSPACE}" || exit
TEMP_PATH="$(mktemp -d)"
PATH="${TEMP_PATH}:$PATH"
echo '::group::🐶 Installing reviewdog ... https://github.com/reviewdog/reviewdog'
curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b "${TEMP_PATH}" "${REVIEWDOG_VERSION}" 2>&1
echo '::endgroup::'
echo '::group:: Installing textlint ... https://github.com/textlint/textlint'
if [ -x "./node_modules/.bin/textlint" ]; then
echo 'already installed'
elif [[ "${INPUT_PACKAGE_MANAGER}" == "npm" ]]; then
echo 'npm ci start'
npm ci
elif [[ "${INPUT_PACKAGE_MANAGER}" == "yarn" ]]; then
echo 'yarn install start'
yarn install
elif [[ "${INPUT_PACKAGE_MANAGER}" == "pnpm" ]]; then
echo 'pnpm install start'
pnpm install
else
echo 'The specified package manager is not supported.'
echo '::endgroup::'
exit 1
fi
if [ -x "./node_modules/.bin/textlint" ]; then
npx textlint --version
else
echo 'This repository was not configured for textlint, process done.'
exit 1
fi
echo '::endgroup::'
export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}"
echo '::group:: Running textlint with reviewdog 🐶 ...'
textlint_exit_val="0"
reviewdog_exit_val="0"
# ignore preview exit code
reviewdog_exit_val2="0"
# shellcheck disable=SC2086
textlint_check_output=$(npx textlint -f checkstyle ${INPUT_TEXTLINT_FLAGS} 2>&1) \
|| textlint_exit_val="$?"
# shellcheck disable=SC2086
echo "${textlint_check_output}" | reviewdog -f=checkstyle \
-name="${INPUT_TOOL_NAME}" \
-reporter="${INPUT_REPORTER:-github-pr-review}" \
-filter-mode="${INPUT_FILTER_MODE}" \
-fail-on-error="${INPUT_FAIL_ON_ERROR}" \
-level="${INPUT_LEVEL}" \
${INPUT_REVIEWDOG_FLAGS} || reviewdog_exit_val="$?"
echo '::endgroup::'
# github-pr-review only diff adding
if [[ "${INPUT_REPORTER}" == "github-pr-review" ]]; then
echo '::group:: Running textlint fixing report 🐶 ...'
# fix
npx textlint --fix ${INPUT_TEXTLINT_FLAGS:-.} || true
TMPFILE=$(mktemp)
git diff > "${TMPFILE}"
git stash -u
# shellcheck disable=SC2086,SC2034
reviewdog \
-f=diff \
-f.diff.strip=1 \
-name="${INPUT_TOOL_NAME}-fix" \
-reporter="github-pr-review" \
-filter-mode="${INPUT_FILTER_MODE}" \
-fail-on-error="${INPUT_FAIL_ON_ERROR}" \
-level="${INPUT_LEVEL}" \
${INPUT_REVIEWDOG_FLAGS} < "${TMPFILE}" \
|| reviewdog_exit_val2="$?"
git stash drop || true
echo '::endgroup::'
fi
# Throw error if an error occurred and fail_on_error is true
# textlint exitcode: 0 success 1 lint error detect 2 fatal error
# (not 0) AND (not 1) is error
if [[ "${INPUT_FAIL_ON_ERROR}" == "true" \
&& (( "${textlint_exit_val}" != "0" \
&& "${textlint_exit_val}" != "1" ) \
|| "${reviewdog_exit_val}" != "0" ) \
]]; then
exit 1
fi
# EOF