Skip to content

Commit

Permalink
ci: updating static analysis workflow to output modified files vs unm…
Browse files Browse the repository at this point in the history
…odified files
  • Loading branch information
SuperFola committed Jul 3, 2024
1 parent f73cf79 commit 292e294
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
43 changes: 43 additions & 0 deletions .github/generate_cppcheck_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import sys

UPDATED_FILES = sys.argv[1:]
TABLE_HEADER = """| Filename | Line | Type | Description |
| -------- | ---- | ---- | ----------- |"""

with open("cppcheck.txt") as f:
content = f.readlines()

updated = []
anything_else = []

for line in content:
filename, row, kind, desc = line.split(":", 3)
formatted = f"| {filename} | {row} | {kind.strip()} | {desc.strip()} |"

if filename == "nofile":
continue

if filename in UPDATED_FILES:
updated.append(formatted)
else:
anything_else.append(formatted)


def make_output(data):
if data:
output = TABLE_HEADER + "\n"
output += "\n".join(data)
return output
return ""


print(f"""### CppCheck report
{make_output(updated)}
<details>
<summary>Report files about files you didn't modify in this PR</summary>
{make_output(anything_else)}
</details>
""")
12 changes: 6 additions & 6 deletions .github/launch-lizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@


def make_sorted_table_lines(lines_with_ccn):
output = ""
for line in sorted(lines_with_ccn, key=lambda e: e[1], reverse=True):
output += f"| {line[0]} | {line[1]} |\n"
return output
if lines_with_ccn:
output = TABLE_HEADERS + "\n"
for line in sorted(lines_with_ccn, key=lambda e: e[1], reverse=True):
output += f"| {line[0]} | {line[1]} |\n"
return output
return ""


print(f"""### Lizard report
Listing only functions with cyclomatic complexity >= {MAX_CCN} or NLOC >= {MAX_NLOC} or parameters >= {MAX_PARAM}.
{TABLE_HEADERS}
{make_sorted_table_lines(updated)}
<details>
<summary>Report about files you didn't modify in this PR</summary>
{TABLE_HEADERS}
{make_sorted_table_lines(anything_else)}
</details>
""")
7 changes: 2 additions & 5 deletions .github/workflows/static_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ jobs:
-I include src \
--enable=all --inline-suppr \
--suppressions-list=cppcheck-suppressions.txt
cat cppcheck.txt | sort > cppcheck_sorted.txt
content=$(python .github/generate_cppcheck_report.py $(echo $(git diff --name-only -r HEAD^1 HEAD)))
echo "CPPCHECK_REPORT<<EOF" >> $GITHUB_ENV
echo "| Filename | Line | Type | Description |" >> $GITHUB_ENV
echo "| -------- | ---- | ---- | ----------- |" >> $GITHUB_ENV
cat cppcheck_sorted.txt | awk -F ":" '{type=$3;out=""; for (i = 4; i <= NF; i++) {out = out " " $i}; print $1 " | " $2 " |" type " |" out}' >> $GITHUB_ENV
echo "$content" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Find Comment
Expand All @@ -63,6 +61,5 @@ jobs:
---
### CppCheck report
${{ env.CPPCHECK_REPORT }}
edit-mode: replace
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# Personal utilities
warnings.log
cppcheck.txt

# ArkScript
__arkscript__/
Expand Down

0 comments on commit 292e294

Please sign in to comment.