Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: exclude non-project files from go version consistency lint check #775

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions tools/check-go-version-dockerfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
26 changes: 21 additions & 5 deletions tools/check-go-version-yaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading