Skip to content

Commit

Permalink
Add only-diff mode (#6)
Browse files Browse the repository at this point in the history
* Add options for onlydiff mode

* Add -x flag
  • Loading branch information
MinyazevR authored Nov 8, 2024
1 parent e36b4c9 commit 1bc72cf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ inputs:
description: |-
Is used to read a compile command database.
default: ""
only-diff:
description: |-
Is used to check only modified and appended files.
default: ""
outputs:
warnings-count:
description: 'Total warnings count'
Expand Down Expand Up @@ -148,6 +152,7 @@ runs:
VISIT_IMPLICIT_CODE: ${{ inputs.visit-implicit-code }}
CLAZY_CHECKS_AS_ERRORS: ${{ inputs.warnings_as_errors }}
IGNORE_HEADERS : ${{ inputs.ignore-headers }}
ONLY_DIFF: ${{ inputs.only-diff }}
run: |
PATH=~/.local/clazy/bin:$PATH "$GITHUB_ACTION_PATH/clazy.sh"
Expand Down
24 changes: 18 additions & 6 deletions clazy.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/bin/bash
set -x

options=()
extra_args=()
extra_args_before=()
files=()

for pair in $EXTRA_ARG; do
extra_args+=( "--extra-arg=$pair" )
Expand Down Expand Up @@ -35,12 +37,22 @@ fi

pattern='^(.*?):([0-9]+):([0-9]+): (.+): (.+) \[(.*)\]$'

IFS=',' read -r -a extensions <<< "$EXTENSIONS"
for ext in "${extensions[@]}"; do
while IFS= read -r -d '' file; do
files+=($(realpath "$file"))
done < <(find . -name "*.$ext" -print0)
done
if [[ -n "$ONLY_DIFF" ]]; then
for file in $(git diff --name-only HEAD^1 HEAD); do
file_extension="${file##*.}"
if echo "$EXTENSIONS" | grep -q "$file_extension"; then
files+=("$(realpath "$file")")
fi
done
else
IFS=',' read -r -a extensions <<< "$EXTENSIONS"
for ext in "${extensions[@]}"; do
while IFS= read -r -d '' file; do
files+=($(realpath "$file"))
done < <(find . -name "*.$ext" -print0)
done

fi

output=$(clazy-standalone --checks="$CHECKS" -p="$DATABASE" \
--header-filter="$HEADER_FILTER" --ignore-dirs="$IGNORE_DIRS" \
Expand Down

0 comments on commit 1bc72cf

Please sign in to comment.