-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update golanci-lint-action to scan all affected directories and corre…
…ctly upload reports Update golangci-lint action to go through all dirs if no working directory set Update paths to linter reports Restore producing test coverage report for each unit test run Remove test files fail_test.go and polished the workflows Get list of affected files Map affected files to modules Update lint working directory for uploading step Update lint working directory for uploading step Removed duplicated runs of golangci-lint Move running tests for core/scripts module to ci-core.yaml workflow Remove test files Move validation of golangci results to a non-matrix job Add filter for affected files in core/scripts. Move related tests to a separate job Update SonarQube to pick up coverage reports for core/scripts test runs
- Loading branch information
Showing
12 changed files
with
262 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# This script: | ||
# 1. Finds all modules. | ||
# 2. Maps changed files (passed as a param) to found modules. | ||
# 3. Prints out the affected modules. | ||
# 4. Output the result (as JSON) to a GitHub Actions environment variable. | ||
|
||
# Get the list of changed files as parameter (from JSON array) | ||
changed_files=$(echo "$1" | jq -r '.[]') | ||
echo "Changed files: $changed_files" | ||
|
||
# 1. Find all modules in the repository, | ||
# - Strip the leading './' from the path | ||
# (necessary for comparison, affected files do not have leading './') | ||
modules=$(find . -name 'go.mod' -exec dirname {} \; | sed 's|^./||' | uniq) | ||
echo "Found modules: $modules" | ||
|
||
# Use a Bash associative array to track unique modules | ||
declare -A unique_modules | ||
|
||
for path_to_file in $changed_files; do | ||
echo "Resolving a module affected by a file: '$path_to_file'" | ||
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'" | ||
unique_modules["$module"]="$module" | ||
break | ||
fi | ||
done | ||
done | ||
|
||
# Convert keys (module names) of the associative array to an indexed array | ||
affected_modules=("${!unique_modules[@]}") | ||
echo "Affected modules: ${affected_modules[@]}" | ||
|
||
# Convert bash array to a JSON array for GitHub Actions | ||
json_array=$(printf '%s\n' "${affected_modules[@]}" | jq -R . | jq -s . | jq -c) | ||
echo "module_names=$json_array" >> "$GITHUB_OUTPUT" |
Oops, something went wrong.