Skip to content

Commit bd19d90

Browse files
committed
Add workflow for individual test directories
1 parent 6267c39 commit bd19d90

5 files changed

Lines changed: 294 additions & 13 deletions

File tree

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
name: Test PHP Directories
2+
run-name: Test PHP ${{ inputs.php-version }} directories
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
php-version:
7+
description: 'PHP version to test'
8+
required: true
9+
test-directories:
10+
description: 'Comma or newline-separated test directories'
11+
required: true
12+
arch:
13+
type: choice
14+
options: [x64, x86]
15+
description: 'Architecture'
16+
required: true
17+
default: x64
18+
ts:
19+
type: choice
20+
options: [nts, ts]
21+
description: 'Thread safety'
22+
required: true
23+
default: nts
24+
opcache:
25+
type: choice
26+
options: [nocache, opcache]
27+
description: 'Opcache mode'
28+
required: true
29+
default: nocache
30+
test-type:
31+
type: choice
32+
options: [ext, php]
33+
description: 'Test type'
34+
required: true
35+
default: ext
36+
php-build-run-id:
37+
description: 'Optional php-windows-builder run ID containing merged artifacts'
38+
required: false
39+
libs-build-runs:
40+
description: 'Comma-separated winlibs/winlib-builder run IDs used by the PHP build artifacts'
41+
required: false
42+
source-repository:
43+
description: 'php-src repository to source tests from when source-ref is provided'
44+
required: true
45+
default: php/php-src
46+
source-ref:
47+
description: 'Optional branch, tag, or SHA in the php-src repository'
48+
required: false
49+
50+
permissions:
51+
contents: read
52+
actions: read
53+
54+
jobs:
55+
set-matrix:
56+
runs-on: ubuntu-latest
57+
outputs:
58+
test-matrix: ${{ steps.set-matrix.outputs.test-matrix }}
59+
steps:
60+
- name: Generate test directory matrix
61+
id: set-matrix
62+
shell: pwsh
63+
run: |
64+
$ErrorActionPreference = 'Stop'
65+
$directories = @(
66+
'${{ inputs.test-directories }}' -split "[,`r`n]+" |
67+
ForEach-Object { $_.Trim() } |
68+
Where-Object { $_ -ne '' }
69+
)
70+
if ($directories.Count -eq 0) {
71+
throw 'No test directories were provided.'
72+
}
73+
74+
$include = @()
75+
foreach ($directory in $directories) {
76+
$name = ($directory -replace '[^A-Za-z0-9_.-]+', '-').Trim('-')
77+
if ([string]::IsNullOrWhiteSpace($name)) {
78+
$name = 'tests'
79+
}
80+
$include += [PSCustomObject]@{
81+
directory = $directory
82+
name = $name
83+
}
84+
}
85+
86+
$json = ConvertTo-Json @{ include = $include } -Compress -Depth 4
87+
Add-Content -Path $env:GITHUB_OUTPUT -Value "test-matrix=$json"
88+
89+
test:
90+
needs: set-matrix
91+
name: ${{ inputs.php-version }} ${{ matrix.name }} ${{ inputs.arch }} ${{ inputs.ts }} ${{ inputs.opcache }}
92+
runs-on: windows-2022
93+
timeout-minutes: 60
94+
strategy:
95+
fail-fast: false
96+
matrix: ${{ fromJSON(needs.set-matrix.outputs.test-matrix) }}
97+
steps:
98+
- name: Checkout
99+
uses: actions/checkout@v6
100+
101+
- name: Download PHP build artifacts
102+
if: ${{ inputs.php-build-run-id != '' }}
103+
shell: pwsh
104+
env:
105+
GH_TOKEN: ${{ github.token }}
106+
RUN_ID: ${{ inputs.php-build-run-id }}
107+
run: |
108+
$ErrorActionPreference = 'Stop'
109+
gh run download $env:RUN_ID `
110+
-R $env:GITHUB_REPOSITORY `
111+
-n artifacts `
112+
-D .
113+
Get-ChildItem -Filter '*.zip' | Sort-Object Name | Select-Object Name, Length
114+
115+
- name: Get Cache Key
116+
id: cache-key
117+
shell: pwsh
118+
run: |
119+
Import-Module (Join-Path $(pwd).Path '\php\BuildPhp') -Force
120+
$cacheInfo = Get-DepsCacheInfo `
121+
-PhpVersion '${{ inputs.php-version }}' `
122+
-Arch '${{ inputs.arch }}' `
123+
-LibsBuildRuns '${{ inputs.libs-build-runs }}' `
124+
-IncludeDefaultRunsKey
125+
Set-Content -Path packages.txt -Value ($cacheInfo.Packages -join "`n")
126+
Add-Content -Value "cache-key=$($cacheInfo.CacheKey)" -Path $env:GITHUB_OUTPUT
127+
Add-Content -Value "cache-dir=$($cacheInfo.CacheDir)" -Path $env:GITHUB_OUTPUT
128+
129+
- name: Cache Deps
130+
id: cache-deps
131+
uses: actions/cache@v5
132+
with:
133+
path: ${{ steps.cache-key.outputs.cache-dir }}
134+
key: ${{ steps.cache-key.outputs.cache-key }}-${{ hashFiles('packages.txt') }}
135+
136+
- name: Run tests
137+
shell: pwsh
138+
env:
139+
DEPS_DIR: ${{ steps.cache-key.outputs.cache-dir }}
140+
DEPS_CACHE_HIT: ${{ steps.cache-deps.outputs.cache-hit }}
141+
LIBS_BUILD_RUNS: ${{ inputs.libs-build-runs }}
142+
GITHUB_TOKEN: ${{ github.token }}
143+
run: |
144+
Import-Module (Join-Path $(pwd).Path '\php\BuildPhp') -Force
145+
Invoke-PhpTests -PhpVersion '${{ inputs.php-version }}' `
146+
-Arch '${{ inputs.arch }}' `
147+
-Ts '${{ inputs.ts }}' `
148+
-Opcache '${{ inputs.opcache }}' `
149+
-TestType '${{ inputs.test-type }}' `
150+
-SourceRepository '${{ inputs.source-repository }}' `
151+
-SourceRef '${{ inputs.source-ref }}' `
152+
-TestDirectories '${{ matrix.directory }}' `
153+
-FailOnError
154+
155+
- name: Upload test results
156+
if: always()
157+
continue-on-error: true
158+
uses: actions/upload-artifact@v7
159+
with:
160+
name: test-results-${{ inputs.php-version }}-${{ matrix.name }}-${{ inputs.arch }}-${{ inputs.ts }}-${{ inputs.opcache }}
161+
path: |
162+
test-${{ inputs.arch }}-${{ inputs.ts }}-${{ inputs.opcache }}-${{ inputs.test-type }}.xml
163+
test-${{ inputs.arch }}-${{ inputs.ts }}-${{ inputs.opcache }}-${{ inputs.test-type }}.log
164+
if-no-files-found: ignore

php/BuildPhp/BuildPhp.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
'Set-OdbcTestEnvironment',
9393
'Set-OpenSslTestEnvironment',
9494
'Set-PgSqlTestEnvironment',
95+
'Set-PhpExtTestEnvironment',
9596
'Set-PhpIniForTests',
9697
'Set-SnmpTestEnvironment',
9798

php/BuildPhp/private/Get-TestsList.ps1

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ function Get-TestsList {
66
Output file
77
.PARAMETER Type
88
Test type
9+
.PARAMETER TestDirectories
10+
Optional test directories to run instead of the configured test list
911
#>
1012
[OutputType()]
1113
param (
@@ -16,14 +18,26 @@ function Get-TestsList {
1618
[Parameter(Mandatory = $true, Position=1, HelpMessage='Test type')]
1719
[ValidateNotNull()]
1820
[ValidateSet('php', 'ext')]
19-
[string] $Type
21+
[string] $Type,
22+
[Parameter(Mandatory = $false, Position=2, HelpMessage='Optional test directories')]
23+
[string[]] $TestDirectories = @()
2024
)
2125
begin {
2226
}
2327
process {
2428
Remove-Item $OutputFile -ErrorAction "Ignore"
25-
foreach ($line in Get-Content "$PSScriptRoot\..\config\${Type}_test_directories") {
26-
$ttr = Get-ChildItem -Path $line -Filter "*.phpt" -Recurse
29+
$directories = $TestDirectories
30+
if ($null -eq $directories -or $directories.Count -eq 0) {
31+
$directories = Get-Content "$PSScriptRoot\..\config\${Type}_test_directories"
32+
}
33+
34+
foreach ($line in $directories) {
35+
$path = "$line".Trim()
36+
if ([string]::IsNullOrWhiteSpace($path)) {
37+
continue
38+
}
39+
40+
$ttr = Get-ChildItem -Path $path -Filter "*.phpt" -Recurse
2741
foreach ($t in $ttr) {
2842
Add-Content $OutputFile $t.FullName
2943
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
function Set-PhpExtTestEnvironment {
2+
<#
3+
.SYNOPSIS
4+
Configure extension-specific test environment dependencies.
5+
.PARAMETER TestDirectories
6+
Optional extension test directories to run.
7+
.PARAMETER BuildDirectory
8+
PHP build directory.
9+
.PARAMETER TestsDirectory
10+
PHP tests directory name.
11+
#>
12+
[CmdletBinding()]
13+
param (
14+
[Parameter(Mandatory = $false, Position=0, HelpMessage='Optional extension test directories')]
15+
[string[]] $TestDirectories = @(),
16+
[Parameter(Mandatory = $true, Position=1, HelpMessage='PHP build directory')]
17+
[ValidateNotNull()]
18+
[ValidateLength(1, [int]::MaxValue)]
19+
[string] $BuildDirectory,
20+
[Parameter(Mandatory = $true, Position=2, HelpMessage='PHP tests directory')]
21+
[ValidateNotNull()]
22+
[ValidateLength(1, [int]::MaxValue)]
23+
[string] $TestsDirectory
24+
)
25+
process {
26+
$runAllExtSetup = $null -eq $TestDirectories -or $TestDirectories.Count -eq 0
27+
$testDirectoryText = (@($TestDirectories) -join ';').ToLowerInvariant()
28+
29+
$testEnvironmentSetups = @(
30+
[pscustomobject] @{
31+
Match = @('mysql')
32+
Command = 'Set-MySqlTestEnvironment'
33+
Parameters = @{}
34+
},
35+
[pscustomobject] @{
36+
Match = @('pgsql', 'pdo_pgsql')
37+
Command = 'Set-PgSqlTestEnvironment'
38+
Parameters = @{}
39+
},
40+
[pscustomobject] @{
41+
Match = @('odbc', 'pdo_odbc')
42+
Command = 'Set-OdbcTestEnvironment'
43+
Parameters = @{}
44+
},
45+
[pscustomobject] @{
46+
Match = @('sqlsrv', 'pdo_sqlsrv')
47+
Command = 'Set-MsSqlTestEnvironment'
48+
Parameters = @{}
49+
},
50+
[pscustomobject] @{
51+
Match = @('firebird', 'interbase')
52+
Command = 'Set-FirebirdTestEnvironment'
53+
Parameters = @{}
54+
},
55+
[pscustomobject] @{
56+
Match = @('openssl')
57+
Command = 'Set-OpenSslTestEnvironment'
58+
Parameters = @{
59+
PhpBinDirectory = "$BuildDirectory\phpbin"
60+
}
61+
},
62+
[pscustomobject] @{
63+
Match = @('enchant')
64+
Command = 'Set-EnchantTestEnvironment'
65+
Parameters = @{}
66+
},
67+
[pscustomobject] @{
68+
Match = @('snmp')
69+
Command = 'Set-SnmpTestEnvironment'
70+
Parameters = @{
71+
TestsDirectoryPath = "$BuildDirectory\$TestsDirectory"
72+
}
73+
}
74+
)
75+
76+
$selectedSetups = if($runAllExtSetup) {
77+
$testEnvironmentSetups
78+
} else {
79+
$testEnvironmentSetups | Where-Object {
80+
$setup = $_
81+
@($setup.Match | Where-Object { $testDirectoryText.Contains($_) }).Count -gt 0
82+
}
83+
}
84+
85+
foreach($setup in $selectedSetups) {
86+
$parameters = $setup.Parameters
87+
& $setup.Command @parameters
88+
}
89+
}
90+
}

php/BuildPhp/public/Invoke-PhpTests.ps1

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ function Invoke-PhpTests {
1616
php-src repository to source tests from when SourceRef is provided.
1717
.PARAMETER SourceRef
1818
Optional branch, tag, or SHA in the custom php-src repository.
19+
.PARAMETER TestDirectories
20+
Optional test directories to run instead of the configured test list.
21+
.PARAMETER FailOnError
22+
Fail when run-tests.php returns a non-zero exit code.
1923
#>
2024
[OutputType()]
2125
param (
@@ -40,7 +44,11 @@ function Invoke-PhpTests {
4044
[Parameter(Mandatory = $false, Position=5, HelpMessage='php-src repository to source tests from when SourceRef is provided')]
4145
[string] $SourceRepository = 'php/php-src',
4246
[Parameter(Mandatory = $false, Position=6, HelpMessage='Optional branch, tag, or SHA in the custom php-src repository')]
43-
[string] $SourceRef = ''
47+
[string] $SourceRef = '',
48+
[Parameter(Mandatory = $false, Position=7, HelpMessage='Optional test directories')]
49+
[string[]] $TestDirectories = @(),
50+
[Parameter(Mandatory = $false, Position=8, HelpMessage='Fail on test errors')]
51+
[switch] $FailOnError
4452
)
4553
begin {
4654
}
@@ -93,19 +101,14 @@ function Invoke-PhpTests {
93101

94102
Set-Location "$testsDirectory"
95103

96-
Get-TestsList -OutputFile "$TestType-tests-to-run.txt" -Type $TestType
104+
Get-TestsList -OutputFile "$TestType-tests-to-run.txt" -Type $TestType -TestDirectories $TestDirectories
97105

98106
$settings = Get-TestSettings -PhpVersion $PhpVersion
99107

100108
if($TestType -eq "ext") {
101-
Set-MySqlTestEnvironment
102-
Set-PgSqlTestEnvironment
103-
Set-OdbcTestEnvironment
104-
Set-MsSqlTestEnvironment
105-
Set-FirebirdTestEnvironment
106-
Set-OpenSslTestEnvironment -PhpBinDirectory "$buildDirectory\phpbin"
107-
Set-EnchantTestEnvironment
108-
Set-SnmpTestEnvironment -TestsDirectoryPath "$buildDirectory\$testsDirectory"
109+
Set-PhpExtTestEnvironment -TestDirectories $TestDirectories `
110+
-BuildDirectory $buildDirectory `
111+
-TestsDirectory $testsDirectory
109112
}
110113

111114
$testTimeout = if ($TestType -eq 'ext') { '300' } else { '120' }
@@ -156,14 +159,23 @@ function Invoke-PhpTests {
156159
}
157160

158161
& $buildDirectory\phpbin\php.exe @params 2>&1 | Tee-Object -FilePath $testLogFile | Out-Host
162+
$testExitCode = $LASTEXITCODE
159163

160164
if(Test-Path $testResultFile) {
161165
Copy-Item $testResultFile $currentDirectory -Force
162166
} else {
163167
Write-Warning "Test results file was not generated: $testResultFile"
164168
}
165169

170+
if(Test-Path $testLogFile) {
171+
Copy-Item $testLogFile $currentDirectory -Force
172+
}
173+
166174
Set-Location "$currentDirectory"
175+
176+
if($FailOnError -and $testExitCode -ne 0) {
177+
throw "PHP tests failed for $Arch-$Ts-$Opcache-$TestType with exit code $testExitCode"
178+
}
167179
}
168180
end {
169181
}

0 commit comments

Comments
 (0)