Skip to content

Commit 1bc72cf

Browse files
authored
Add only-diff mode (#6)
* Add options for onlydiff mode * Add -x flag
1 parent e36b4c9 commit 1bc72cf

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ inputs:
7676
description: |-
7777
Is used to read a compile command database.
7878
default: ""
79+
only-diff:
80+
description: |-
81+
Is used to check only modified and appended files.
82+
default: ""
7983
outputs:
8084
warnings-count:
8185
description: 'Total warnings count'
@@ -148,6 +152,7 @@ runs:
148152
VISIT_IMPLICIT_CODE: ${{ inputs.visit-implicit-code }}
149153
CLAZY_CHECKS_AS_ERRORS: ${{ inputs.warnings_as_errors }}
150154
IGNORE_HEADERS : ${{ inputs.ignore-headers }}
155+
ONLY_DIFF: ${{ inputs.only-diff }}
151156
run: |
152157
PATH=~/.local/clazy/bin:$PATH "$GITHUB_ACTION_PATH/clazy.sh"
153158

clazy.sh

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/bin/bash
2+
set -x
23

34
options=()
45
extra_args=()
56
extra_args_before=()
7+
files=()
68

79
for pair in $EXTRA_ARG; do
810
extra_args+=( "--extra-arg=$pair" )
@@ -35,12 +37,22 @@ fi
3537

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

38-
IFS=',' read -r -a extensions <<< "$EXTENSIONS"
39-
for ext in "${extensions[@]}"; do
40-
while IFS= read -r -d '' file; do
41-
files+=($(realpath "$file"))
42-
done < <(find . -name "*.$ext" -print0)
43-
done
40+
if [[ -n "$ONLY_DIFF" ]]; then
41+
for file in $(git diff --name-only HEAD^1 HEAD); do
42+
file_extension="${file##*.}"
43+
if echo "$EXTENSIONS" | grep -q "$file_extension"; then
44+
files+=("$(realpath "$file")")
45+
fi
46+
done
47+
else
48+
IFS=',' read -r -a extensions <<< "$EXTENSIONS"
49+
for ext in "${extensions[@]}"; do
50+
while IFS= read -r -d '' file; do
51+
files+=($(realpath "$file"))
52+
done < <(find . -name "*.$ext" -print0)
53+
done
54+
55+
fi
4456

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

0 commit comments

Comments
 (0)