generated from reviewdog/action-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint.sh
executable file
·139 lines (114 loc) · 3.46 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/sh
set -eou
# Build in
GITHUB_WORKSPACE="${GITHUB_WORKSPACE:-}"
# Inputs
## Required (defaults set by `action.yml`)
INPUT_GITHUB_TOKEN="${INPUT_GITHUB_TOKEN:?No github token provided}"
INPUT_WORKDIR="${INPUT_WORKDIR:?No reviewdog relative working directory provided}"
INPUT_LEVEL="${INPUT_LEVEL:?No reviewdog level provided}"
INPUT_FILTER_MODE="${INPUT_FILTER_MODE:?No reviewdog filter mode provided}"
INPUT_REPORTER="${INPUT_REPORTER:?No reviewdog reporter provided}"
INPUT_FAIL_ON_ERROR="${INPUT_FAIL_ON_ERROR:?No reviewdog fail on error provided}"
## Optional
INPUT_REVIEWDOG_FLAGS="${INPUT_REVIEWDOG_FLAGS:-}"
INPUT_FILES="${INPUT_FILES:-}"
# TODO: Check if expansion is applied
# INPUT_EXCLUDE="${INPUT_EXCLUDE:-}"
INPUT_CONFIG="${INPUT_CONFIG:-}"
INPUT_ISOLATED="${INPUT_ISOLATED:-}"
INPUT_WRITE_CHANGES="${INPUT_WRITE_CHANGES:-}"
INPUT_LOCALE="${INPUT_LOCALE:-}"
INPUT_DEBUG="${INPUT_DEBUG:-}"
# Logic
if [ -n "${GITHUB_WORKSPACE}" ] ; then
cd "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit
git config --global --add safe.directory "${GITHUB_WORKSPACE}" || exit 1
fi
# Enable debug mode if the action was run with `Enable debug logging` mode
if [ "${RUNNER_DEBUG:-}" = "1" ]; then
echo 'Action run with enable debug logging: Forcing debug mode'
INPUT_DEBUG="true"
fi
if [ "${INPUT_DEBUG}" = "true" ]; then
set -x
fi
export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}"
echo '::group:: Setting up typos args ...'
ARGS="--force-exclude"
# Use a custom configuration file
if [ -n "${INPUT_CONFIG}" ]; then
ARGS="${ARGS} --config ${INPUT_CONFIG}"
fi
while read -r exclude_glob; do
if [ -n "${exclude_glob}" ]; then
set -- --exclude="${exclude_glob}"
ARGS="${ARGS} ${*}"
fi
done <<EOF
${INPUT_EXCLUDE:-}
EOF
# Ignore implicit configuration files
if [ "${INPUT_ISOLATED}" = "true" ]; then
ARGS="${ARGS} --isolated"
fi
if [ "${INPUT_WRITE_CHANGES}" = "true" ]; then
ARGS="${ARGS} --write-changes"
fi
if [ -n "${INPUT_LOCALE}" ]; then
ARGS="${ARGS} --locale ${INPUT_LOCALE}"
fi
if [ "${INPUT_DEBUG}" = "true" ]; then
# Verbosity 4 seems to be the sweet spot?
ARGS="${ARGS} -vvvv"
fi
while read -r file; do
if [ -n "${file}" ]; then
ARGS="${ARGS} ${file}"
fi
done <<EOF
${INPUT_FILES}
EOF
echo '::endgroup::'
if [ "${INPUT_DEBUG}" = "true" ]; then
echo '::group:: Debugging typos (config) ...'
# shellcheck disable=SC2086
typos ${ARGS} --dump-config -
echo '::endgroup::'
echo '::group:: Debugging typos (files) ...'
# shellcheck disable=SC2086
typos ${ARGS} --files
echo '::endgroup::'
fi
if [ "${INPUT_REPORTER}" = "github-pr-review" ]; then
echo '::group:: Running typos (suggestion) ...'
# -reporter must be github-pr-review for the suggestion feature.
# shellcheck disable=SC2086
typos ${ARGS} --diff \
| reviewdog \
-name="typos (suggestion)" \
-f=diff \
-f.diff.strip=1 \
-reporter="github-pr-review" \
-filter-mode="${INPUT_FILTER_MODE}" \
-fail-on-error="${INPUT_FAIL_ON_ERROR}" \
${INPUT_REVIEWDOG_FLAGS}
EXIT_CODE="${?}"
echo '::endgroup::'
else
echo '::group:: Running typos ...'
# shellcheck disable=SC2086
typos ${ARGS} --format brief \
| reviewdog -efm="%f:%l:%c: %m" \
-name="typos" \
-reporter="${INPUT_REPORTER}" \
-filter-mode="${INPUT_FILTER_MODE}" \
-fail-on-error="${INPUT_FAIL_ON_ERROR}" \
-level="${INPUT_LEVEL}" \
${INPUT_REVIEWDOG_FLAGS}
EXIT_CODE="${?}"
echo '::endgroup::'
fi
if [ "${EXIT_CODE}" -ne 0 ]; then
exit $((EXIT_CODE))
fi