-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
entrypoint.sh
executable file
·96 lines (81 loc) · 2.78 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
#!/usr/bin/env bash
set -euo pipefail
echo "::group::eslint-changed-files"
if [[ -n $INPUT_PATH ]]; then
REPO_DIR="$GITHUB_WORKSPACE/$INPUT_PATH"
echo "Resolving repository path: $REPO_DIR"
if [[ ! -d "$REPO_DIR" ]]; then
echo "::error::Invalid repository path: $REPO_DIR"
echo "::endgroup::"
exit 1
fi
cd "$REPO_DIR"
fi
TEMP_DIR=$(mktemp -d)
RD_JSON_FILE="$TEMP_DIR/rd.json"
ESLINT_FORMATTER="$TEMP_DIR/formatter.cjs"
if [[ "$INPUT_SKIP_ANNOTATIONS" != "true" ]]; then
curl -sf -o "$ESLINT_FORMATTER" https://raw.githubusercontent.com/reviewdog/action-eslint/master/eslint-formatter-rdjson/index.js
# shellcheck disable=SC2034
export REVIEWDOG_GITHUB_API_TOKEN=$INPUT_TOKEN
fi
EXTRA_ARGS="$INPUT_EXTRA_ARGS"
CONFIG_ARG=""
if [[ -n "$INPUT_CONFIG_PATH" ]]; then
CONFIG_ARG="--config=${INPUT_CONFIG_PATH}"
fi
if [[ "$INPUT_ALL_FILES" == "true" ]]; then
echo "Running ESLint on all files..."
if [[ "$INPUT_SKIP_ANNOTATIONS" == "true" ]]; then
echo "Skipping annotations..."
# shellcheck disable=SC2086
npx eslint ${CONFIG_ARG} ${EXTRA_ARGS} && exit_status=$? || exit_status=$?
else
# shellcheck disable=SC2086
npx eslint ${CONFIG_ARG} ${EXTRA_ARGS} -f="${ESLINT_FORMATTER}" . > "$RD_JSON_FILE" && exit_status=$? || exit_status=$?
fi
if [[ "$INPUT_SKIP_ANNOTATIONS" != "true" ]]; then
reviewdog -f=rdjson \
-name=eslint \
-reporter="${INPUT_REPORTER}" \
-filter-mode="nofilter" \
-fail-on-error="${INPUT_FAIL_ON_ERROR}" \
-level="${INPUT_LEVEL}" < "$RD_JSON_FILE" || true
fi
if [[ $exit_status -ne 0 ]]; then
echo "::error::Error running eslint."
rm -rf "$TEMP_DIR"
echo "::endgroup::"
exit 1;
fi
else
if [[ -n "${INPUT_CHANGED_FILES[*]}" ]]; then
echo "Running ESLint on changed files..."
if [[ "$INPUT_SKIP_ANNOTATIONS" == "true" ]]; then
echo "Skipping annotations..."
# shellcheck disable=SC2086
npx eslint ${CONFIG_ARG} ${EXTRA_ARGS} ${INPUT_CHANGED_FILES} && exit_status=$? || exit_status=$?
else
# shellcheck disable=SC2086
npx eslint ${CONFIG_ARG} ${EXTRA_ARGS} -f="${ESLINT_FORMATTER}" ${INPUT_CHANGED_FILES} > "$RD_JSON_FILE" && exit_status=$? || exit_status=$?
fi
if [[ "$INPUT_SKIP_ANNOTATIONS" != "true" ]]; then
reviewdog -f=rdjson \
-name=eslint \
-reporter="${INPUT_REPORTER}" \
-filter-mode="nofilter" \
-fail-on-error="${INPUT_FAIL_ON_ERROR}" \
-level="${INPUT_LEVEL}" < "$RD_JSON_FILE" || true
fi
if [[ $exit_status -ne 0 ]]; then
echo "::error::Error running eslint."
rm -rf "$TEMP_DIR"
echo "::endgroup::"
exit 1;
fi
else
echo "Skipping: No files to lint"
fi
fi
rm -rf "$TEMP_DIR"
echo "::endgroup::"