Skip to content

Commit

Permalink
Golangci-lint: fix logic for mapping affected files in CI (#15776)
Browse files Browse the repository at this point in the history
  • Loading branch information
chudilka1 authored Dec 19, 2024
1 parent 73f16fe commit 06a4445
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
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

0 comments on commit 06a4445

Please sign in to comment.