@@ -15,71 +15,109 @@ jobs:
1515 resolve_wolfssl_ref :
1616 runs-on : ubuntu-latest
1717 outputs :
18- should_run : ${{ steps.resolve.outputs.should_run }}
19- wolfssl_repo : ${{ steps.resolve.outputs.wolfssl_repo }}
20- wolfssl_ref : ${{ steps.resolve.outputs.wolfssl_ref }}
21- pr_number : ${{ steps.resolve.outputs.pr_number }}
18+ should_run : ${{ steps.eval_prs.outputs.should_run }}
19+ wolfssl_repo : ${{ steps.eval_prs.outputs.wolfssl_repo }}
20+ wolfssl_ref : ${{ steps.eval_prs.outputs.wolfssl_ref }}
2221 steps :
2322 - uses : actions/checkout@v4
2423
25- - name : Resolve wolfSSL ref from patch defines
26- id : resolve
24+ - name : Install prerequisites
2725 run : |
28- set -euo pipefail
26+ sudo apt-get update
27+ sudo apt-get install -y jq curl
2928
30- # Find WOLFSSL_PR*_PATCH_APPLIED defines in wolfssl source.
31- defines="$(./scripts/find-wolfssl-pr-patch-defines.sh)"
29+ - name : Find patch defines
30+ id : find_defines
31+ run : |
32+ set -euo pipefail
33+ defines=""
34+ if ! defines="$(./scripts/find-wolfssl-pr-patch-defines.sh)"; then
35+ echo "::warning::find-wolfssl-pr-patch-defines.sh failed; skipping patched CI."
36+ echo "should_run=false" >> "$GITHUB_OUTPUT"
37+ exit 0
38+ fi
3239 if [ -z "$defines" ]; then
3340 echo "::warning::No WOLFSSL_PR*_PATCH_APPLIED defines found; skipping patched CI."
3441 echo "should_run=false" >> "$GITHUB_OUTPUT"
3542 exit 0
3643 fi
3744 echo "Found patch defines:"
3845 printf "%s\n" "$defines"
46+ {
47+ echo "should_run=true"
48+ echo "defines<<EOF"
49+ printf "%s\n" "$defines"
50+ echo "EOF"
51+ } >> "$GITHUB_OUTPUT"
52+
53+ - name : Evaluate PR statuses
54+ id : eval_prs
55+ if : steps.find_defines.outputs.should_run == 'true'
56+ run : |
57+ set -euo pipefail
3958
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"
48-
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."
57-
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')"
62-
63- if [ -n "$merged_at" ]; then
64- echo "PR #$pr_number is merged; using wolfSSL master branch."
65- echo "should_run=true" >> "$GITHUB_OUTPUT"
66- echo "wolfssl_repo=wolfSSL/wolfssl" >> "$GITHUB_OUTPUT"
67- echo "wolfssl_ref=master" >> "$GITHUB_OUTPUT"
68- echo "pr_number=$pr_number" >> "$GITHUB_OUTPUT"
69- exit 0
70- fi
59+ defines="${{ steps.find_defines.outputs.defines }}"
60+ should_run=true
61+ wolfssl_repo="wolfSSL/wolfssl"
62+ wolfssl_ref="master"
63+ found_open=false
7164
72- if [ "$state" = "open" ] && [ -n "$head_repo" ] && [ -n "$head_ref" ]; then
73- 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."
78- exit 0
79- fi
65+ echo "Evaluating patch defines:"
66+ printf "%s\n" "$defines"
8067
81- echo "::warning::PR #$pr_number is not merged or has no accessible branch; skipping patched CI."
82- echo "should_run=false" >> "$GITHUB_OUTPUT"
68+ while read -r define; do
69+ define="$(printf "%s" "$define" | tr -d '\r' | xargs)"
70+ [ -z "$define" ] && continue
71+ pr_number="$(printf "%s" "$define" | sed -E 's/^WOLFSSL_PR([0-9]+)_PATCH_APPLIED$/\1/')"
72+ if [ -z "$pr_number" ] || [ "$pr_number" = "$define" ]; then
73+ echo "::warning::Failed to derive PR number from define $define; skipping patched CI."
74+ echo "should_run=false" >> "$GITHUB_OUTPUT"
75+ exit 0
76+ fi
77+
78+ fork_ref_status=""
79+ if ! fork_ref_status="$(./scripts/find-pr-fork-branch.sh "$pr_number" --repo wolfSSL/wolfssl)"; then
80+ echo "::warning::find-pr-fork-branch.sh failed for PR #$pr_number; skipping patched CI."
81+ echo "should_run=false" >> "$GITHUB_OUTPUT"
82+ exit 0
83+ fi
84+ if [ -z "$fork_ref_status" ]; then
85+ echo "::warning::Unable to resolve PR #$pr_number fork/branch; skipping patched CI."
86+ echo "should_run=false" >> "$GITHUB_OUTPUT"
87+ exit 0
88+ fi
89+ echo "PR #$pr_number raw status: [$fork_ref_status]"
90+
91+ case "$fork_ref_status" in
92+ *" (merged)")
93+ continue
94+ ;;
95+ *" (open)")
96+ if [ "$found_open" = "false" ]; then
97+ full_ref="${fork_ref_status%% *}"
98+ wolfssl_repo="${full_ref%/*}"
99+ wolfssl_ref="${full_ref##*/}"
100+ found_open=true
101+ echo "PR #$pr_number is open; using fork ref $wolfssl_repo/$wolfssl_ref for wolfSSL source"
102+ else
103+ echo "::warning::Found multiple PRs with patch defines; unable to determine which one to use; skipping patched CI."
104+ should_run=false
105+ break
106+ fi
107+ ;;
108+ *)
109+ echo "::warning::PR #$pr_number is in unexpected state: $fork_ref_status; skipping patched CI."
110+ should_run=false
111+ break
112+ ;;
113+ esac
114+ done <<EOF
115+ $defines
116+ EOF
117+
118+ echo "should_run=$should_run" >> "$GITHUB_OUTPUT"
119+ echo "wolfssl_repo=$wolfssl_repo" >> "$GITHUB_OUTPUT"
120+ echo "wolfssl_ref=$wolfssl_ref" >> "$GITHUB_OUTPUT"
83121
84122 patched_jni_build :
85123 needs : resolve_wolfssl_ref
@@ -126,10 +164,9 @@ jobs:
126164 run : |
127165 echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GITHUB_WORKSPACE/build-dir/lib" >> "$GITHUB_ENV"
128166
129- - name : Build and test JNI library with all patches
167+ - name : Build and test JNI library with all patches enabled
130168 run : |
131- make all-patched PREFIX=$GITHUB_WORKSPACE/build-dir
132- make check
169+ make build check PREFIX=$GITHUB_WORKSPACE/build-dir ENABLE_PATCHES=1
133170
134171 - name : Show logs on failure
135172 if : failure() || cancelled()
0 commit comments