Skip to content

Commit 1df0fa6

Browse files
committed
Add support to test building PHP with new library builds
Add smoke tests to php builds
1 parent 7bf87d7 commit 1df0fa6

14 files changed

Lines changed: 539 additions & 37 deletions

.github/workflows/php.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,34 @@ jobs:
105105
name: test-results-${{matrix.arch}}-${{matrix.ts}}-${{matrix.opcache}}-${{matrix.test-type}}
106106
path: test-${{matrix.arch}}-${{matrix.ts}}-${{matrix.opcache}}-${{matrix.test-type}}.xml
107107

108+
smoke-tests:
109+
strategy:
110+
matrix:
111+
arch: [x64, x86]
112+
ts: [nts, ts]
113+
runs-on: windows-2022
114+
needs: [artifacts]
115+
steps:
116+
- name: Checkout
117+
uses: actions/checkout@v5
118+
119+
- name: Download artifacts
120+
uses: actions/download-artifact@v5
121+
with:
122+
name: artifacts
123+
path: artifacts
124+
125+
- name: Smoke test PHP builds
126+
shell: pwsh
127+
run: |
128+
Import-Module (Join-Path $(pwd).Path '\php\BuildPhp') -Force
129+
Invoke-PhpSmokeTests -ArtifactsDirectory (Join-Path $(pwd).Path 'artifacts') `
130+
-Arch ${{matrix.arch}} `
131+
-Ts ${{matrix.ts}}
132+
108133
upload:
109134
runs-on: ubuntu-latest
110-
needs: [artifacts, tests]
135+
needs: [artifacts, tests, smoke-tests]
111136
if: ${{ github.event.inputs.upload == 'true' }}
112137
steps:
113138
- name: Upload to downloads server
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
name: Build PHP with custom library builds from winlibs/winlib-builder
2+
run-name: Build PHP ${{ inputs.php-version }}
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
php-version:
7+
description: 'PHP version to build'
8+
required: true
9+
libs-build-runs:
10+
description: 'Comma-separated list of GitHub Actions run IDs from winlibs/winlib-builder'
11+
required: false
12+
13+
jobs:
14+
php:
15+
strategy:
16+
matrix:
17+
arch: [x64, x86]
18+
ts: [nts, ts]
19+
runs-on: windows-2022
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v5
23+
24+
- name: Build
25+
uses: ./php
26+
with:
27+
php-version: ${{ inputs.php-version }}
28+
arch: ${{ matrix.arch }}
29+
ts: ${{ matrix.ts }}
30+
libs-build-runs: ${{ inputs.libs-build-runs }}
31+
env:
32+
PHP_BUILD_PROVIDER: "The PHP Group"
33+
34+
artifacts:
35+
runs-on: ubuntu-latest
36+
needs: php
37+
outputs:
38+
artifact-id: ${{ steps.artifacts.outputs.artifact-id }}
39+
steps:
40+
- name: Upload artifacts
41+
uses: actions/upload-artifact/merge@v5
42+
id: artifacts
43+
with:
44+
name: artifacts
45+
delete-merged: true
46+
tests:
47+
strategy:
48+
matrix:
49+
arch: [x64, x86]
50+
ts: [nts, ts]
51+
opcache: [opcache, nocache]
52+
test-type: [php, ext]
53+
runs-on: windows-2022
54+
needs: artifacts
55+
steps:
56+
- name: Checkout
57+
uses: actions/checkout@v5
58+
59+
- name: Download artifacts
60+
uses: actions/download-artifact@v5
61+
id: artifacts
62+
with:
63+
name: artifacts
64+
65+
- name: Get Cache Key
66+
id: cache-key
67+
run: |
68+
$pv = '${{inputs.php-version}}'
69+
if('${{inputs.php-version}}' -ne 'master') {
70+
$pv = '${{inputs.php-version}}'.Split('.')[0..1] -join '.'
71+
}
72+
$vsVersion = (Get-Content -Raw -Path (Join-Path $(pwd).Path '\php\BuildPhp\config\vs.json') | ConvertFrom-Json).php.$pv
73+
$packagesListUrl = "https://downloads.php.net/~windows/php-sdk/deps/series/packages-$pv-$vsVersion-${{ matrix.arch }}-staging.txt"
74+
Invoke-WebRequest -OutFile packages.txt -Uri $packagesListUrl
75+
Add-Content -Value "cache-key=deps-$pv-${{ matrix.arch }}-${{ inputs.libs-build-runs }}" -Path $env:GITHUB_OUTPUT
76+
Add-Content -Value "cache-dir=C:\deps-$pv-${{ matrix.arch }}" -Path $env:GITHUB_OUTPUT
77+
78+
- name: Cache Deps
79+
id: cache-deps
80+
uses: actions/cache@v4
81+
with:
82+
path: ${{ steps.cache-key.outputs.cache-dir }}
83+
key: ${{ steps.cache-key.outputs.cache-key }}-${{ hashFiles('packages.txt') }}
84+
85+
- name: Test PHP
86+
shell: pwsh
87+
continue-on-error: true
88+
env:
89+
DEPS_DIR: ${{ steps.cache-key.outputs.cache-dir }}
90+
DEPS_CACHE_HIT: ${{ steps.cache-deps.outputs.cache-hit }}
91+
LIBS_BUILD_RUNS: ${{ inputs.libs-build-runs }}
92+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
93+
run: |
94+
Import-Module (Join-Path $(pwd).Path '\php\BuildPhp') -Force
95+
Invoke-PhpTests -PhpVersion ${{inputs.php-version}} `
96+
-Arch ${{matrix.arch}} `
97+
-Ts ${{matrix.ts}} `
98+
-Opcache ${{matrix.opcache}} `
99+
-TestType ${{matrix.test-type}}
100+
101+
- name: Upload artifacts
102+
uses: actions/upload-artifact@v5
103+
continue-on-error: true
104+
with:
105+
name: test-results-${{matrix.arch}}-${{matrix.ts}}-${{matrix.opcache}}-${{matrix.test-type}}
106+
path: test-${{matrix.arch}}-${{matrix.ts}}-${{matrix.opcache}}-${{matrix.test-type}}.xml
107+
108+
smoke-tests:
109+
strategy:
110+
matrix:
111+
arch: [x64, x86]
112+
ts: [nts, ts]
113+
runs-on: windows-2022
114+
needs: [artifacts]
115+
steps:
116+
- name: Checkout
117+
uses: actions/checkout@v5
118+
119+
- name: Download artifacts
120+
uses: actions/download-artifact@v5
121+
with:
122+
name: artifacts
123+
path: artifacts
124+
125+
- name: Smoke test PHP builds
126+
shell: pwsh
127+
run: |
128+
Import-Module (Join-Path $(pwd).Path '\php\BuildPhp') -Force
129+
Invoke-PhpSmokeTests -ArtifactsDirectory (Join-Path $(pwd).Path 'artifacts') `
130+
-Arch ${{matrix.arch}} `
131+
-Ts ${{matrix.ts}}

php/BuildPhp/BuildPhp.psd1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@
6767
'Add-TestRequirements',
6868
'Add-Vs',
6969
'Get-File',
70+
'Get-LibsBuildDeps',
7071
'Get-OciSdk',
7172
'Get-PhpBuild',
72-
'Get-PhpDeps',
7373
'Get-PhpSdk',
7474
'Get-PhpSrc',
7575
'Get-PhpTestPack',
@@ -92,6 +92,7 @@
9292

9393
# Public functions
9494
'Invoke-PhpBuild',
95+
'Invoke-PhpSmokeTests',
9596
'Invoke-PhpTests'
9697
)
9798

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
bz2
2+
com_dotnet
3+
curl
4+
enchant
5+
ftp
6+
gd
7+
intl
8+
ldap
9+
mbstring
10+
mysqli
11+
mysqlnd
12+
odbc
13+
openssl
14+
PDO
15+
pdo_mysql
16+
PDO_ODBC
17+
pdo_pgsql
18+
pdo_sqlite
19+
pgsql
20+
readline
21+
SimpleXML
22+
sodium
23+
sqlite3
24+
xml
25+
xmlreader
26+
xmlwriter
27+
xsl
28+
Zend OPcache
29+
zip
30+
zlib
Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
function Get-PhpDeps {
1+
function Add-PhpDeps {
22
<#
33
.SYNOPSIS
4-
Fetch specified PHP SDK deps zip packages and extract them to a destination directory.
5-
.PARAMETER Version
6-
PHP version series (e.g., 8.3 or master).
4+
Add PHP dependencies, optionally fetching from GitHub Actions workflow runs first.
5+
.PARAMETER PhpVersion
6+
PHP version (e.g., 8.4.18, 8.4, or master).
77
.PARAMETER VsVersion
88
Visual Studio toolset version (e.g., vs16, vs17).
99
.PARAMETER Arch
@@ -30,19 +30,42 @@ function Get-PhpDeps {
3030
begin {
3131
$baseurl = 'https://downloads.php.net/~windows/php-sdk/deps'
3232
}
33+
3334
process {
3435
if (-not (Test-Path -LiteralPath $Destination)) {
3536
New-Item -ItemType Directory -Force -Path $Destination | Out-Null
3637
}
3738

38-
$seriesUrl = "$baseurl/series/packages-$PhpVersion-$VsVersion-$Arch-staging.txt"
39-
Write-Verbose "Fetching series listing: $seriesUrl"
39+
$depsPhpVersion = $PhpVersion
40+
if ($PhpVersion -ne 'master') {
41+
$versionParts = $PhpVersion.Split('.')
42+
if ($versionParts.Count -ge 2) {
43+
$depsPhpVersion = $versionParts[0..1] -join '.'
44+
}
45+
}
46+
47+
$downloadedLibs = @()
48+
if ($env:LIBS_BUILD_RUNS) {
49+
$downloadedLibs = Get-LibsBuildDeps -Arch $Arch -Destination $Destination
50+
}
51+
52+
$seriesUrl = "$baseurl/series/packages-$depsPhpVersion-$VsVersion-$Arch-staging.txt"
53+
Write-Host "Fetching series listing: $seriesUrl"
4054
$series = Invoke-WebRequest -Uri $seriesUrl -UseBasicParsing -ErrorAction Stop
4155
$lines = @()
4256
if ($series -and $series.Content) {
4357
$lines = $series.Content -split "[\r\n]+" | Where-Object { $_ -and $_.Trim().Length -gt 0 }
4458
}
59+
4560
foreach ($line in $lines) {
61+
# Extract library name from package filename (e.g., "net-snmp-5.7.3-vs17-x64.zip" -> "net-snmp")
62+
$libName = $line -replace '-\d.*$', ''
63+
64+
if ($downloadedLibs -contains $libName) {
65+
Write-Host "Skipping package $line (already downloaded from workflow run)"
66+
continue
67+
}
68+
4669
Write-Host "Processing package $line"
4770
$temp = New-TemporaryFile | Rename-Item -NewName { $_.Name + '.zip' } -PassThru
4871
$url = "$baseurl/$VsVersion/$Arch/$line"

php/BuildPhp/private/Add-TestRequirements.ps1

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,12 @@ function Add-TestRequirements {
7979
}
8080

8181
$FetchDeps = $False
82-
$majorMinorVersion = ($PhpVersion -split '\.')[0..1] -join '.'
8382
if($null -eq $env:DEPS_DIR) {
84-
$env:DEPS_DIR = "C:\deps-$majorMinorVersion-$Arch"
83+
$env:DEPS_DIR = "C:\deps-$PhpVersion-$Arch"
8584
$FetchDeps = $True
8685
}
8786
if($FetchDeps -eq $True -or $null -eq $Env:DEPS_CACHE_HIT -or $Env:DEPS_CACHE_HIT -ne 'true') {
88-
Get-PhpDeps -PhpVersion $majorMinorVersion -VsVersion $VsVersion -Arch $Arch -Destination $env:DEPS_DIR
87+
Add-PhpDeps -PhpVersion $PhpVersion -VsVersion $VsVersion -Arch $Arch -Destination $env:DEPS_DIR
8988
}
9089
Invoke-EditBin -Exe "$binDirectoryPath\php.exe" -StackSize 8388608 -Arch $Arch
9190
Invoke-EditBin -Exe "$binDirectoryPath\php-cgi.exe" -StackSize 8388608 -Arch $Arch
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
function Get-LibsBuildDeps {
2+
<#
3+
.SYNOPSIS
4+
Download dependencies from GitHub Actions workflow runs.
5+
.PARAMETER Arch
6+
Target architecture: x86 or x64.
7+
.PARAMETER Destination
8+
Destination directory to extract the downloaded deps into.
9+
.OUTPUTS
10+
Array of library names that were downloaded.
11+
#>
12+
[CmdletBinding()]
13+
[OutputType([string[]])]
14+
param(
15+
[Parameter(Mandatory=$true)]
16+
[ValidateSet('x86','x64')]
17+
[string] $Arch,
18+
[Parameter(Mandatory=$true)]
19+
[ValidateNotNullOrEmpty()]
20+
[string] $Destination
21+
)
22+
23+
$downloadedLibs = @()
24+
25+
$runIds = @($env:LIBS_BUILD_RUNS -split ',' | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne '' })
26+
if ($runIds.Count -eq 0) {
27+
Write-Host 'No run IDs provided in LIBS_BUILD_RUNS'
28+
return $downloadedLibs
29+
}
30+
31+
$headers = @{
32+
'Accept' = 'application/vnd.github+json'
33+
'X-GitHub-Api-Version' = '2022-11-28'
34+
'User-Agent' = 'php-windows-builder'
35+
}
36+
37+
if ($env:GITHUB_TOKEN) {
38+
$headers['Authorization'] = 'Bearer ' + $env:GITHUB_TOKEN
39+
} else {
40+
Write-Warning 'GITHUB_TOKEN not set. API rate limits may apply.'
41+
}
42+
43+
foreach ($runId in $runIds) {
44+
Write-Host "Processing workflow run: $runId"
45+
$url = "https://api.github.com/repos/winlibs/winlib-builder/actions/runs/$runId/artifacts"
46+
$response = Invoke-RestMethod -Uri $url -Headers $headers -Method Get
47+
48+
if ($response.total_count -eq 0) {
49+
Write-Warning "No artifacts for run $runId"
50+
continue
51+
}
52+
53+
foreach ($artifact in $response.artifacts) {
54+
# Filter by architecture
55+
if ($artifact.name -notmatch $Arch) {
56+
continue
57+
}
58+
59+
Write-Host "Downloading artifact: $($artifact.name)"
60+
$libName = $artifact.name -replace '-\d.*$', ''
61+
$downloadedLibs += $libName
62+
63+
$tempZip = Join-Path $env:TEMP ([System.Guid]::NewGuid().ToString() + '.zip')
64+
65+
try {
66+
Write-Host "Downloading from: $($artifact.archive_download_url)"
67+
Invoke-WebRequest -Uri $artifact.archive_download_url -Headers $headers -OutFile $tempZip
68+
Write-Host "Downloaded to: $tempZip (Size: $((Get-Item $tempZip).Length) bytes)"
69+
70+
Write-Host "Extracting to: $Destination"
71+
Expand-Archive -LiteralPath $tempZip -DestinationPath $Destination -Force
72+
Write-Host "Extracted $($artifact.name) successfully"
73+
}
74+
catch {
75+
Write-Error "Failed to process artifact $($artifact.name): $_"
76+
throw
77+
}
78+
finally {
79+
Remove-Item -Path $tempZip -Force -ErrorAction SilentlyContinue
80+
}
81+
}
82+
}
83+
84+
Write-Host "Downloaded libraries from workflow runs: $($downloadedLibs -join ', ')"
85+
return $downloadedLibs
86+
}

0 commit comments

Comments
 (0)