@@ -17,57 +17,52 @@ jobs:
1717 python-version : ["3.13"]
1818
1919 steps :
20- - name : Parse testing SDK branch from PR body
20+ - name : Parse testing SDK branch from PR body (Python)
2121 id : parse
2222 shell : bash
2323 run : |
2424 set -euo pipefail
2525
26- # Safely capture the PR body without breaking on quotes/newlines.
27- # GitHub interpolates the expression *before* bash sees it.
28- pr_body=$(cat <<'EOF'
29- ${{ github.event.pull_request.body }}
30- EOF
31- )
26+ python - << 'PYTHON'
27+ import os
28+ import re
3229
33- default_ref="main"
30+ body = os.environ.get("PR_BODY", "") or ""
31+ default_ref = "main"
3432
35- # Extract value from lines like:
36- # TESTING_SDK_BRANCH: feature/foo
37- # TESTING_SDK_BRANCH = feature/foo
38- # some text TESTING_SDK_BRANCH : feature/foo
39- #
40- # Rules:
41- # - case-insensitive key
42- # - accept ":" or "="
43- # - ignore surrounding whitespace
44- ref=$(
45- printf '%s\n' "$pr_body" \
46- | awk '
47- BEGIN { IGNORECASE = 1 }
48- {
49- # Match key, optional whitespace, : or =, optional whitespace, capture rest
50- if (match($0, /TESTING_SDK_BRANCH[[:space:]]*[:=][[:space:]]*(.*)$/, m)) {
51- val = m[1]
52- # Trim trailing whitespace
53- sub(/[[:space:]]+$/, "", val)
54- if (val != "") {
55- print val
56- exit 0
57- }
58- }
59- }
60- ' \
61- | head -n1 \
62- | tr -d "\r"
63- )
33+ # Regex:
34+ # - (?i) case-insensitive
35+ # - TESTING_SDK_BRANCH
36+ # - optional spaces
37+ # - : or =
38+ # - optional spaces
39+ # - capture rest of line
40+ pattern = re.compile(r"(?i)TESTING_SDK_BRANCH\s*[:=]\s*(.+)$")
6441
65- if [ -z "${ref:-}" ]; then
66- ref="$default_ref"
67- fi
42+ ref = None
43+ for line in body.splitlines() :
44+ m = pattern.search(line)
45+ if m :
46+ # Strip trailing whitespace
47+ candidate = m.group(1).strip()
48+ if candidate :
49+ ref = candidate
50+ break
51+
52+ if not ref :
53+ ref = default_ref
6854
69- echo "testing_ref=$ref" >> "$GITHUB_OUTPUT"
70- echo "Using testing SDK branch: $ref"
55+ github_output = os.environ.get("GITHUB_OUTPUT")
56+ if not github_output :
57+ raise SystemExit("GITHUB_OUTPUT not set")
58+
59+ with open(github_output, "a", encoding="utf-8") as fh :
60+ fh.write(f"testing_ref={ref}\n")
61+
62+ print(f"Using testing SDK branch : {ref}")
63+ PYTHON
64+ env :
65+ PR_BODY : ${{ github.event.pull_request.body }}
7166 - name : Checkout Language SDK (this PR)
7267 uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
7368 with :
0 commit comments