header_check: Check header for changed text files

We are running `header_check` for non-text files like binary files,
symbolic link files, image files (pictures) and etc., which does not
make sense.

Filter out non-text files and run `header_check` only for text files
changed.

Signed-off-by: Ruoqing He <heruoqing@iscas.ac.cn>
This commit is contained in:
Ruoqing He 2025-02-18 18:41:26 +08:00
parent 7e49e83779
commit d23284a0dc

View File

@ -413,10 +413,21 @@ static_check_license_headers()
files=$(get_pr_changed_file_details || true) files=$(get_pr_changed_file_details || true)
# Strip off status # Strip off status and convert to array
files=$(echo "$files"|awk '{print $NF}') files=($(echo "$files"|awk '{print $NF}'))
# no files were changed text_files=()
# Filter out non-text files
for file in "${files[@]}"; do
if [[ -f "$file" ]] && file --mime-type "$file" | grep -q "text/"; then
text_files+=("$file")
else
info "Ignoring non-text file: $file"
fi
done
files="${text_files[*]}"
# no text files were changed
[ -z "$files" ] && info "No files found" && popd && return [ -z "$files" ] && info "No files found" && popd && return
local header_check local header_check