chore(ci): run linter on proto and grpc modules when librarian.yaml is updated - #14004
chore(ci): run linter on proto and grpc modules when librarian.yaml is updated#14004zhumin8 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request modifies .kokoro/build.sh to conditionally include proto-* and grpc-* modules in the lint check when librarian.yaml is modified. The review feedback suggests improving the robustness of the file detection by using a regular expression to match exact file names and simplifying the complex conditional logic in the directory filtering using idiomatic Bash syntax.
| echo "${changed_file_list}" | ||
|
|
||
| has_librarian_change="false" | ||
| if grep -q "librarian.yaml" <<< "${changed_file_list}"; then |
There was a problem hiding this comment.
Using grep -q "librarian.yaml" can lead to false positives if there are other files containing librarian.yaml as a substring (e.g., not_librarian.yaml or some_librarian.yaml). To ensure we only match files named exactly librarian.yaml (either at the root or in a subdirectory), use a regular expression that matches the start of a line or a slash, followed by librarian.yaml at the end of the line.
| if grep -q "librarian.yaml" <<< "${changed_file_list}"; then | |
| if grep -qE "(^|/)librarian\.yaml$" <<< "${changed_file_list}"; then |
| { [ "${has_librarian_change}" == "true" ] || [[ "$(basename "${dir}")" != "proto-google-"* ]]; } && \ | ||
| { [ "${has_librarian_change}" == "true" ] || [[ "$(basename "${dir}")" != "grpc-google-"* ]]; } && \ |
There was a problem hiding this comment.
Using { [ ... ] || [[ ... ]]; } is complex and mixes different test syntaxes ([ and [[) along with command grouping { ... }. Since Bash's [[ ... ]] natively supports the || operator, you can simplify these conditions to be much more readable and idiomatic.
| { [ "${has_librarian_change}" == "true" ] || [[ "$(basename "${dir}")" != "proto-google-"* ]]; } && \ | |
| { [ "${has_librarian_change}" == "true" ] || [[ "$(basename "${dir}")" != "grpc-google-"* ]]; } && \ | |
| [[ "${has_librarian_change}" == "true" || "$(basename "${dir}")" != "proto-google-"* ]] && \ | |
| [[ "${has_librarian_change}" == "true" || "$(basename "${dir}")" != "grpc-google-"* ]] && \ |
This change aim to catch future lint issues when onboarding libraries at the initial PR, while not offsetting regular PR's lint run time.
For googleapis/librarian#7146