@@ -22,12 +22,10 @@ jobs:
2222 steps :
2323 - uses : actions/checkout@v4
2424
25- - name : Resolve wolfSSL ref from patch defines
26- id : resolve
25+ - name : Find patch defines
26+ id : find_defines
2727 run : |
2828 set -euo pipefail
29-
30- # Find WOLFSSL_PR*_PATCH_APPLIED defines in wolfssl source.
3129 defines="$(./scripts/find-wolfssl-pr-patch-defines.sh)"
3230 if [ -z "$defines" ]; then
3331 echo "::warning::No WOLFSSL_PR*_PATCH_APPLIED defines found; skipping patched CI."
@@ -36,49 +34,115 @@ jobs:
3634 fi
3735 echo "Found patch defines:"
3836 printf "%s\n" "$defines"
37+ {
38+ echo "should_run=true"
39+ echo "defines<<EOF"
40+ printf "%s\n" "$defines"
41+ echo "EOF"
42+ } >> "$GITHUB_OUTPUT"
43+
44+ - name : Evaluate PR statuses
45+ id : eval_prs
46+ if : steps.find_defines.outputs.should_run == 'true'
47+ run : |
48+ set -euo pipefail
3949
40- # Find the highest PR number from the defines.
41- pr_number="$(printf "%s\n" "$defines" | sed -E 's/^WOLFSSL_PR([0-9]+)_PATCH_APPLIED$/\1/' | sort -n | tail -1)"
42- if [ -z "$pr_number" ]; then
43- echo "::warning::Failed to derive PR number from patch defines; skipping patched CI."
44- echo "should_run=false" >> "$GITHUB_OUTPUT"
45- exit 0
46- fi
47- echo "Highest PR number from defines: $pr_number"
50+ defines="${{ steps.find_defines.outputs.defines }}"
51+ merged_all=true
52+ open_count=0
53+ open_repo=""
54+ open_ref=""
55+ open_pr=""
56+ has_invalid=false
4857
49- # Check PR status via GitHub API.
50- pr_json="$(curl -fsSL "https://api.github.com/repos/wolfSSL/wolfssl/pulls/$pr_number" || true)"
51- if [ -z "$pr_json" ]; then
52- echo "::warning::Unable to fetch PR #$pr_number from GitHub API; skipping patched CI."
53- echo "should_run=false" >> "$GITHUB_OUTPUT"
54- exit 0
55- fi
56- echo "Fetched PR #$pr_number info from GitHub API."
58+ echo "Evaluating patch defines:"
59+ printf "%s\n" "$defines"
60+
61+ while read -r define; do
62+ [ -z "$define" ] && continue
63+ pr_number="$(printf "%s" "$define" | sed -E 's/^WOLFSSL_PR([0-9]+)_PATCH_APPLIED$/\\1/')"
64+ if [ -z "$pr_number" ] || [ "$pr_number" = "$define" ]; then
65+ echo "::warning::Failed to derive PR number from define $define; skipping patched CI."
66+ echo "should_run=false" >> "$GITHUB_OUTPUT"
67+ exit 0
68+ fi
69+
70+ fork_ref_status="$(./scripts/find-pr-fork-branch.sh "$pr_number" --repo wolfSSL/wolfssl || true)"
71+ if [ -z "$fork_ref_status" ]; then
72+ echo "::warning::Unable to resolve PR #$pr_number fork/branch; skipping patched CI."
73+ echo "should_run=false" >> "$GITHUB_OUTPUT"
74+ exit 0
75+ fi
76+
77+ fork_ref="$(printf "%s" "$fork_ref_status" | sed -E 's/ \\([^)]*\\)$//')"
78+ pr_status="$(printf "%s" "$fork_ref_status" | sed -E 's/^.* \\(([^)]*)\\)$/\\1/')"
79+
80+ head_repo="${fork_ref%/*}"
81+ head_ref="${fork_ref#*/}"
82+ if [ -z "$head_repo" ] || [ -z "$head_ref" ] || [ "$head_repo" = "$head_ref" ]; then
83+ echo "::warning::Malformed fork/branch from helper script; skipping patched CI."
84+ echo "should_run=false" >> "$GITHUB_OUTPUT"
85+ exit 0
86+ fi
87+
88+ if [ "$pr_status" = "merged" ]; then
89+ continue
90+ elif [ "$pr_status" = "open" ]; then
91+ merged_all=false
92+ open_count=$((open_count + 1))
93+ open_repo="$head_repo"
94+ open_ref="$head_ref"
95+ open_pr="$pr_number"
96+ else
97+ merged_all=false
98+ has_invalid=true
99+ fi
100+ done <<EOF
101+ $defines
102+ EOF
103+
104+ {
105+ echo "MERGED_ALL=$merged_all"
106+ echo "OPEN_COUNT=$open_count"
107+ echo "OPEN_REPO=$open_repo"
108+ echo "OPEN_REF=$open_ref"
109+ echo "OPEN_PR=$open_pr"
110+ echo "HAS_INVALID=$has_invalid"
111+ } >> "$GITHUB_ENV"
112+
113+ echo "should_run=true" >> "$GITHUB_OUTPUT"
57114
58- state="$(printf "%s" "$pr_json" | jq -r '.state // empty')"
59- merged_at="$(printf "%s" "$pr_json" | jq -r '.merged_at // empty')"
60- head_repo="$(printf "%s" "$pr_json" | jq -r '.head.repo.full_name // empty')"
61- head_ref="$(printf "%s" "$pr_json" | jq -r '.head.ref // empty')"
115+ - name : Resolve wolfSSL ref from patch defines
116+ id : resolve
117+ if : steps.find_defines.outputs.should_run == 'true' && steps.eval_prs.outputs.should_run == 'true'
118+ run : |
119+ set -euo pipefail
62120
63- if [ -n "$merged_at " ]; then
64- echo "PR #$pr_number is merged; using wolfSSL master branch."
121+ if [ "${MERGED_ALL}" = "true " ]; then
122+ echo "All PRs are merged; using wolfSSL master branch."
65123 echo "should_run=true" >> "$GITHUB_OUTPUT"
66124 echo "wolfssl_repo=wolfSSL/wolfssl" >> "$GITHUB_OUTPUT"
67125 echo "wolfssl_ref=master" >> "$GITHUB_OUTPUT"
68- echo "pr_number=$pr_number" >> "$GITHUB_OUTPUT"
126+ echo "pr_number=all" >> "$GITHUB_OUTPUT"
127+ exit 0
128+ fi
129+
130+ if [ "${HAS_INVALID}" = "true" ]; then
131+ echo "::warning::One or more PRs are not merged or open; skipping patched CI."
132+ echo "should_run=false" >> "$GITHUB_OUTPUT"
69133 exit 0
70134 fi
71135
72- if [ "$state" = "open" ] && [ -n "$head_repo" ] && [ -n "$head_ref" ]; then
136+ if [ "${OPEN_COUNT}" -eq 1 ]; then
73137 echo "should_run=true" >> "$GITHUB_OUTPUT"
74- echo "wolfssl_repo=$head_repo " >> "$GITHUB_OUTPUT"
75- echo "wolfssl_ref=$head_ref " >> "$GITHUB_OUTPUT"
76- echo "pr_number=$pr_number " >> "$GITHUB_OUTPUT"
77- echo "PR #$pr_number is open; using branch $head_ref from repo $head_repo ."
138+ echo "wolfssl_repo=${OPEN_REPO} " >> "$GITHUB_OUTPUT"
139+ echo "wolfssl_ref=${OPEN_REF} " >> "$GITHUB_OUTPUT"
140+ echo "pr_number=${OPEN_PR} " >> "$GITHUB_OUTPUT"
141+ echo "Exactly one PR is open (#${OPEN_PR}) ; using branch ${OPEN_REF} from repo ${OPEN_REPO} ."
78142 exit 0
79143 fi
80144
81- echo "::warning::PR #$pr_number is not merged or has no accessible branch ; skipping patched CI."
145+ echo "::warning::Multiple open PRs found ; skipping patched CI."
82146 echo "should_run=false" >> "$GITHUB_OUTPUT"
83147
84148 patched_jni_build :
@@ -126,10 +190,9 @@ jobs:
126190 run : |
127191 echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GITHUB_WORKSPACE/build-dir/lib" >> "$GITHUB_ENV"
128192
129- - name : Build and test JNI library with all patches
193+ - name : Build and test JNI library with all patches enabled
130194 run : |
131- make all-patched PREFIX=$GITHUB_WORKSPACE/build-dir
132- make check
195+ make build check PREFIX=$GITHUB_WORKSPACE/build-dir ENABLE_PATCHES=1
133196
134197 - name : Show logs on failure
135198 if : failure() || cancelled()
0 commit comments