From 1bc72cfa4049f63dfa55b639c993939eb6b6698d Mon Sep 17 00:00:00 2001 From: MinyazevR <89993880+MinyazevR@users.noreply.github.com> Date: Fri, 8 Nov 2024 11:02:12 +0300 Subject: [PATCH] Add only-diff mode (#6) * Add options for onlydiff mode * Add -x flag --- action.yml | 5 +++++ clazy.sh | 24 ++++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/action.yml b/action.yml index 88b6116..51c0ac3 100644 --- a/action.yml +++ b/action.yml @@ -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' @@ -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" diff --git a/clazy.sh b/clazy.sh index d5c4ae2..a0ac789 100755 --- a/clazy.sh +++ b/clazy.sh @@ -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" ) @@ -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" \