Skip to content

Commit 9b64ad8

Browse files
authored
Add dev:gen-ext-test-matrix command (#1133)
2 parents ca8a28a + 4d1ae00 commit 9b64ad8

51 files changed

Lines changed: 1113 additions & 270 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/tests.yml‎

Lines changed: 144 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
name: Tests
1+
name: v3 Tests
22

33
on:
44
pull_request:
5-
branches: [ "main", "v3" ]
6-
types: [ opened, synchronize, reopened ]
5+
branches: [ "v3" ]
6+
types: [ opened, synchronize, reopened, labeled, unlabeled ]
77
paths:
88
- 'src/**'
99
- 'config/**'
@@ -15,6 +15,10 @@ on:
1515

1616
permissions: read-all
1717

18+
concurrency:
19+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
20+
cancel-in-progress: true
21+
1822
env:
1923
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2024

@@ -103,114 +107,171 @@ jobs:
103107
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
104108

105109
- name: "Run PHPUnit Tests"
106-
run: SPC_LIBC=glibc vendor/bin/phpunit tests/ --no-coverage
110+
run: vendor/bin/phpunit tests/ --no-coverage
107111

108-
define-matrix:
109-
if: false # TODO: enable when refactoring workflows
110-
name: "Define Matrix"
112+
check-gate:
113+
name: "Check: need-test label"
111114
runs-on: ubuntu-latest
112115
outputs:
113-
php: ${{ steps.gendef.outputs.php }}
114-
os: ${{ steps.gendef.outputs.os }}
116+
enabled: ${{ steps.gate.outputs.enabled }}
115117
steps:
116-
- name: "Checkout"
117-
uses: actions/checkout@v4
118+
- name: Check label
119+
id: gate
120+
run: |
121+
LABELS='${{ toJSON(github.event.pull_request.labels.*.name) }}'
122+
if echo "$LABELS" | grep -q '"need-test"'; then
123+
echo "enabled=true" >> "$GITHUB_OUTPUT"
124+
else
125+
echo "enabled=false" >> "$GITHUB_OUTPUT"
126+
fi
127+
128+
test-bot:
129+
name: "Test Bot: analyze PR"
130+
needs: check-gate
131+
if: needs.check-gate.outputs.enabled == 'true'
132+
runs-on: ubuntu-latest
133+
permissions:
134+
pull-requests: write
135+
contents: read
136+
outputs:
137+
need_test: ${{ steps.bot.outputs.need_test }}
138+
gen_matrix_args: ${{ steps.bot.outputs.gen_matrix_args }}
139+
gen_matrix_args_tier2: ${{ steps.bot.outputs.gen_matrix_args_tier2 }}
140+
php_versions: ${{ steps.bot.outputs.php_versions }}
141+
tier2: ${{ steps.bot.outputs.tier2 }}
142+
steps:
143+
- uses: actions/checkout@v4
118144

119-
- name: "Setup PHP"
145+
- name: Setup PHP
120146
uses: shivammathur/setup-php@v2
121147
with:
122-
php-version: 8.4
148+
php-version: '8.4'
123149
extensions: curl, openssl, mbstring
150+
ini-values: memory_limit=-1
151+
tools: composer
152+
153+
- name: Install dependencies
154+
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --no-dev
124155

125-
- name: Define
126-
id: gendef
156+
- name: Run dev:test-bot
157+
id: bot
158+
env:
159+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
127160
run: |
128-
PHP_VERSIONS=$(php src/globals/test-extensions.php php)
129-
OS_VERSIONS=$(php src/globals/test-extensions.php os)
130-
echo 'php='"$PHP_VERSIONS" >> "$GITHUB_OUTPUT"
131-
echo 'os='"$OS_VERSIONS" >> "$GITHUB_OUTPUT"
161+
BOT_JSON=$(php -d opcache.enable_cli=0 bin/spc dev:test-bot \
162+
--pr=${{ github.event.pull_request.number }} \
163+
--repo=${{ github.repository }} 2>/dev/null)
164+
165+
echo "need_test=$(echo "$BOT_JSON" | jq -r '.need_test')" >> "$GITHUB_OUTPUT"
166+
echo "gen_matrix_args=$(echo "$BOT_JSON" | jq -r '.gen_matrix_args')" >> "$GITHUB_OUTPUT"
167+
echo "gen_matrix_args_tier2=$(echo "$BOT_JSON" | jq -r '.gen_matrix_args_tier2')" >> "$GITHUB_OUTPUT"
168+
echo "php_versions=$(echo "$BOT_JSON" | jq -c '.php_versions')" >> "$GITHUB_OUTPUT"
169+
echo "tier2=$(echo "$BOT_JSON" | jq -r '.tier2')" >> "$GITHUB_OUTPUT"
170+
171+
COMMENT_BODY=$(echo "$BOT_JSON" | jq -r '.comment_body')
172+
MARKER="<!-- spc-test-bot -->"
173+
174+
# Find existing bot comment id
175+
EXISTING_ID=$(gh api \
176+
repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments \
177+
--jq "[.[] | select(.body | startswith(\"$MARKER\")) | .id] | first // empty")
178+
179+
if [ -n "$EXISTING_ID" ]; then
180+
gh api --method PATCH \
181+
repos/${{ github.repository }}/issues/comments/"$EXISTING_ID" \
182+
-f body="$COMMENT_BODY"
183+
else
184+
gh pr comment ${{ github.event.pull_request.number }} \
185+
--repo ${{ github.repository }} \
186+
--body "$COMMENT_BODY"
187+
fi
188+
189+
gen-matrix:
190+
name: "Generate test matrix"
191+
needs: test-bot
192+
if: needs.test-bot.outputs.need_test == 'true'
193+
runs-on: ubuntu-latest
194+
outputs:
195+
matrix: ${{ steps.build.outputs.matrix }}
196+
steps:
197+
- uses: actions/checkout@v4
132198

199+
- name: Setup PHP
200+
uses: shivammathur/setup-php@v2
201+
with:
202+
php-version: '8.4'
203+
extensions: curl, openssl, mbstring
204+
ini-values: memory_limit=-1
205+
tools: composer
206+
207+
- name: Install dependencies
208+
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --no-dev
133209

134-
build:
135-
if: false
136-
name: "Build PHP Test (PHP ${{ matrix.php }} ${{ matrix.os }})"
137-
runs-on: ${{ matrix.os }}
138-
needs: [define-matrix, php-cs-fixer, phpstan, phpunit]
210+
- name: Build matrix
211+
id: build
212+
env:
213+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
214+
GEN_MATRIX_ARGS: ${{ needs.test-bot.outputs.gen_matrix_args }}
215+
GEN_MATRIX_ARGS_TIER2: ${{ needs.test-bot.outputs.gen_matrix_args_tier2 }}
216+
PHP_VERSIONS: ${{ needs.test-bot.outputs.php_versions }}
217+
TIER2: ${{ needs.test-bot.outputs.tier2 }}
218+
run: |
219+
# Tier1 matrix
220+
MATRIX1=$(bin/spc dev:gen-ext-test-matrix $GEN_MATRIX_ARGS 2>/dev/null)
221+
222+
# Merge Tier2 if requested
223+
if [ "$TIER2" = "true" ] && [ -n "$GEN_MATRIX_ARGS_TIER2" ]; then
224+
MATRIX2=$(bin/spc dev:gen-ext-test-matrix $GEN_MATRIX_ARGS_TIER2 2>/dev/null)
225+
COMBINED=$(jq -n --argjson m1 "$MATRIX1" --argjson m2 "$MATRIX2" '$m1 + $m2')
226+
else
227+
COMBINED=$MATRIX1
228+
fi
229+
230+
# Expand PHP versions: cartesian product of entries × php_versions
231+
FINAL=$(echo "$COMBINED" | jq --argjson versions "$PHP_VERSIONS" \
232+
'[.[] | . as $entry | $versions[] | $entry + {"php-version": .}]')
233+
234+
echo "matrix=$(echo "$FINAL" | jq -c '{"combo": .}')" >> "$GITHUB_OUTPUT"
235+
236+
ext-test:
237+
name: "Ext test: ${{ matrix.combo.extension }} (PHP ${{ matrix.combo.php-version }} · ${{ matrix.combo.os }}-${{ matrix.combo.arch }})"
238+
needs: gen-matrix
239+
runs-on: ${{ matrix.combo.runner }}
139240
timeout-minutes: 120
140241
strategy:
141-
matrix:
142-
php: ${{ fromJSON(needs.define-matrix.outputs.php) }}
143-
os: ${{ fromJSON(needs.define-matrix.outputs.os) }}
144242
fail-fast: false
243+
matrix: ${{ fromJSON(needs.gen-matrix.outputs.matrix) }}
145244
steps:
146-
- name: "Update runner packages"
147-
if: ${{ startsWith(matrix.os, 'ubuntu-') }}
148-
run: sudo apt-get update && sudo apt-get install -y ca-certificates
245+
- uses: actions/checkout@v4
149246

150-
- name: "Checkout"
151-
uses: actions/checkout@v4
152-
153-
- name: "Setup PHP"
247+
- name: Setup PHP
154248
uses: shivammathur/setup-php@v2
155249
with:
156250
php-version: 8.4
157-
tools: pecl, composer
158251
extensions: curl, openssl, mbstring
159252
ini-values: memory_limit=-1
253+
tools: composer
160254
env:
161255
phpts: nts
162256

163-
- name: "Cache composer packages"
164-
id: composer-cache
165-
uses: actions/cache@v4
166-
with:
167-
path: vendor
168-
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
169-
restore-keys: |
170-
${{ runner.os }}-php-
171-
172-
# Cache downloaded source
173-
- id: cache-download
174-
uses: actions/cache@v4
175-
with:
176-
path: downloads
177-
key: php-dependencies-${{ matrix.os }}
178-
179-
- name: "Install Dependencies"
180-
run: composer update -vvv --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --no-plugins
181-
182-
- name: "Run Build Tests (doctor)"
183-
run: php src/globals/test-extensions.php doctor_cmd ${{ matrix.os }} ${{ matrix.php }}
184-
185-
- name: "Prepare UPX for Windows"
186-
if: ${{ startsWith(matrix.os, 'windows-') }}
187-
run: |
188-
php src/globals/test-extensions.php install_upx_cmd ${{ matrix.os }} ${{ matrix.php }}
189-
echo "UPX_CMD=$(php src/globals/test-extensions.php upx)" >> $env:GITHUB_ENV
257+
- name: Install dependencies
258+
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --no-dev
190259

191-
- name: "Prepare UPX for Linux"
192-
if: ${{ startsWith(matrix.os, 'ubuntu-') }}
260+
- name: Build
261+
env:
262+
SPC_USE_SUDO: "yes"
263+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
193264
run: |
194-
php src/globals/test-extensions.php install_upx_cmd ${{ matrix.os }} ${{ matrix.php }}
195-
echo "UPX_CMD=$(php src/globals/test-extensions.php upx)" >> $GITHUB_ENV
196-
197-
- name: "Run Build Tests (download)"
198-
run: php src/globals/test-extensions.php download_cmd ${{ matrix.os }} ${{ matrix.php }}
199-
200-
- name: "Run Build Tests (build)"
201-
run: php src/globals/test-extensions.php build_cmd ${{ matrix.os }} ${{ matrix.php }}
265+
./bin/spc doctor --auto-fix
266+
${{ matrix.combo.build-args }} --dl-with-php=${{ matrix.combo.php-version }}
202267
203-
- name: "Run Build Tests (build - embed for non-windows)"
204-
if: ${{ !startsWith(matrix.os, 'windows-') }}
205-
run: php src/globals/test-extensions.php build_embed_cmd ${{ matrix.os }} ${{ matrix.php }}
268+
# - name: Setup upterm session
269+
# if: ${{ failure() }}
270+
# uses: owenthereal/action-upterm@v1
206271

207-
- name: "Upload logs"
208-
if: ${{ always() && hashFiles('log/**') != '' }}
209-
uses: actions/upload-artifact@v7
272+
- name: Upload logs
273+
if: always() && hashFiles('log/**') != ''
274+
uses: actions/upload-artifact@v4
210275
with:
211-
name: build-logs-${{ matrix.os }}-${{ matrix.php }}
276+
name: logs-${{ matrix.combo.os }}-${{ matrix.combo.arch }}-${{ matrix.combo.extension }}-php${{ matrix.combo.php-version }}
212277
path: log
213-
214-
# - name: Setup tmate session
215-
# if: ${{ failure() }}
216-
# uses: mxschmitt/action-tmate@v3

‎config/artifact/ncurses.yml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
ncurses:
2-
binary: hosted
32
metadata:
43
license-files:
54
- COPYING

‎config/pkg/ext/builtin-extensions.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ ext-xmlreader:
348348
type: php-extension
349349
depends:
350350
- ext-xml
351+
- ext-dom
351352
php-extension:
352353
arg-type: enable
353354
build-with-php: true

‎config/pkg/ext/ext-ds.yml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ ext-ds:
22
type: php-extension
33
artifact:
44
source:
5-
type: pecl
6-
name: ds
5+
type: git
6+
url: 'https://github.com/php-ds/ext-ds.git'
7+
rev: master
8+
extract: php-src/ext/ds
79
metadata:
810
license-files: [LICENSE]
911
license: MIT

‎config/pkg/ext/ext-swow.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ ext-swow:
1414
- curl
1515
- ext-openssl
1616
- ext-curl
17+
- postgresql
1718
php-extension:
1819
arg-type: custom

‎config/pkg/lib/brotli.yml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ brotli:
55
type: ghtagtar
66
repo: google/brotli
77
match: 'v1\.\d.*'
8-
binary: hosted
98
metadata:
109
license-files: [LICENSE]
1110
license: MIT

‎config/pkg/lib/bzip2.yml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ bzip2:
88
type: filelist
99
url: 'https://sourceware.org/pub/bzip2/'
1010
regex: '/href="(?<file>bzip2-(?<version>[^"]+)\.tar\.gz)"/'
11-
binary: hosted
1211
metadata:
1312
license-files: ['@/bzip2.txt']
1413
license: bzip2-1.0.6

‎config/pkg/lib/glfw.yml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
glfw:
22
type: library
33
artifact: glfw
4+
frameworks:
5+
- Cocoa
6+
- CoreFoundation
7+
- CoreVideo
8+
- IOKit
9+
- QuartzCore
410
headers:
511
- GLFW/glfw3.h
612
- GLFW/glfw3native.h

‎config/pkg/lib/libcares.yml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ libcares:
1010
type: filelist
1111
url: 'https://c-ares.org/download/'
1212
regex: '/href="\/download\/(?<file>c-ares-(?<version>[^"]+)\.tar\.gz)"/'
13-
binary: hosted
1413
metadata:
1514
license-files: [LICENSE.md]
1615
headers@unix:

‎config/pkg/lib/libedit.yml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ libedit:
55
type: filelist
66
url: 'https://thrysoee.dk/editline/'
77
regex: '/href="(?<file>libedit-(?<version>[^"]+)\.tar\.gz)"/'
8-
binary: hosted
98
metadata:
109
license-files: [COPYING]
1110
license: BSD-3-Clause

0 commit comments

Comments
 (0)