Skip to content

Commit 9084f7f

Browse files
author
Astraea Quinn S
authored
ci(sdk): fix branch parsing for integ framework
* fix branch parsing script * Format and fix tests * fix merge error * move workflow * fix invoke of the step
1 parent 43ad878 commit 9084f7f

4 files changed

Lines changed: 159 additions & 31 deletions

File tree

.github/workflows/integration-tests.yml

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,17 @@ jobs:
1717
python-version: ["3.13"]
1818

1919
steps:
20-
- name: Parse testing SDK branch from PR body
21-
id: parse
22-
run: |
23-
# Look for a line like: TESTING_SDK_BRANCH: feature/foo
24-
REF=$(printf '%s\n' '${{ github.event.pull_request.body }}' | sed -n 's/^TESTING_SDK_BRANCH:[[:space:]]*//p' | head -n1)
25-
if [ -z "$REF" ]; then REF="main"; fi
26-
echo "testing_ref=$REF" >> "$GITHUB_OUTPUT"
27-
echo "Using testing SDK branch: $REF"
28-
2920
- name: Checkout Language SDK (this PR)
3021
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
3122
with:
3223
path: language-sdk
3324

25+
- name: Parse testing SDK branch from PR body
26+
id: parse
27+
run: python language-sdk/ops/parse_sdk_branch.py
28+
env:
29+
PR_BODY: ${{ github.event.pull_request.body }}
30+
3431
- name: Checkout Testing SDK
3532
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
3633
with:
@@ -67,22 +64,19 @@ jobs:
6764
if: github.event_name == 'pull_request'
6865
env:
6966
AWS_REGION: us-west-2
70-
71-
steps:
72-
- name: Parse testing SDK branch from PR body
73-
id: parse
74-
run: |
75-
# Look for a line like: TESTING_SDK_BRANCH: feature/foo
76-
REF=$(printf '%s\n' '${{ github.event.pull_request.body }}' | sed -n 's/^TESTING_SDK_BRANCH:[[:space:]]*//p' | head -n1)
77-
if [ -z "$REF" ]; then REF="main"; fi
78-
echo "testing_ref=$REF" >> "$GITHUB_OUTPUT"
79-
echo "Using testing SDK branch: $REF"
8067

68+
steps:
8169
- name: Checkout Language SDK (this PR)
8270
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
8371
with:
8472
path: language-sdk
8573

74+
- name: Parse testing SDK branch from PR body
75+
id: parse
76+
run: python language-sdk/ops/parse_sdk_branch.py
77+
env:
78+
PR_BODY: ${{ github.event.pull_request.body }}
79+
8680
- name: Checkout Testing SDK
8781
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
8882
with:
@@ -133,20 +127,20 @@ jobs:
133127
run: |
134128
echo "Building examples..."
135129
hatch run examples:build
136-
130+
137131
# Get first integration example for testing
138132
EXAMPLE_NAME=$(echo '${{ steps.get-examples.outputs.examples }}' | jq -r '.[0].name')
139133
EXAMPLE_NAME_CLEAN=$(echo "$EXAMPLE_NAME" | sed 's/ //g')
140134
FUNCTION_NAME="${EXAMPLE_NAME_CLEAN}-LanguageSDK-PR-${{ github.event.number }}"
141-
135+
142136
echo "Deploying example: $EXAMPLE_NAME as $FUNCTION_NAME"
143137
hatch run examples:deploy "$EXAMPLE_NAME" --function-name "$FUNCTION_NAME"
144-
138+
145139
QUALIFIED_FUNCTION_NAME="$FUNCTION_NAME:\$LATEST"
146-
140+
147141
echo "Waiting for function to be ready..."
148142
aws lambda wait function-active --function-name "$FUNCTION_NAME" --endpoint-url "$LAMBDA_ENDPOINT" --region "${{ env.AWS_REGION }}"
149-
143+
150144
echo "Invoking Lambda function: $QUALIFIED_FUNCTION_NAME"
151145
aws lambda invoke \
152146
--function-name "$QUALIFIED_FUNCTION_NAME" \
@@ -156,18 +150,18 @@ jobs:
156150
--endpoint-url "$LAMBDA_ENDPOINT" \
157151
/tmp/response.json \
158152
> /tmp/invoke_response.json
159-
153+
160154
echo "Response:"
161155
cat /tmp/response.json
162-
156+
163157
# Check for function errors
164158
FUNCTION_ERROR=$(jq -r '.FunctionError // empty' /tmp/invoke_response.json)
165159
if [ -n "$FUNCTION_ERROR" ]; then
166160
echo "ERROR: Lambda function failed with error: $FUNCTION_ERROR"
167161
cat /tmp/response.json
168162
exit 1
169163
fi
170-
164+
171165
echo "Getting durable executions..."
172166
aws lambda list-durable-executions-by-function \
173167
--function-name "$QUALIFIED_FUNCTION_NAME" \
@@ -176,15 +170,13 @@ jobs:
176170
--endpoint-url "$LAMBDA_ENDPOINT" \
177171
--cli-binary-format raw-in-base64-out \
178172
> /tmp/executions.json
179-
173+
180174
echo "Durable Executions:"
181175
cat /tmp/executions.json
182-
176+
183177
# Cleanup
184178
echo "Cleaning up function: $FUNCTION_NAME"
185179
aws lambda delete-function \
186180
--function-name "$FUNCTION_NAME" \
187181
--endpoint-url "$LAMBDA_ENDPOINT" \
188182
--region "${{ env.AWS_REGION }}" || echo "Function cleanup failed or already deleted"
189-
190-

.github/workflows/test-parser.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Test Parser
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'ops/parse_sdk_branch.py'
7+
- 'ops/__tests__/**'
8+
push:
9+
branches: [ main ]
10+
paths:
11+
- 'ops/parse_sdk_branch.py'
12+
- 'ops/__tests__/**'
13+
14+
jobs:
15+
test-parser:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
19+
20+
- name: Run parser tests
21+
run: python ops/__tests__/test_parse_sdk_branch.py
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import sys
5+
6+
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
7+
8+
from parse_sdk_branch import parse_sdk_branch
9+
10+
11+
def test_parse_sdk_branch():
12+
test_cases = [
13+
# Basic cases
14+
("TESTING_SDK_BRANCH = feature/test", "feature/test"),
15+
("TESTING_SDK_BRANCH: feature/test", "feature/test"),
16+
("TESTING_SDK_BRANCH=feature/test", "feature/test"),
17+
("testing_sdk_branch: feature/test", "feature/test"),
18+
# Complex PR body with backticks and contractions
19+
(
20+
"""Updated the script to safely parse the testing SDK branch from the PR body, handling case insensitivity and whitespace.
21+
22+
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`
23+
24+
```
25+
plus of course the usage of multiple backticks to include code
26+
```
27+
28+
TESTING_SDK_BRANCH = main
29+
30+
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.""",
31+
"main",
32+
),
33+
# Edge cases with markdown and special characters
34+
(
35+
"""# PR Title
36+
37+
Some `code` and we've got contractions here.
38+
39+
```python
40+
def test():
41+
return "test"
42+
```
43+
44+
TESTING_SDK_BRANCH: feature/fix-backticks
45+
46+
More text with `inline code` and don't forget contractions.""",
47+
"feature/fix-backticks",
48+
),
49+
# Multiple occurrences (should take first)
50+
(
51+
"""TESTING_SDK_BRANCH = first-branch
52+
53+
Some text here.
54+
55+
TESTING_SDK_BRANCH = second-branch""",
56+
"first-branch",
57+
),
58+
# Whitespace variations
59+
(" TESTING_SDK_BRANCH = feature/spaces ", "feature/spaces"),
60+
("TESTING_SDK_BRANCH:feature/no-space", "feature/no-space"),
61+
# Default cases
62+
("No branch specified", "main"),
63+
("", "main"),
64+
("Just some random text", "main"),
65+
# Case with backticks in branch name
66+
("TESTING_SDK_BRANCH = feature/fix-`backticks`", "feature/fix-`backticks`"),
67+
# Case with contractions in surrounding text
68+
(
69+
"We've updated this and TESTING_SDK_BRANCH = feature/test and we're done",
70+
"feature/test",
71+
),
72+
]
73+
74+
for input_text, expected in test_cases:
75+
result = parse_sdk_branch(input_text)
76+
if result != expected:
77+
return False
78+
79+
return True
80+
81+
82+
if __name__ == "__main__":
83+
success = test_parse_sdk_branch()
84+
sys.exit(0 if success else 1)

ops/parse_sdk_branch.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import re
5+
6+
7+
def parse_sdk_branch(pr_body: str, default_ref: str = "main") -> str:
8+
"""Parse PR body for TESTING_SDK_BRANCH and return the branch reference."""
9+
pattern = re.compile(r"(?i)TESTING_SDK_BRANCH\s*[:=]\s*(\S+)", re.MULTILINE)
10+
11+
match = pattern.search(pr_body)
12+
if match:
13+
ref = match.group(1).strip()
14+
if ref:
15+
return ref
16+
17+
return default_ref
18+
19+
20+
def main():
21+
pr_body = os.environ.get("PR_BODY", "")
22+
ref = parse_sdk_branch(pr_body)
23+
24+
github_output = os.environ.get("GITHUB_OUTPUT")
25+
if github_output:
26+
with open(github_output, "a", encoding="utf-8") as f:
27+
f.write(f"testing_ref={ref}\n")
28+
29+
30+
if __name__ == "__main__":
31+
main()

0 commit comments

Comments
 (0)