Skip to content

Commit 6e37d8d

Browse files
authored
Add new options and simplify the script (#7)
* Add ignore-external-files option * Fix typo * Use correct bash syntax * Simplify script and add ignore-header-deps option * Disable additional logging * Use correct way to check what file already checked
1 parent eb0ea31 commit 6e37d8d

2 files changed

Lines changed: 37 additions & 71 deletions

File tree

action.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ inputs:
3939
In this case, the version field is ignored.
4040
required: false
4141
default: false
42-
ignore-headers:
42+
ignore-external-files:
4343
description: |
4444
Ignore thirdparty headers.
4545
required: false
@@ -61,6 +61,10 @@ inputs:
6161
Won't emit warnings for non-Qt files, or in other words, if -DQT_CORE_LIB is missing.
6262
required: false
6363
default: false
64+
ignore-header-deps:
65+
description: |
66+
required: false
67+
default: false
6468
qt4-compat:
6569
description: |
6670
Turns off checks not compatible with Qt 4
@@ -84,6 +88,10 @@ inputs:
8488
description: |-
8589
Is used to check only modified and appended files.
8690
default: ""
91+
root-dir:
92+
description: |-
93+
If the ignore-external-files option is set, the final output on GH will show files that are located below this directory
94+
default: ""
8795
outputs:
8896
warnings-count:
8997
description: 'Total warnings count'
@@ -155,8 +163,10 @@ runs:
155163
SUPPORTED_CHECKS_JSON: ${{ inputs.supported-checks-json }}
156164
VISIT_IMPLICIT_CODE: ${{ inputs.visit-implicit-code }}
157165
CLAZY_CHECKS_AS_ERRORS: ${{ inputs.warnings_as_errors }}
158-
IGNORE_HEADERS : ${{ inputs.ignore-headers }}
166+
IGNORE_EXTERNAL_FILES : ${{ inputs.ignore-external-files }}
159167
ONLY_DIFF: ${{ inputs.only-diff }}
168+
ROOT_DIR: ${{ inputs.root-dir }}
169+
IGNORE_HEADER_DEPS: ${{ inputs.ignore-header-deps }}
160170
run: |
161171
PATH=~/.local/clazy/bin:$PATH "$GITHUB_ACTION_PATH/clazy.sh"
162172

clazy.sh

Lines changed: 25 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ if [ "$VISIT_IMPLICIT_CODE" == "true" ]; then
3030
options+=( "--visit-implicit-code" )
3131
fi
3232

33-
if [ "$IGNORE_HEADERS" == "true" ] && [ -n "$DATABASE" ]; then
34-
cp $DATABASE/compile_commands.json $DATABASE/compile_commands_backup.json
35-
sed -i 's/-I\([^ ]*\)/-isystem\1/g' $DATABASE/compile_commands.json
36-
fi
37-
3833
pattern='^(.*?):([0-9]+):([0-9]+): (.+): (.+) \[(.*)\]$'
3934

4035
if [[ -n "$ONLY_DIFF" ]]; then
@@ -68,93 +63,54 @@ echo 0 > "$warnings_file"
6863
echo 0 > "$errors_file"
6964

7065
declare -A warnings_seen
71-
66+
root_path=$(realpath -s "$ROOT_DIR")
67+
7268
echo "$output" | grep -E "$pattern" | while IFS= read -r line; do
7369
if [[ $line =~ $pattern ]]; then
74-
relative_path="${BASH_REMATCH[1]}"
70+
absolute_path="${BASH_REMATCH[1]}"
7571
line_number="${BASH_REMATCH[2]}"
7672
column_number="${BASH_REMATCH[3]}"
7773
warning_type="${BASH_REMATCH[4]}"
7874
warning_message="${BASH_REMATCH[5]}"
7975
warning_code="${BASH_REMATCH[6]}"
8076

81-
counter=0
82-
if [[ "$relative_path" == /* ]]; then
83-
absolute_path=$relative_path
84-
else
85-
for full_path in "${files[@]}"; do
86-
if [[ "$(basename "$full_path")" == "$relative_path" ]]; then
87-
absolute_path="$full_path"
88-
((counter++))
89-
fi
90-
done
91-
fi
92-
93-
# This is incredibly bad, but I don't know how to properly handle the clazy output yet
94-
if [ "$counter" -ne 1 ]; then
95-
continue
96-
fi
97-
9877
warning_key="${absolute_path}:${line_number}:${column_number}:${warning_code}"
78+
hash=$(echo -n "$warning_key" | md5sum | cut -d' ' -f1)
9979

100-
if [[ -n "${warnings_seen[$warning_key]}" ]]; then
80+
if [[ -n "${warnings_seen[$hash]:-}" ]]; then
10181
continue
10282
fi
10383

10484
warnings_seen["$warning_key"]=1
10585

106-
if [ "$IGNORE_HEADERS" != "true" ]; then
107-
if [[ "$warning_type" == "warning" ]]; then
108-
echo "warning file=$absolute_path,line=$line_number,col=$column_number,$warning_message [$warning_code]"
109-
current_warnings=$(<"$warnings_file")
110-
((current_warnings++))
111-
echo "$current_warnings" > "$warnings_file"
112-
fi
113-
114-
if [[ "$warning_type" == "error" ]]; then
115-
echo "error file=$absolute_path,line=$line_number,col=$column_number,$warning_message [$warning_code]"
116-
current_errors=$(<"$errors_file")
117-
((current_errors++))
118-
echo "$current_errors" > "$errors_file"
119-
fi
120-
121-
elif [[ "${files[@]}" =~ "$absolute_path" ]]; then
122-
123-
if [[ "$warning_type" == "warning" ]]; then
124-
echo "warning file=$absolute_path,line=$line_number,col=$column_number,$warning_message [$warning_code]"
125-
current_warnings=$(<"$warnings_file")
126-
((current_warnings++))
127-
echo "$current_warnings" > "$warnings_file"
128-
fi
129-
130-
if [[ "$warning_type" == "error" ]]; then
131-
echo "error file=$absolute_path,line=$line_number,col=$column_number,$warning_message [$warning_code]"
132-
current_errors=$(<"$errors_file")
133-
((current_errors++))
134-
echo "$current_errors" > "$errors_file"
135-
fi
136-
fi
137-
138-
if [[ "${files[@]}" =~ "$absolute_path" ]]; then
139-
if [[ "$warning_type" == "warning" ]]; then
140-
echo "::warning file=$absolute_path,line=$line_number,col=$column_number::$warning_message [$warning_code]"
141-
fi
86+
if [[ "$IGNORE_EXTERNAL_FILES" == "true" && "$absolute_path" != "$root_path"* ]]; then
87+
continue
88+
fi
14289

143-
if [[ "$warning_type" == "error" ]]; then
144-
echo "::error file=$absolute_path,line=$line_number,col=$column_number::$warning_message [$warning_code]"
145-
fi
90+
if [[ "$IGNORE_HEADER_DEPS" == "true" ]] && [[ ! "${files[@]}" =~ "$absolute_path" ]]; then
91+
continue
92+
fi
93+
94+
if [[ "$warning_type" == "warning" ]]; then
95+
echo "::warning file=$absolute_path,line=$line_number,col=$column_number::$warning_message [$warning_code]"
96+
current_warnings=$(<"$warnings_file")
97+
((current_warnings++))
98+
echo "$current_warnings" > "$warnings_file"
14699
fi
100+
101+
if [[ "$warning_type" == "error" ]]; then
102+
echo "::error file=$absolute_path,line=$line_number,col=$column_number::$warning_message [$warning_code]"
103+
current_errors=$(<"$errors_file")
104+
((current_errors++))
105+
echo "$current_errors" > "$errors_file"
106+
fi
147107
fi
148108
done
149109

150110
warnings_count=$(<"$warnings_file")
151111
errors_count=$(<"$errors_file")
152112

153113
echo "::set-output name=errors-count::$errors_count"
154-
echo "::set-output name=warnings-count::$warnings_count"
155-
156-
if [ "$IGNORE_HEADERS" == "true" ] && [ -n "$DATABASE" ]; then
157-
mv $DATABASE/compile_commands_backup.json $DATABASE/compile_commands.json
158-
fi
114+
echo "::set-output name=warnings-count::$warnings_count"
159115

160116
rm -f "$warnings_file" "$errors_file"

0 commit comments

Comments
 (0)