Skip to content

Commit 5e54ff9

Browse files
committed
tools: exclude non-project files from go version consistency lint check
1 parent cd916e7 commit 5e54ff9

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

tools/check-go-version-dockerfile.sh

+22-5
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,29 @@ fi
2525

2626
target_go_version="$1"
2727

28-
# Search for Dockerfiles in the current directory and its subdirectories
29-
dockerfiles=$(find . -type f -name "*.Dockerfile" -o -name "Dockerfile")
30-
31-
# Check each Dockerfile
32-
for file in $dockerfiles; do
28+
# We find target files using the 'find' command in conjunction with the 'read'
29+
# command. We exclude some directories from the search.
30+
#
31+
# We use the 'read' command to help ensure that we correctly handle filenames
32+
# with spaces, newlines, and special characters. The '-print0' option in 'find'
33+
# outputs filenames separated by a null character. This allows the 'read'
34+
# command in the while loop to accurately distinguish each filename. The
35+
# 'target_files' array is then populated, preserving the integrity of each
36+
# filename. This approach ensures safe handling of filenames, regardless of
37+
# their complexity.
38+
while IFS= read -r -d '' file; do
39+
target_files+=("$file")
40+
done < <(find . \
41+
-path ./vendor -prune -o \
42+
-type f \
43+
\( -name "*.Dockerfile" -o -name "Dockerfile" \) \
44+
-print0 \
45+
)
46+
47+
# Check for the expected Go version in each file.
48+
for file in "${target_files[@]}"; do
3349
check_go_version "$file" "$target_go_version"
3450
done
3551

52+
3653
echo "All Dockerfiles pass the Go version check for Go version $target_go_version."

tools/check-go-version-yaml.sh

+21-5
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,27 @@ fi
3636

3737
target_go_version="$1"
3838

39-
# Search for YAML files in the current directory and its subdirectories
40-
yaml_files=$(find . -type f -name "*.yaml" -o -name "*.yml")
41-
42-
# Check each YAML file
43-
for file in $yaml_files; do
39+
# We find target files using the 'find' command in conjunction with the 'read'
40+
# command. We exclude some directories from the search.
41+
#
42+
# We use the 'read' command to help ensure that we correctly handle filenames
43+
# with spaces, newlines, and special characters. The '-print0' option in 'find'
44+
# outputs filenames separated by a null character. This allows the 'read'
45+
# command in the while loop to accurately distinguish each filename. The
46+
# 'target_files' array is then populated, preserving the integrity of each
47+
# filename. This approach ensures safe handling of filenames, regardless of
48+
# their complexity.
49+
while IFS= read -r -d '' file; do
50+
target_files+=("$file")
51+
done < <(find . \
52+
-path ./vendor -prune -o \
53+
-type f \
54+
\( -name "*.yaml" -o -name "*.yml" \) \
55+
-print0 \
56+
)
57+
58+
# Check for the expected Go version in each file.
59+
for file in "${target_files[@]}"; do
4460
check_go_version "$file" "$target_go_version"
4561
done
4662

0 commit comments

Comments
 (0)