generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,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 | ||
This file contains hidden or 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,84 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| import os | ||
| import sys | ||
|
|
||
| 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 input_text, expected in test_cases: | ||
| result = parse_sdk_branch(input_text) | ||
| if result != expected: | ||
| return False | ||
|
|
||
| return True | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| success = test_parse_sdk_branch() | ||
| sys.exit(0 if success else 1) |
This file contains hidden or 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,31 @@ | ||
| #!/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*(\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") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium test
Copilot Autofix
AI about 1 month ago
To fix this problem, add a
permissionskey to your workflow file, restricting the GITHUB_TOKEN privileges. Place this key either at the root, affecting all jobs, or under the relevant job. In this case, since only one job exists, it's simplest and clearest to place it at the workflow root (right after thename:and beforeon:), specifying minimal permissions. A starting point iscontents: read, which covers checking out code. If your workflow or job needs additional permissions, you can add them as needed. For this workflow, which just checks out code and runs a Python test file, this minimal set appears sufficient. Add:right after the
name:field and beforeon:.