forked from WongNung/ci-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake8-summarize
More file actions
executable file
·35 lines (27 loc) · 969 Bytes
/
flake8-summarize
File metadata and controls
executable file
·35 lines (27 loc) · 969 Bytes
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
#!/usr/bin/env bash
# Make sure to have Github Actions: setup-python
# Make sure to install latest pip and flake8 package
FLAKE8_ARGS="$@"
FLAKE8_OUT=$(flake8 --tee --format='%(path)s:%(row)d:%(col)d:%(code)s:%(text)s' $FLAKE8_ARGS)
# Markdown properties
SUMMARY=""
TABLE_HEADERS=("Location" "Row" "Col" "Code" "Explanation")
SUMMARY+=$'# Linting Summary\n'
SUMMARY+="|${TABLE_HEADERS[0]}|${TABLE_HEADERS[1]}|${TABLE_HEADERS[2]}|${TABLE_HEADERS[3]}|${TABLE_HEADERS[4]}|"$'\n|:--|:-:|:-:|:--|:--|\n'
# Use double-quotes to preserve newlines.
# echo "$FLAKE8_OUT"
COUNT=0
while IFS= read -r line; do
[ -z "$line" ] && continue
while IFS=':' read -ra entry; do
SUMMARY+="|\`${entry[0]}\`|\`${entry[1]}\`|\`${entry[2]}\`|\`${entry[3]}\`|\`${entry[4]}\`|"$'\n'
COUNT+=1
done <<< "$line"
done <<< "$FLAKE8_OUT"
if [ $COUNT -le 0 ]; then
SUMMARY+=$'\n🎉🎉 Code looks pretty clean! 🎉🎉'
fi
echo "$SUMMARY"
if [ $COUNT -gt 0 ]; then
exit 1
fi