-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.sh
executable file
·69 lines (63 loc) · 2.08 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
#!/bin/sh -e
setup_git() {
if [ -n "${GITHUB_WORKSPACE}" ]; then
git config --global --add safe.directory "${GITHUB_WORKSPACE}" || exit 1
git config --global --add safe.directory "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit 1
cd "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit 1
fi
}
setup_reviewdog() {
export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}"
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::'
}
setup_erblint() {
echo '::group:: Installing erb-lint with extensions ... https://github.com/Shopify/erb-lint'
# if 'gemfile' erb-lint version selected
if [ "$INPUT_ERBLINT_VERSION" = "gemfile" ]; then
# if Gemfile.lock is here
if [ -f 'Gemfile.lock' ]; then
# grep for erb-lint version
ERBLINT_GEMFILE_VERSION=$(ruby -ne 'print $& if /^\s{4}erb_lint\s\(\K.*(?=\))/' Gemfile.lock)
# if erb-lint version found, then pass it to the gem install
# left it empty otherwise, so no version will be passed
if [ -n "$ERBLINT_GEMFILE_VERSION" ]; then
ERBLINT_VERSION=$ERBLINT_GEMFILE_VERSION
else
printf "Cannot get the erb-lint's version from Gemfile.lock. The latest version will be installed."
fi
else
printf 'Gemfile.lock not found. The latest version will be installed.'
fi
else
# set desired erb-lint version
ERBLINT_VERSION=$INPUT_ERBLINT_VERSION
fi
gem install -N erb_lint --version "${ERBLINT_VERSION}"
echo '::endgroup::'
}
setup_bundler() {
if [ "${INPUT_USE_BUNDLER}" = "false" ]; then
BUNDLE_EXEC=""
else
BUNDLE_EXEC="bundle exec "
fi
}
run_linter() {
echo '::group:: Running erb-lint with reviewdog 🐶 ...'
${BUNDLE_EXEC}erblint --lint-all --format compact |
reviewdog \
-efm="%f:%l:%c: %m" \
-reporter="${INPUT_REPORTER}" \
-filter-mode="${INPUT_FILTER_MODE}" \
-level="${INPUT_LEVEL}"
echo '::endgroup::'
}
setup_git
setup_reviewdog
setup_erblint
setup_bundler
run_linter