Skip to content

Commit 4abd2d2

Browse files
committed
Fix running Invoke-PhpBuild from paths with spaces
Add test workflow for local set up
1 parent 4b47956 commit 4abd2d2

3 files changed

Lines changed: 303 additions & 6 deletions

File tree

.github/workflows/local-test.yml

Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
name: Local Test
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
smoke:
11+
runs-on: windows-2022
12+
timeout-minutes: 240
13+
env:
14+
BUILD_ARCH: x64
15+
BUILD_TS: nts
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v6
19+
20+
- name: Resolve latest PHP 8.5 and Xdebug releases
21+
id: versions
22+
shell: pwsh
23+
env:
24+
GITHUB_TOKEN: ${{ github.token }}
25+
run: |
26+
$activeReleases = Invoke-RestMethod -Uri 'https://www.php.net/releases/active.php'
27+
$phpRelease = $activeReleases.'8'.'8.5'
28+
if (-not $phpRelease.version) {
29+
throw 'Could not resolve the latest PHP 8.5 release from php.net.'
30+
}
31+
32+
$phpVersion = $phpRelease.version
33+
$phpMinorVersion = ($phpVersion -split '\.')[0..1] -join '.'
34+
35+
$headers = @{
36+
Accept = 'application/vnd.github+json'
37+
'X-GitHub-Api-Version' = '2022-11-28'
38+
}
39+
if ($env:GITHUB_TOKEN) {
40+
$headers.Authorization = "Bearer $env:GITHUB_TOKEN"
41+
}
42+
43+
$xdebugRelease = Invoke-RestMethod -Uri 'https://api.github.com/repos/xdebug/xdebug/releases/latest' -Headers $headers
44+
$xdebugVersion = $xdebugRelease.tag_name.TrimStart('v')
45+
if (-not $xdebugVersion) {
46+
throw 'Could not resolve the latest Xdebug release from GitHub.'
47+
}
48+
49+
"php-version=$phpVersion" | Add-Content -Path $env:GITHUB_OUTPUT
50+
"php-version-minor=$phpMinorVersion" | Add-Content -Path $env:GITHUB_OUTPUT
51+
"xdebug-version=$xdebugVersion" | Add-Content -Path $env:GITHUB_OUTPUT
52+
53+
$xdebugPublishedAt = [DateTimeOffset]::Parse($xdebugRelease.published_at).ToString('yyyy-MM-dd')
54+
Write-Host "PHP 8.5 release: $phpVersion ($($phpRelease.date))"
55+
Write-Host "Xdebug release: $xdebugVersion ($xdebugPublishedAt)"
56+
57+
- name: Install local modules into Program Files with Install-Module
58+
shell: powershell
59+
run: |
60+
$repoName = 'LocalWorkspace'
61+
$repoPath = Join-Path $env:RUNNER_TEMP 'psrepo'
62+
$moduleNames = @('BuildPhp', 'BuildPhpExtension')
63+
$programFilesRoots = @(
64+
(Join-Path $env:ProgramFiles 'PowerShell\Modules'),
65+
(Join-Path $env:ProgramFiles 'WindowsPowerShell\Modules')
66+
)
67+
68+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
69+
Import-Module PowerShellGet -Force
70+
Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null
71+
72+
if (Get-PSRepository -Name $repoName -ErrorAction SilentlyContinue) {
73+
Unregister-PSRepository -Name $repoName
74+
}
75+
76+
Remove-Item -Path $repoPath -Recurse -Force -ErrorAction SilentlyContinue
77+
New-Item -Path $repoPath -ItemType Directory -Force | Out-Null
78+
Register-PSRepository -Name $repoName -SourceLocation $repoPath -PublishLocation $repoPath -InstallationPolicy Trusted
79+
80+
foreach ($moduleName in $moduleNames) {
81+
Get-InstalledModule -Name $moduleName -AllVersions -ErrorAction SilentlyContinue | Uninstall-Module -Force -ErrorAction SilentlyContinue
82+
83+
foreach ($root in $programFilesRoots) {
84+
$installedPath = Join-Path $root $moduleName
85+
if (Test-Path $installedPath) {
86+
Remove-Item -Path $installedPath -Recurse -Force
87+
}
88+
}
89+
}
90+
91+
Publish-Module -Path (Join-Path $env:GITHUB_WORKSPACE 'php\BuildPhp') -Repository $repoName -NuGetApiKey 'local'
92+
Publish-Module -Path (Join-Path $env:GITHUB_WORKSPACE 'extension\BuildPhpExtension') -Repository $repoName -NuGetApiKey 'local'
93+
94+
Install-Module -Name BuildPhp -Repository $repoName -Scope AllUsers -Force -AllowClobber -SkipPublisherCheck
95+
Install-Module -Name BuildPhpExtension -Repository $repoName -Scope AllUsers -Force -AllowClobber -SkipPublisherCheck
96+
97+
foreach ($moduleName in $moduleNames) {
98+
$module = Get-Module -ListAvailable -Name $moduleName | Sort-Object Version -Descending | Select-Object -First 1
99+
if (-not $module) {
100+
throw "Failed to install module $moduleName."
101+
}
102+
103+
$installedInProgramFiles = $false
104+
foreach ($root in $programFilesRoots) {
105+
if ($module.ModuleBase.StartsWith($root, [System.StringComparison]::OrdinalIgnoreCase)) {
106+
$installedInProgramFiles = $true
107+
break
108+
}
109+
}
110+
111+
if (-not $installedInProgramFiles) {
112+
throw "$moduleName was not installed under Program Files. Module path: $($module.ModuleBase)"
113+
}
114+
115+
Write-Host "$moduleName installed at $($module.ModuleBase)"
116+
}
117+
118+
"BUILDPHP_MODULE_BASE=$((Get-Module -ListAvailable -Name BuildPhp | Sort-Object Version -Descending | Select-Object -First 1).ModuleBase)" | Add-Content -Path $env:GITHUB_ENV
119+
"BUILDPHPEXTENSION_MODULE_BASE=$((Get-Module -ListAvailable -Name BuildPhpExtension | Sort-Object Version -Descending | Select-Object -First 1).ModuleBase)" | Add-Content -Path $env:GITHUB_ENV
120+
121+
- name: Build PHP
122+
shell: pwsh
123+
run: |
124+
$phpBuildRoot = Join-Path $env:RUNNER_TEMP 'php-build'
125+
Remove-Item -Path $phpBuildRoot -Recurse -Force -ErrorAction SilentlyContinue
126+
New-Item -Path $phpBuildRoot -ItemType Directory -Force | Out-Null
127+
128+
$buildPhpManifest = Join-Path $env:BUILDPHP_MODULE_BASE 'BuildPhp.psd1'
129+
Write-Host "Importing BuildPhp from $buildPhpManifest"
130+
Import-Module $buildPhpManifest -Force
131+
132+
Push-Location $phpBuildRoot
133+
try {
134+
Invoke-PhpBuild -PhpVersion '${{ steps.versions.outputs.php-version }}' `
135+
-Arch $env:BUILD_ARCH `
136+
-Ts $env:BUILD_TS
137+
} finally {
138+
Pop-Location
139+
}
140+
141+
- name: Build Xdebug
142+
shell: pwsh
143+
env:
144+
RUN_TESTS: 'false'
145+
run: |
146+
$xdebugBuildRoot = Join-Path $env:RUNNER_TEMP 'xdebug-build'
147+
Remove-Item -Path $xdebugBuildRoot -Recurse -Force -ErrorAction SilentlyContinue
148+
New-Item -Path $xdebugBuildRoot -ItemType Directory -Force | Out-Null
149+
150+
$buildPhpExtensionManifest = Join-Path $env:BUILDPHPEXTENSION_MODULE_BASE 'BuildPhpExtension.psd1'
151+
Write-Host "Importing BuildPhpExtension from $buildPhpExtensionManifest"
152+
Import-Module $buildPhpExtensionManifest -Force
153+
154+
Push-Location $xdebugBuildRoot
155+
try {
156+
Invoke-PhpBuildExtension -ExtensionUrl 'https://github.com/xdebug/xdebug' `
157+
-ExtensionRef '${{ steps.versions.outputs.xdebug-version }}' `
158+
-PhpVersion '${{ steps.versions.outputs.php-version-minor }}' `
159+
-Arch $env:BUILD_ARCH `
160+
-Ts $env:BUILD_TS `
161+
-Libraries 'zlib' `
162+
-Args '--with-xdebug'
163+
} finally {
164+
Pop-Location
165+
}
166+
167+
- name: Smoke test PHP with built Xdebug
168+
shell: pwsh
169+
env:
170+
PHP_VERSION: ${{ steps.versions.outputs.php-version }}
171+
XDEBUG_VERSION: ${{ steps.versions.outputs.xdebug-version }}
172+
run: |
173+
$phpArtifacts = Join-Path $env:RUNNER_TEMP 'php-build\artifacts'
174+
$xdebugArtifacts = Join-Path $env:RUNNER_TEMP 'xdebug-build\artifacts'
175+
$smokeRoot = Join-Path $env:RUNNER_TEMP 'smoke'
176+
$phpExtract = Join-Path $smokeRoot 'php'
177+
$xdebugExtract = Join-Path $smokeRoot 'xdebug'
178+
179+
Remove-Item -Path $smokeRoot -Recurse -Force -ErrorAction SilentlyContinue
180+
New-Item -Path $phpExtract -ItemType Directory -Force | Out-Null
181+
New-Item -Path $xdebugExtract -ItemType Directory -Force | Out-Null
182+
183+
$phpZip = Get-ChildItem -Path $phpArtifacts -File -Filter '*.zip' | Where-Object {
184+
$_.Name -notmatch '^php-(devel-pack|debug-pack|test-pack)-' -and
185+
$_.Name -notmatch '-src\.zip$'
186+
} | Sort-Object Name | Select-Object -First 1
187+
if (-not $phpZip) {
188+
throw 'Could not find the built PHP runtime archive.'
189+
}
190+
191+
$xdebugZip = Get-ChildItem -Path $xdebugArtifacts -File -Filter '*.zip' | Sort-Object Name | Select-Object -First 1
192+
if (-not $xdebugZip) {
193+
throw 'Could not find the built Xdebug archive.'
194+
}
195+
196+
Expand-Archive -Path $phpZip.FullName -DestinationPath $phpExtract -Force
197+
Expand-Archive -Path $xdebugZip.FullName -DestinationPath $xdebugExtract -Force
198+
199+
$xdebugDll = Get-ChildItem -Path $xdebugExtract -Filter 'php_xdebug*.dll' -File -Recurse | Select-Object -First 1
200+
if (-not $xdebugDll) {
201+
throw 'Could not find the built Xdebug DLL in the artifact.'
202+
}
203+
204+
$phpExtDirectory = Join-Path $phpExtract 'ext'
205+
New-Item -Path $phpExtDirectory -ItemType Directory -Force | Out-Null
206+
Copy-Item -Path $xdebugDll.FullName -Destination (Join-Path $phpExtDirectory 'php_xdebug.dll') -Force
207+
208+
Get-ChildItem -Path $xdebugExtract -Filter '*.dll' -File -Recurse | Where-Object {
209+
$_.FullName -ne $xdebugDll.FullName
210+
} | ForEach-Object {
211+
Copy-Item -Path $_.FullName -Destination $phpExtract -Force
212+
}
213+
214+
$phpIni = Join-Path $phpExtract 'php.ini'
215+
@(
216+
'[PHP]'
217+
"extension_dir=$phpExtDirectory"
218+
"zend_extension=$phpExtDirectory\php_xdebug.dll"
219+
) | Set-Content -Path $phpIni -Encoding Ascii
220+
221+
$phpExe = Join-Path $phpExtract 'php.exe'
222+
if (-not (Test-Path $phpExe)) {
223+
throw "Could not find php.exe in $phpExtract."
224+
}
225+
226+
$phpVersionOutput = (& $phpExe -c $phpIni -v 2>&1) | Out-String
227+
$phpVersionOutput | Tee-Object -FilePath (Join-Path $smokeRoot 'php-v.txt')
228+
if ($LASTEXITCODE -ne 0) {
229+
throw 'php -v failed.'
230+
}
231+
if ($phpVersionOutput -notmatch [regex]::Escape($env:PHP_VERSION)) {
232+
throw "php -v did not report PHP $($env:PHP_VERSION)."
233+
}
234+
if ($phpVersionOutput -notmatch 'Xdebug v') {
235+
throw 'php -v did not report a loaded Xdebug extension.'
236+
}
237+
238+
$xdebugInfoOutput = (& $phpExe -c $phpIni --ri xdebug 2>&1) | Out-String
239+
$xdebugInfoOutput | Tee-Object -FilePath (Join-Path $smokeRoot 'xdebug-ri.txt')
240+
if ($LASTEXITCODE -ne 0) {
241+
throw 'php --ri xdebug failed.'
242+
}
243+
if ($xdebugInfoOutput -notmatch [regex]::Escape($env:XDEBUG_VERSION)) {
244+
throw "php --ri xdebug did not report Xdebug $($env:XDEBUG_VERSION)."
245+
}
246+
247+
- name: Upload build and smoke artifacts
248+
if: always()
249+
uses: actions/upload-artifact@v7
250+
with:
251+
name: program-files-smoke-artifacts
252+
if-no-files-found: ignore
253+
path: |
254+
${{ runner.temp }}\php-build\artifacts\*
255+
${{ runner.temp }}\xdebug-build\artifacts\*
256+
${{ runner.temp }}\smoke\*
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
function Invoke-PhpSdkStarter {
2+
<#
3+
.SYNOPSIS
4+
Invoke phpsdk-starter.bat with the provided build configuration.
5+
.PARAMETER BuildDirectory
6+
Build directory containing the PHP SDK.
7+
.PARAMETER VsConfig
8+
Visual Studio configuration for the build.
9+
.PARAMETER Arch
10+
PHP Architecture
11+
.PARAMETER Task
12+
Task script to run through the PHP SDK starter.
13+
#>
14+
[OutputType()]
15+
param (
16+
[Parameter(Mandatory = $true, Position=0, HelpMessage='Build directory')]
17+
[string] $BuildDirectory,
18+
[Parameter(Mandatory = $true, Position=1, HelpMessage='Visual Studio configuration')]
19+
[PSCustomObject] $VsConfig,
20+
[Parameter(Mandatory = $true, Position=2, HelpMessage='PHP Architecture')]
21+
[ValidateNotNull()]
22+
[ValidateSet('x86', 'x64')]
23+
[string] $Arch,
24+
[Parameter(Mandatory = $true, Position=3, HelpMessage='Task script')]
25+
[string] $Task
26+
)
27+
begin {
28+
}
29+
process {
30+
$process = Start-Process -FilePath "$BuildDirectory\php-sdk\phpsdk-starter.bat" `
31+
-ArgumentList @('-c', $VsConfig.vs, '-a', $Arch, '-s', $VsConfig.toolset, '-t', $Task) `
32+
-NoNewWindow `
33+
-Wait `
34+
-PassThru
35+
if ($process.ExitCode -ne 0) {
36+
throw "build failed with errorlevel $($process.ExitCode)"
37+
}
38+
}
39+
end {
40+
}
41+
}

php/BuildPhp/public/Invoke-PhpBuild.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ function Invoke-PhpBuild {
6161

6262
if(-not [string]::IsNullOrWhiteSpace($env:LIBS_BUILD_RUNS)) {
6363
Add-PhpDeps -PhpVersion $PhpVersion -VsVersion $VsConfig.vs -Arch $Arch -Destination "$buildPath\..\deps"
64-
$task = "$PSScriptRoot\..\runner\task-$Ts.bat"
64+
$taskTemplate = Join-Path $PSScriptRoot "..\runner\task-$Ts.bat"
6565
} else {
66-
$task = "$PSScriptRoot\..\runner\task-$Ts-with-deps.bat"
66+
$taskTemplate = Join-Path $PSScriptRoot "..\runner\task-$Ts-with-deps.bat"
6767
}
6868

69-
& "$buildDirectory\php-sdk\phpsdk-starter.bat" -c $VsConfig.vs -a $Arch -s $VsConfig.toolset -t $task
70-
if (-not $?) {
71-
throw "build failed with errorlevel $LastExitCode"
72-
}
69+
$task = [System.IO.Path]::GetFileName($taskTemplate)
70+
Copy-Item -Path $taskTemplate -Destination $task -Force
71+
72+
Invoke-PhpSdkStarter -BuildDirectory $buildDirectory -VsConfig $VsConfig -Arch $Arch -Task $task
7373

7474
$artifacts = if ($Ts -eq "ts") {"..\obj\Release_TS\php-*.zip"} else {"..\obj\Release\php-*.zip"}
7575
New-Item "$currentDirectory\artifacts" -ItemType "directory" -Force > $null 2>&1

0 commit comments

Comments
 (0)