From 04fb5c41e06006ab8c4db4464d2b520f53f1737c Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Tue, 20 May 2025 14:03:10 +0200 Subject: [PATCH] scripts: exclude backward compatible versions from linter --- scripts/check-go-version-dockerfile.sh | 8 +++++++ scripts/check-go-version-yaml.sh | 29 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/scripts/check-go-version-dockerfile.sh b/scripts/check-go-version-dockerfile.sh index 303ee42ed..a09acc29e 100755 --- a/scripts/check-go-version-dockerfile.sh +++ b/scripts/check-go-version-dockerfile.sh @@ -34,6 +34,7 @@ exception_list=( # Exclude the tools Dockerfile as otherwise the linter may need to be # considered every time the Go version is updated. "./tools/Dockerfile" + "./itest/backward-compat" ) # is_exception checks if a file is in the exception list. @@ -43,6 +44,13 @@ is_exception() { if [ "$file" == "$exception" ]; then return 0 fi + + # Check if the file is inside an excluded directory. + # The trailing slash ensures that similarly named directories + # (e.g., ./itest/backward-compat_other) are not mistakenly excluded. + if [[ "$file/" == "$exclude"* ]]; then + return 0 + fi done return 1 } diff --git a/scripts/check-go-version-yaml.sh b/scripts/check-go-version-yaml.sh index bd65ffa01..eae0b86ce 100755 --- a/scripts/check-go-version-yaml.sh +++ b/scripts/check-go-version-yaml.sh @@ -63,11 +63,40 @@ fi target_go_version="$1" +# File paths to be excluded from the check. +exception_list=( + "./itest/backward-compat" +) + +# is_exception checks if a file is in the exception list. +is_exception() { + local file="$1" + for exception in "${exception_list[@]}"; do + if [ "$file" == "$exception" ]; then + return 0 + fi + + # Check if the file is inside an excluded directory. + # The trailing slash ensures that similarly named directories + # (e.g., ./itest/backward-compat_other) are not mistakenly excluded. + if [[ "$file/" == "$exclude"* ]]; then + return 0 + fi + done + return 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 + # Skip the file if it is in the exception list. + if is_exception "$file"; then + echo "Skipping $file" + continue + fi + check_go_version_yaml "$file" "$target_go_version" check_go_version_env_variable "$file" "$target_go_version" done