From 5e54ff9397ebbd422866072bf419269cf805cb5b Mon Sep 17 00:00:00 2001 From: ffranr Date: Tue, 30 Jan 2024 13:09:42 +0000 Subject: [PATCH] tools: exclude non-project files from go version consistency lint check --- tools/check-go-version-dockerfile.sh | 27 ++++++++++++++++++++++----- tools/check-go-version-yaml.sh | 26 +++++++++++++++++++++----- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/tools/check-go-version-dockerfile.sh b/tools/check-go-version-dockerfile.sh index 0853ecbe3..6a310ddea 100755 --- a/tools/check-go-version-dockerfile.sh +++ b/tools/check-go-version-dockerfile.sh @@ -25,12 +25,29 @@ fi target_go_version="$1" -# Search for Dockerfiles in the current directory and its subdirectories -dockerfiles=$(find . -type f -name "*.Dockerfile" -o -name "Dockerfile") - -# Check each Dockerfile -for file in $dockerfiles; do +# We find target files using the 'find' command in conjunction with the 'read' +# command. We exclude some directories from the search. +# +# We use the 'read' command to help ensure that we correctly handle filenames +# with spaces, newlines, and special characters. The '-print0' option in 'find' +# outputs filenames separated by a null character. This allows the 'read' +# command in the while loop to accurately distinguish each filename. The +# 'target_files' array is then populated, preserving the integrity of each +# filename. This approach ensures safe handling of filenames, regardless of +# their complexity. +while IFS= read -r -d '' file; do + target_files+=("$file") +done < <(find . \ + -path ./vendor -prune -o \ + -type f \ + \( -name "*.Dockerfile" -o -name "Dockerfile" \) \ + -print0 \ +) + +# Check for the expected Go version in each file. +for file in "${target_files[@]}"; do check_go_version "$file" "$target_go_version" done + echo "All Dockerfiles pass the Go version check for Go version $target_go_version." diff --git a/tools/check-go-version-yaml.sh b/tools/check-go-version-yaml.sh index 84103b80c..9fac2678f 100755 --- a/tools/check-go-version-yaml.sh +++ b/tools/check-go-version-yaml.sh @@ -36,11 +36,27 @@ fi target_go_version="$1" -# Search for YAML files in the current directory and its subdirectories -yaml_files=$(find . -type f -name "*.yaml" -o -name "*.yml") - -# Check each YAML file -for file in $yaml_files; do +# We find target files using the 'find' command in conjunction with the 'read' +# command. We exclude some directories from the search. +# +# We use the 'read' command to help ensure that we correctly handle filenames +# with spaces, newlines, and special characters. The '-print0' option in 'find' +# outputs filenames separated by a null character. This allows the 'read' +# command in the while loop to accurately distinguish each filename. The +# 'target_files' array is then populated, preserving the integrity of each +# filename. This approach ensures safe handling of filenames, regardless of +# their complexity. +while IFS= read -r -d '' file; do + target_files+=("$file") +done < <(find . \ + -path ./vendor -prune -o \ + -type f \ + \( -name "*.yaml" -o -name "*.yml" \) \ + -print0 \ +) + +# Check for the expected Go version in each file. +for file in "${target_files[@]}"; do check_go_version "$file" "$target_go_version" done