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

Golangci-lint: fix logic for mapping affected files in CI #15776

Merged
merged 1 commit into from
Dec 19, 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
5 changes: 5 additions & 0 deletions .changeset/large-fishes-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

Fix logic for mapping affected files in CI that affects golangci-lint execution
34 changes: 22 additions & 12 deletions .github/scripts/map-affected-files-to-modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,35 @@ echo "Found modules: $modules"
declare -A unique_modules

for path_to_file in $changed_files; do
echo "Resolving a module affected by a file: '$path_to_file'"
echo "Resolving a module affected by a file: '$path_to_file'"
# the flag that indicates if the path matches any module
is_path_in_modules=false
for module in $modules; do
echo "Validating against module: '$module'"

# if no slash in the path, it is the root
# (i.e. `main.go`, `.gitignore` vs `core/main.go`)
if [[ ! $path_to_file =~ \/ ]]; then
echo "File '$path_to_file' mapped to the "root" module."
unique_modules["."]="."
break
# if a module's name matches with a file path
# add it, to the affected modules array, skipping the root (`.`)
elif [[ $module != "." && $path_to_file =~ ^$module* ]]; then
echo "File '$path_to_file' mapped the module '$module'"
if [[ $module != "." && $path_to_file =~ ^$module* ]]; then
echo -e "File '$path_to_file' mapped to the module '$module'\n"
unique_modules["$module"]="$module"
is_path_in_modules=true
break
fi
done
done
done
# if no matched module default to root module
if [[ $is_path_in_modules == false ]]; then
echo "File '$path_to_file' did not match any module, defaulting to root '.'"
unique_modules["."]="."
is_path_in_modules=false
fi
is_path_in_modules=false
done

# if the path is empty (for any reason), it will not get to the loop,
# so if the unique_modules array is empty, default to the root module
if [[ ${#unique_modules[@]} -eq 0 ]]; then
echo "No files were changed, defaulting to the root module '.'"
unique_modules["."]="."
fi

# Convert keys (module names) of the associative array to an indexed array
affected_modules=("${!unique_modules[@]}")
Expand Down
Loading