-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathentrypoint.sh
More file actions
185 lines (150 loc) · 5.88 KB
/
entrypoint.sh
File metadata and controls
185 lines (150 loc) · 5.88 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/bash
SPELLCHECK_CONFIG_FILE=''
if [ -n "$INPUT_CONFIG_PATH" ]; then
SPELLCHECK_CONFIG_FILE=$INPUT_CONFIG_PATH
else
if [ -f "./.spellcheck.yml" ]; then
SPELLCHECK_CONFIG_FILE=".spellcheck.yml"
elif [ -f "./.spellcheck.yaml" ]; then
SPELLCHECK_CONFIG_FILE=".spellcheck.yaml"
elif [ -f "./spellcheck.yml" ]; then
SPELLCHECK_CONFIG_FILE="spellcheck.yml"
elif [ -f "./spellcheck.yaml" ]; then
SPELLCHECK_CONFIG_FILE="spellcheck.yaml"
elif [ -f "./.pyspelling.yaml" ]; then
SPELLCHECK_CONFIG_FILE=".pyspelling.yaml"
elif [ -f "./.pyspelling.yml" ]; then
SPELLCHECK_CONFIG_FILE=".pyspelling.yml"
else
SPELLCHECK_CONFIG_FILE="spellcheck.yaml"
fi
fi
echo ""
echo "Using pyspelling on configuration outlined in >$SPELLCHECK_CONFIG_FILE<"
pyspelling --version
aspell --version
hunspell --version
echo "----------------------------------------------------------------"
SINGLE="'"
DOUBLE='"'
SPLIT=false
SOURCES_LIST=()
if [ -n "$INPUT_SOURCE_FILES" ]; then
echo "Source files to check: >$INPUT_SOURCE_FILES<"
if grep -q $SINGLE <<< "$INPUT_SOURCE_FILES"; then
OIFS=$IFS
IFS=$SINGLE
SPLIT=true
echo "Detected separator: >$SINGLE< (single quote)"
fi
if grep -q $DOUBLE <<< "$INPUT_SOURCE_FILES"; then
OIFS=$IFS
IFS=$DOUBLE
SPLIT=true
echo "Detected separator: >$DOUBLE< (double quote)"
fi
if [ -z "$INPUT_TASK_NAME" ]; then
echo "task_name must be specified to use source_files option"
exit 1
else
echo "Running task >$INPUT_TASK_NAME<"
fi
if [ "$SPLIT" = true ]; then
echo "IFS = >$IFS<"
read -r -a arr <<< "$INPUT_SOURCE_FILES"
for FILE in "${arr[@]}"; do
echo "$FILE" | python3 /pwc.py "$SPELLCHECK_CONFIG_FILE"
PATTERN_MATCH_EXITCODE=$?
if [ $PATTERN_MATCH_EXITCODE -eq 1 ]; then
echo "Skipping file >$FILE<"
continue
fi
# Skip null items
if [ -z "$FILE" ]; then
continue
fi
if [ "$FILE" = ' ' ]; then
continue
fi
SOURCES_LIST+=("--source" "$FILE")
echo "Checking quoted file >$FILE<"
done
IFS=$OIFS
unset OIFS
else
read -r -a arr <<< "$INPUT_SOURCE_FILES"
for FILE in "${arr[@]}"; do
echo "$FILE" | python3 /pwc.py "$SPELLCHECK_CONFIG_FILE"
PATTERN_MATCH_EXITCODE=$?
if [ $PATTERN_MATCH_EXITCODE -eq 1 ]; then
echo "Skipping file >$FILE<"
continue
fi
SOURCES_LIST+=("--source" "$FILE")
echo "Checking file >$FILE<"
done
fi
echo "Checking files specification in sources_list as: >${SOURCES_LIST[*]}<"
else
echo "Checking files matching specification outlined in: >$SPELLCHECK_CONFIG_FILE<"
fi
if [ -n "$INPUT_TASK_NAME" ]; then
echo "INPUT_TASK_NAME set to: >$INPUT_TASK_NAME<, using this as task name for pyspelling via --name parameter"
TASK_NAME="$INPUT_TASK_NAME"
fi
SPELL_CHECKER='aspell'
if [ -n "$INPUT_SPELL_CHECKER" ]; then
if [ "${INPUT_SPELL_CHECKER,,}" = "hunspell" ]; then # lowercased INPUT_SPELL_CHECKER for caseinsensitive compare
echo "Using hunspell as spell checker via action configuration"
SPELL_CHECKER="hunspell"
elif [ "${INPUT_SPELL_CHECKER,,}" = "aspell" ]; then # lowercased INPUT_SPELL_CHECKER for caseinsensitive compare
echo "Using aspell as spell checker via action configuration"
else
echo "Using aspell as spell checker by default"
fi
fi
SKIP_DICT_COMPILE='true'
if [ -n "$INPUT_SKIP_DICT_COMPILE" ]; then
if [ "${INPUT_SKIP_DICT_COMPILE,,}" = "true" ]; then # lowercased INPUT_SKIP_DICT_COMPILE for caseinsensitive compare
echo "Skipping dictionary compilation via action configuration"
SKIP_DICT_COMPILE="true"
elif [ "${INPUT_SKIP_DICT_COMPILE,,}" = "false" ]; then # lowercased INPUT_SKIP_DICT_COMPILE for caseinsensitive compare
echo "Not skipping dictionary compilation via action configuration"
else
echo "Invalid value for skip_dict_compile, using default: false"
fi
fi
COMMAND=("pyspelling" "--verbose")
if [ "$SKIP_DICT_COMPILE" = "false" ]; then
COMMAND+=("--skip-dict-compile")
fi
if [ -n "$TASK_NAME" ]; then
COMMAND+=("--name" "$TASK_NAME")
fi
EXITCODE=0
# Command line template
# pyspelling --verbose --config "$SPELLCHECK_CONFIG_FILE" --spellchecker "$SPELL_CHECKER" --name "$TASK_NAME" --source "FILE 1" --source "FILE 2" --source "FILE N"
# source and name are included in the parameters used
if [ -n "$INPUT_OUTPUT_FILE" ] && [ "${#SOURCES_LIST[@]}" -gt 0 ]; then
"${COMMAND[@]}" --config "$SPELLCHECK_CONFIG_FILE" --spellchecker "$SPELL_CHECKER" "${SOURCES_LIST[@]}" | tee "$INPUT_OUTPUT_FILE"
EXITCODE=${PIPESTATUS[0]}
elif [ -n "$INPUT_OUTPUT_FILE" ]; then
"${COMMAND[@]}" --config "$SPELLCHECK_CONFIG_FILE" --spellchecker "$SPELL_CHECKER" | tee "$INPUT_OUTPUT_FILE"
EXITCODE=${PIPESTATUS[0]}
elif [ "${#SOURCES_LIST[@]}" -gt 0 ]; then
"${COMMAND[@]}" --config "$SPELLCHECK_CONFIG_FILE" --spellchecker "$SPELL_CHECKER" "${SOURCES_LIST[@]}"
EXITCODE=$?
elif [ -z "$INPUT_SOURCE_FILES" ]; then
"${COMMAND[@]}" --config "$SPELLCHECK_CONFIG_FILE" --spellchecker "$SPELL_CHECKER"
EXITCODE=$?
else
echo "No files to check, exiting"
EXITCODE=0
fi
echo "----------------------------------------------------------------"
if [ -n "$GITHUB_ACTIONS" ]; then
test "$EXITCODE" -gt 0 && echo "::error title=Error::Files in repository contain spelling errors or or spelling check action failed, please check diagnostics";
else
test "$EXITCODE" -gt 0 && echo "Files in repository contain spelling errors or spelling check action failed, please check diagnostics";
fi
exit "$EXITCODE"