-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(workflow): prevent false positives in cli import check #4048
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
base: main
Are you sure you want to change the base?
Conversation
|
Note Gemini is unable to generate a summary for this pull request due to the file types involved not being currently supported. |
|
Hi @KrshnKush , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Your PR has been received by the team and is currently under review. We will provide feedback as soon as we have an update to share. |
|
Hi @DeanChensj , can you please review this. LGTM , resolves a lot of false positives. |
| set +e | ||
| FILES_WITH_FORBIDDEN_IMPORT=$(grep -lE '^from.*cli.*import.*$' $CHANGED_FILES) | ||
| FILES_WITH_FORBIDDEN_IMPORT=$(grep -lE '^from\s+([^ ]*\.)?cli(\s|\.)' $CHANGED_FILES) | ||
| GREP_EXIT_CODE=$? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few things:
- Instead of "\s+", just match the space character " "
- don't match any pattern before "cli", just match optional "google.adk." or "adk.", i.e. (google.adk.)|(adk.)
- add back the matching of "import"
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
Problem:
The CI check for forbidden
clipackage imports uses an overly broad regex pattern^from.*cli.*import.*$that incorrectly matches any import containing the substring "cli". This causes false positives for legitimate imports like:from a2a.client import Clientfrom a2a.client.card_resolver import A2ACardResolverfrom mycli import somethingThese are valid imports from packages named
client,mycli, etc., not the forbiddenclipackage.PR where issue was found: #4023
Solution:
Updated the regex pattern to
^from\s+([^ ]*\.)?cli(\s|\.)which correctly matches only imports from a package literally namedcli:^from\s+- matches "from" followed by whitespace([^ ]*\.)?- optionally matches a module path prefix (e.g.,google.adk.)cli- the literal "cli" package name(\s|\.)- must be followed by whitespace (forimport) or a dot (for submodules)Testing Plan
Unit Tests:
Manual Verification:
Tested the regex patterns against various import statements:
from a2a.client import Clientfrom client import somethingfrom mycli import foofrom precli.something import barfrom cli import somethingfrom google.adk.cli import barfrom google.adk.cli.utils import bazChecklist
Additional context
Files changed:
.github/workflows/check-file-contents.yml- Fixed regex pattern for cli import detection