forked from EPMatt/reviewdog-action-prettier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.sh
executable file
·62 lines (54 loc) · 2.03 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
#!/bin/bash
set -e
# Move to the provided workdir
cd "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit 1
# Install prettier
if [ ! -f "$(npm root)"/.bin/prettier ]; then
echo "::group::🔄 Running npm install to install prettier..."
npm install
echo "::endgroup::"
fi
if [ ! -f "$(npm root)"/.bin/prettier ]; then
echo "❌ Unable to locate or install prettier. Did you provide a workdir which contains a valid package.json?"
exit 1
else
echo ℹ️ prettier version: "$("$(npm root)"/.bin/prettier --version)"
fi
echo "::group::📝 Running prettier with reviewdog 🐶 ..."
export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}"
# if reporter is github-pr-review, run prettier in write mode and report code suggestions
if [ "$INPUT_REPORTER" = "github-pr-review" ]; then
# shellcheck disable=SC2086
"$(npm root)"/.bin/prettier --write ${INPUT_PRETTIER_FLAGS} 2>&1 \
| reviewdog \
-efm="%E[%trror] %f: %m (%l:%c)" \
-efm="%C[error]%r" \
-efm="%Z[error]%r" \
-efm="%-G%r" \
-name="${INPUT_TOOL_NAME}" \
-reporter="${INPUT_REPORTER}" \
-filter-mode="${INPUT_FILTER_MODE}" \
-fail-on-error="${INPUT_FAIL_ON_ERROR}" \
-level="${INPUT_LEVEL}" \
"${INPUT_REVIEWDOG_FLAGS}"
# else run prettier in check mode and report warnings and errors
else
# shellcheck disable=SC2086
"$(npm root)"/.bin/prettier --check ${INPUT_PRETTIER_FLAGS} 2>&1 | sed --regexp-extended 's/(\[warn\].*)$/\1 File is not properly formatted./' \
| reviewdog \
-efm="%-G[warn] Code style issues found in the above file(s). Forgot to run Prettier%. File is not properly formatted." \
-efm="[%tarn] %f %m" \
-efm="%E[%trror] %f: %m (%l:%c)" \
-efm="%C[error]%r" \
-efm="%Z[error]%r" \
-efm="%-G%r" \
-name="${INPUT_TOOL_NAME}" \
-reporter="${INPUT_REPORTER}" \
-filter-mode="${INPUT_FILTER_MODE}" \
-fail-on-error="${INPUT_FAIL_ON_ERROR}" \
-level="${INPUT_LEVEL}" \
"${INPUT_REVIEWDOG_FLAGS}"
fi
exit_code=$?
echo "::endgroup::"
exit $exit_code