-
Notifications
You must be signed in to change notification settings - Fork 17
ci(sdk): fix branch parsing for integ framework #189
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,21 @@ | |||||||||||||||||||||||
| name: Test Parser | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| on: | |||||||||||||||||||||||
| pull_request: | |||||||||||||||||||||||
| paths: | |||||||||||||||||||||||
| - 'ops/parse_sdk_branch.py' | |||||||||||||||||||||||
| - 'ops/__tests__/**' | |||||||||||||||||||||||
| push: | |||||||||||||||||||||||
| branches: [ main ] | |||||||||||||||||||||||
| paths: | |||||||||||||||||||||||
| - 'ops/parse_sdk_branch.py' | |||||||||||||||||||||||
| - 'ops/__tests__/**' | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| jobs: | |||||||||||||||||||||||
| test-parser: | |||||||||||||||||||||||
| runs-on: ubuntu-latest | |||||||||||||||||||||||
| steps: | |||||||||||||||||||||||
| - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| - name: Run parser tests | |||||||||||||||||||||||
| run: python ops/__tests__/test_parse_sdk_branch.py | |||||||||||||||||||||||
|
Comment on lines
+16
to
+21
Check warningCode scanning / CodeQL Workflow does not contain permissions Medium test
Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
Copilot AutofixAI 6 months ago To fix this problem, add a permissions:
contents: readright after the
Suggested changeset
1
.github/workflows/test-parser.yml
Copilot is powered by AI and may make mistakes. Always verify output.
Refresh and try again.
|
|||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| import sys | ||
| import os | ||
| sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) | ||
|
|
||
| from parse_sdk_branch import parse_sdk_branch | ||
|
|
||
|
|
||
| def test_parse_sdk_branch(): | ||
| test_cases = [ | ||
| # Basic cases | ||
| ("TESTING_SDK_BRANCH = feature/test", "feature/test"), | ||
| ("TESTING_SDK_BRANCH: feature/test", "feature/test"), | ||
| ("TESTING_SDK_BRANCH=feature/test", "feature/test"), | ||
| ("testing_sdk_branch: feature/test", "feature/test"), | ||
|
|
||
| # Complex PR body with backticks and contractions | ||
| ("""Updated the script to safely parse the testing SDK branch from the PR body, handling case insensitivity and whitespace. | ||
|
|
||
| The goal here is to fix the usage of backticks such as in `foo`, and contractions that we've been using such as `we've` | ||
|
|
||
| ``` | ||
| plus of course the usage of multiple backticks to include code | ||
| ``` | ||
|
|
||
| TESTING_SDK_BRANCH = main | ||
|
|
||
| By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.""", "main"), | ||
|
|
||
| # Edge cases with markdown and special characters | ||
| ("""# PR Title | ||
|
|
||
| Some `code` and we've got contractions here. | ||
|
|
||
| ```python | ||
| def test(): | ||
| return "test" | ||
| ``` | ||
|
|
||
| TESTING_SDK_BRANCH: feature/fix-backticks | ||
|
|
||
| More text with `inline code` and don't forget contractions.""", "feature/fix-backticks"), | ||
|
|
||
| # Multiple occurrences (should take first) | ||
| ("""TESTING_SDK_BRANCH = first-branch | ||
|
|
||
| Some text here. | ||
|
|
||
| TESTING_SDK_BRANCH = second-branch""", "first-branch"), | ||
|
|
||
| # Whitespace variations | ||
| (" TESTING_SDK_BRANCH = feature/spaces ", "feature/spaces"), | ||
| ("TESTING_SDK_BRANCH:feature/no-space", "feature/no-space"), | ||
|
|
||
| # Default cases | ||
| ("No branch specified", "main"), | ||
| ("", "main"), | ||
| ("Just some random text", "main"), | ||
|
|
||
| # Case with backticks in branch name | ||
| ("TESTING_SDK_BRANCH = feature/fix-`backticks`", "feature/fix-`backticks`"), | ||
|
|
||
| # Case with contractions in surrounding text | ||
| ("We've updated this and TESTING_SDK_BRANCH = feature/test and we're done", "feature/test"), | ||
| ] | ||
|
|
||
| for i, (input_text, expected) in enumerate(test_cases): | ||
| result = parse_sdk_branch(input_text) | ||
| if result != expected: | ||
| print(f"FAIL Test {i+1}: Expected '{expected}', got '{result}'") | ||
| print(f"Input: {repr(input_text[:100])}...") | ||
| return False | ||
| else: | ||
| print(f"PASS Test {i+1}: {expected}") | ||
|
|
||
| print(f"\nAll {len(test_cases)} tests passed!") | ||
| return True | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| success = test_parse_sdk_branch() | ||
| sys.exit(0 if success else 1) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| import os | ||
| import re | ||
|
|
||
|
|
||
|
|
||
| def parse_sdk_branch(pr_body: str, default_ref: str = "main") -> str: | ||
| """Parse PR body for TESTING_SDK_BRANCH and return the branch reference.""" | ||
| pattern = re.compile(r"(?i)TESTING_SDK_BRANCH\s*[:=]\s*(.+)$", re.MULTILINE) | ||
|
|
||
| match = pattern.search(pr_body) | ||
| if match: | ||
| ref = match.group(1).strip() | ||
| if ref: | ||
| return ref | ||
|
|
||
| return default_ref | ||
|
|
||
|
|
||
| def main(): | ||
| pr_body = os.environ.get("PR_BODY", "") | ||
| ref = parse_sdk_branch(pr_body) | ||
|
|
||
| github_output = os.environ.get("GITHUB_OUTPUT") | ||
| if github_output: | ||
| with open(github_output, "a", encoding="utf-8") as f: | ||
| f.write(f"testing_ref={ref}\n") | ||
|
|
||
| print(f"Using testing SDK branch: {ref}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
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.
this could live as a script in the ops/ dir - easier to test there :-)