-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathentrypoint.sh
148 lines (115 loc) · 4.15 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
140
141
142
143
144
145
146
147
148
#!/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<"
SINGLE="'"
DOUBLE='"'
SPLIT=false
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="$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="$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
TASK_NAME="--name $INPUT_TASK_NAME"
fi
EXITCODE=0
# shellcheck disable=SC2086
if [ -n "$INPUT_OUTPUT_FILE" ] && [ -n "$SOURCES_LIST" ]; then
pyspelling --verbose --config "$SPELLCHECK_CONFIG_FILE" $TASK_NAME $SOURCES_LIST | tee "$INPUT_OUTPUT_FILE"
EXITCODE=${PIPESTATUS[0]}
elif [ -n "$INPUT_OUTPUT_FILE" ]; then
pyspelling --verbose --config "$SPELLCHECK_CONFIG_FILE" $TASK_NAME | tee "$INPUT_OUTPUT_FILE"
EXITCODE=${PIPESTATUS[0]}
elif [ -n "$SOURCES_LIST" ]; then
pyspelling --verbose --config "$SPELLCHECK_CONFIG_FILE" $TASK_NAME $SOURCES_LIST
EXITCODE=$?
elif [ -z "$INPUT_SOURCE_FILES" ]; then
pyspelling --verbose --config "$SPELLCHECK_CONFIG_FILE" $TASK_NAME
EXITCODE=$?
else
echo "No files to check, exiting"
EXITCODE=0
fi
echo "----------------------------------------------------------------"
if [ -n "$GITHUB_ACTIONS" ]; then
test "$EXITCODE" -gt 1 && echo "::error title=Spelling check::Spelling check action failed, please check diagnostics";
test "$EXITCODE" -eq 1 && echo "::error title=Spelling errors::Files in repository contain spelling errors";
else
test "$EXITCODE" -gt 1 && echo "Spelling check action failed, please check diagnostics";
test "$EXITCODE" -eq 1 && echo "Files in repository contain spelling errors";
fi
exit "$EXITCODE"