@@ -37,17 +37,15 @@ jobs:
3737 permissions :
3838 contents : read
3939 outputs :
40- matrix : ${{ steps.set-matrix.outputs.matrix }}
41- archs : ${{ steps.set-matrix.outputs.archs }}
40+ libs-pairs : ${{ steps.set-matrix.outputs.libs-pairs }}
41+ php-versions : ${{ steps.set-matrix.outputs.php-versions }}
4242 steps :
4343 - name : Set up matrix
4444 id : set-matrix
4545 run : |
46- # Default values
4746 default_php='["8.2","8.3","8.4","8.5"]'
4847 default_arch='["x86_64","aarch64"]'
4948
50- # Parse inputs or use defaults
5149 if [[ -n "${INPUTS_PHP_VERSIONS}" ]]; then
5250 php_versions=$(echo "${INPUTS_PHP_VERSIONS}" | jq -R 'split(",") | map(gsub("^\\s+|\\s+$";""))')
5351 else
@@ -60,15 +58,10 @@ jobs:
6058 arch_versions=$default_arch
6159 fi
6260
63- matrix=$(jq -nc \
64- --argjson php "$php_versions" \
65- --argjson arch "$arch_versions" \
66- '{"php-version":$php,"arch":$arch}')
61+ libs_pairs=$(jq -nc --argjson arch "$arch_versions" '{include: [$arch[] as $r | {arch: $r}]}')
6762
68- archs=$(jq -nc --argjson arch "$arch_versions" '{"arch":$arch}')
69-
70- echo "matrix=$matrix" >> $GITHUB_OUTPUT
71- echo "archs=$archs" >> $GITHUB_OUTPUT
63+ echo "libs-pairs=$libs_pairs" >> $GITHUB_OUTPUT
64+ echo "php-versions=$php_versions" >> $GITHUB_OUTPUT
7265 env :
7366 INPUTS_PHP_VERSIONS : ${{ inputs.php_versions }}
7467 INPUTS_ARCHITECTURES : ${{ inputs.architectures }}
8780 shell : bash
8881 strategy :
8982 fail-fast : false
90- matrix : ${{ fromJson(needs.setup-matrix.outputs.archs ) }}
83+ matrix : ${{ fromJson(needs.setup-matrix.outputs.libs-pairs ) }}
9184 env :
9285 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
9386 FORCE_JAVASCRIPT_ACTIONS_TO_NODE24 : true
@@ -143,9 +136,9 @@ jobs:
143136 tar -xzf downloads.tar.gz -C downloads
144137 rm downloads.tar.gz
145138
146- - name : Build libs (via PHP 8.5 reference build)
139+ - name : Build libs
147140 if : steps.cache.outputs.cache-hit != 'true'
148- run : php bin/spp all --target="native-native-musl -dynamic" --phpv=8.5 --prefix="-zts" --type=apk
141+ run : bin/spp build --target="native-native-musl -dynamic" --phpv=8.5 --type=apk --libs-only
149142
150143 - name : Pack buildroot
151144 if : steps.cache.outputs.cache-hit != 'true'
@@ -170,8 +163,48 @@ jobs:
170163 uses : mxschmitt/action-tmate@c0afd6f790e3a5564914980036ebf83216678101 # v3
171164 timeout-minutes : 30
172165
173- build :
166+ compute- build-matrix :
174167 needs : [setup-matrix, build-libs]
168+ runs-on : ubuntu-24.04
169+ if : ${{ !cancelled() }}
170+ permissions :
171+ actions : read
172+ outputs :
173+ matrix : ${{ steps.filter.outputs.matrix }}
174+ any : ${{ steps.filter.outputs.any }}
175+ steps :
176+ - name : Filter build matrix to arches with successful libs
177+ id : filter
178+ env :
179+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
180+ PHP_VERSIONS : ${{ needs.setup-matrix.outputs.php-versions }}
181+ run : |
182+ set -euo pipefail
183+ succeeded=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID/jobs" --paginate \
184+ --jq '.jobs[] | select(.conclusion == "success" and (.name | test("^Build libs \\("))) | .name' \
185+ | sed -E 's/^Build libs \(([^)]+)\)$/\1/' \
186+ | sort -u)
187+ echo "Successful libs arches:"
188+ printf '%s\n' "$succeeded"
189+
190+ include=$(jq -nc --arg s "$succeeded" --argjson p "$PHP_VERSIONS" '
191+ ($s | split("\n") | map(select(length > 0) | {arch: .})) as $arches |
192+ [ $arches[] as $a | $p[] as $php | $a + {"php-version": $php} ]
193+ ')
194+ count=$(jq 'length' <<< "$include")
195+ echo "Filtered combos: $count"
196+ printf '%s\n' "$include" | jq .
197+
198+ if [[ "$count" -gt 0 ]]; then
199+ echo "any=true" >> $GITHUB_OUTPUT
200+ else
201+ echo "any=false" >> $GITHUB_OUTPUT
202+ fi
203+ echo "matrix={\"include\":$include}" >> $GITHUB_OUTPUT
204+
205+ build :
206+ needs : [compute-build-matrix]
207+ if : ${{ !cancelled() && needs.compute-build-matrix.outputs.any == 'true' }}
175208 name : Build for ${{ matrix.arch }} PHP ${{ matrix.php-version }}
176209 runs-on : ${{ matrix.arch == 'x86_64' && 'ubuntu-24.04' || 'ubuntu-24.04-arm' }}
177210 container :
@@ -184,7 +217,7 @@ jobs:
184217 shell : bash
185218 strategy :
186219 fail-fast : false
187- matrix : ${{ fromJson(needs.setup -matrix.outputs.matrix) }}
220+ matrix : ${{ fromJson(needs.compute-build -matrix.outputs.matrix) }}
188221 env :
189222 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
190223 ITERATION : ${{ inputs.iteration || '' }}
0 commit comments