Skip to content

Commit

Permalink
Merge pull request #24 from JacobDomagala/23-exclude-dir-not-working-…
Browse files Browse the repository at this point in the history
…clang-tidy

[#23]: Fix excluding directories for clang-tidy
  • Loading branch information
JacobDomagala authored Aug 1, 2021
2 parents f793040 + 8a75d08 commit dda9bb3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 5 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
set -x

if [ "$INPUT_PR_NUM" == "null" ]; then
echo "Pull request number input is not present! This action can only run on Pull Requests!"
exit 0
echo "Pull request number input is not present! This action can only run on Pull Requests!"
exit 0
fi

if [ -n "$INPUT_APT_PCKGS" ]; then
Expand All @@ -24,10 +24,11 @@ files_to_check=$(python3 /get_files_to_check.py -exclude="$INPUT_EXCLUDE_DIR" -j

if [ -z "$INPUT_EXCLUDE_DIR" ]; then
eval cppcheck --project=compile_commands.json "$INPUT_CPPCHECK_ARGS" --output-file=cppcheck.txt
eval clang-tidy-12 "$INPUT_CLANG_TIDY_ARGS" -p "$(pwd)" "$files_to_check" -- > "clang_tidy.txt"
else
eval cppcheck --project=compile_commands.json "$INPUT_CPPCHECK_ARGS" --output-file=cppcheck.txt -i"$GITHUB_WORKSPACE/$INPUT_EXCLUDE_DIR"
eval clang-tidy-12 "$INPUT_CLANG_TIDY_ARGS" -p "$(pwd)" "$files_to_check" -- > "clang_tidy.txt"
fi

# Excludes for clang-tidy are handled in python script
eval clang-tidy-12 "$INPUT_CLANG_TIDY_ARGS" -p "$(pwd)" "$files_to_check" -- >"clang_tidy.txt"

python3 /run_static_analysis.py -cc cppcheck.txt -ct clang_tidy.txt
8 changes: 7 additions & 1 deletion run_static_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ def check_for_char_limit(incoming_line):
return (CURRENT_COMMENT_LENGTH + len(incoming_line)) <= COMMENT_MAX_SIZE


def is_excluded_dir(line):
# In future this could be multiple different directories
excluded_dir = f"{WORK_DIR}/{os.getenv('INPUT_EXCLUDE_DIR')}"
return line.startswith(excluded_dir)


def get_file_line_end(file, file_line_start):
num_lines = sum(1 for line in open(WORK_DIR + file))
return min(file_line_start + 5, num_lines)
Expand All @@ -109,7 +115,7 @@ def create_comment_for_output(tool_output, prefix, files_changed_in_pr):
global CURRENT_COMMENT_LENGTH
output_string = ""
for line in tool_output:
if line.startswith(prefix):
if line.startswith(prefix) and not is_excluded_dir(line):
line = line.replace(prefix, "")
file_path_end_idx = line.index(":")
file_path = line[:file_path_end_idx]
Expand Down

0 comments on commit dda9bb3

Please sign in to comment.