From f194de306071cbe99bf1f3e0877851dadd00a5e5 Mon Sep 17 00:00:00 2001 From: Christopher Phillips Date: Mon, 18 Dec 2023 16:44:12 -0500 Subject: [PATCH] chore: add lint check for large files Signed-off-by: Christopher Phillips --- .github/scripts/check_binary_fixture_size.sh | 35 ++++++++++++++++++++ Taskfile.yaml | 6 ++++ 2 files changed, 41 insertions(+) create mode 100755 .github/scripts/check_binary_fixture_size.sh diff --git a/.github/scripts/check_binary_fixture_size.sh b/.github/scripts/check_binary_fixture_size.sh new file mode 100755 index 000000000..a530d7c05 --- /dev/null +++ b/.github/scripts/check_binary_fixture_size.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Check if a directory is provided as an argument +if [ $# -eq 0 ]; then + echo "Usage: $0 " + exit 1 +fi + +directory="$1" + +# Check if the directory exists +if [ ! -d "$directory" ]; then + echo "Directory not found: $directory" + exit 1 +fi + +# Use find to locate all files in the directory and its subdirectories +found_large_files=0 +while IFS= read -r -d '' file; do + # Check if the file size is greater than 100 bytes + if [ $(wc -c < "$file") -gt 100 ]; then + echo "File $file is greater than 100 bytes." + found_large_files=1 + fi +done < <(find "$directory" -type f -print0) + +# Check if any large files were found +if [ "$found_large_files" -eq 1 ]; then + echo "Script failed: Some files are greater than 100 bytes." + exit 1 +else + echo "All files in $directory and its subdirectories are 100 bytes or smaller. Script passed." + exit 0 +fi + diff --git a/Taskfile.yaml b/Taskfile.yaml index 1df8b4238..a7bbfc664 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -54,6 +54,7 @@ tasks: - task: check-licenses - task: lint - task: check-json-schema-drift + - task: check-binary-fixture-size test: desc: Run all levels of test @@ -169,6 +170,11 @@ tasks: cmds: - .github/scripts/json-schema-drift-check.sh + check-binary-fixture-size: + desc: Ensure that the binary test fixtures are not too large + cmds: + - .github/scripts/check_binary_fixture_size.sh syft/pkg/cataloger/binary/test-fixtures/classifiers/positive + ## Testing tasks #################################