Skip to content

Commit

Permalink
Merge pull request #775 from lightninglabs/go-version-check-file-excl…
Browse files Browse the repository at this point in the history
…usion

tools: exclude non-project files from go version consistency lint check
  • Loading branch information
guggero authored Feb 15, 2024
2 parents 783b7b3 + 5e54ff9 commit bb7e864
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
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

0 comments on commit bb7e864

Please sign in to comment.