From 0e0e7e03511c0f6655404a0985be5e8a352485e8 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Thu, 4 Apr 2024 16:19:31 +0530 Subject: [PATCH] Add support for custom test runner for extensions --- .github/workflows/extension.yml | 5 ++ .../BuildPhpExtension/BuildPhpExtension.psd1 | 2 +- .../private/Invoke-Build.ps1 | 5 -- .../private/Invoke-Tests.ps1 | 57 +++++++++++++++++++ .../public/Invoke-PhpBuildExtension.ps1 | 4 ++ extension/action.yml | 5 ++ 6 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 extension/BuildPhpExtension/private/Invoke-Tests.ps1 diff --git a/.github/workflows/extension.yml b/.github/workflows/extension.yml index 7d98eca..5c5cd63 100644 --- a/.github/workflows/extension.yml +++ b/.github/workflows/extension.yml @@ -12,6 +12,10 @@ on: description: 'Run tests after building the extension' required: false default: 'false' + test-runner: + description: 'Test runner to use' + required: false + default: 'run-tests.php' artifact-naming-scheme: description: 'Naming schema for the artifacts, pie or pecl' required: false @@ -51,6 +55,7 @@ jobs: arch: ${{ matrix.arch }} ts: ${{ matrix.ts }} run-tests: ${{ inputs.run-tests }} + test-runner: ${{ inputs.test-runner }} artifacts: runs-on: ubuntu-latest diff --git a/extension/BuildPhpExtension/BuildPhpExtension.psd1 b/extension/BuildPhpExtension/BuildPhpExtension.psd1 index 3f6d5aa..7f542c0 100644 --- a/extension/BuildPhpExtension/BuildPhpExtension.psd1 +++ b/extension/BuildPhpExtension/BuildPhpExtension.psd1 @@ -60,7 +60,7 @@ # NestedModules = @() # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. - FunctionsToExport = 'Invoke-PhpBuildExtension', 'Add-BuildRequirements', 'Add-Path', 'Get-PhpSdk', 'Add-Dependencies', 'Add-PhpDependencies', 'Get-VsVersion', 'Add-Extension', 'Get-Extension', 'Get-ExtensionSource', 'Add-ExtensionDependencies', 'Get-ExtensionConfig', 'Add-Extensions', 'Get-PhpBuild', 'Invoke-Build', 'Add-Package', 'Get-PhpDevelBuild' + FunctionsToExport = 'Invoke-PhpBuildExtension', 'Add-BuildRequirements', 'Add-Path', 'Get-PhpSdk', 'Add-Dependencies', 'Add-PhpDependencies', 'Get-VsVersion', 'Add-Extension', 'Get-Extension', 'Get-ExtensionSource', 'Add-ExtensionDependencies', 'Get-ExtensionConfig', 'Add-Extensions', 'Get-PhpBuild', 'Invoke-Build', 'Invoke-Tests', 'Add-Package', 'Get-PhpDevelBuild' # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. CmdletsToExport = '*' diff --git a/extension/BuildPhpExtension/private/Invoke-Build.ps1 b/extension/BuildPhpExtension/private/Invoke-Build.ps1 index 8cfa673..c98dc3e 100644 --- a/extension/BuildPhpExtension/private/Invoke-Build.ps1 +++ b/extension/BuildPhpExtension/private/Invoke-Build.ps1 @@ -18,11 +18,6 @@ Function Invoke-Build { $bat_content += "call phpize 2>&1" $bat_content += "call configure --with-php-build=`"..\deps`" $($Config.options) --with-mp=`"disable`" --enable-debug-pack 2>&1" $bat_content += "nmake /nologo 2>&1" - if($env:RUN_TESTS -eq "true") { - $php_dir = Join-Path (Get-Location).Path php-bin - New-Item -ItemType SymbolicLink -Path C:\php -Target $php_dir -Force > $null 2>&1 - $bat_content += "nmake /nologo test 2>&1" - } $bat_content += "exit %errorlevel%" Set-Content -Encoding "ASCII" -Path task.bat -Value $bat_content diff --git a/extension/BuildPhpExtension/private/Invoke-Tests.ps1 b/extension/BuildPhpExtension/private/Invoke-Tests.ps1 new file mode 100644 index 0000000..099c9e4 --- /dev/null +++ b/extension/BuildPhpExtension/private/Invoke-Tests.ps1 @@ -0,0 +1,57 @@ +Function Invoke-Tests { + <# + .SYNOPSIS + Build the extension + .PARAMETER Config + Extension Configuration + #> + [OutputType()] + param( + [Parameter(Mandatory = $true, Position=0, HelpMessage='Extension Configuration')] + [PSCustomObject] $Config + ) + begin { + } + process { + $currentDirectory = (Get-Location).Path + $php_dir = Join-Path $currentDirectory php-bin + $env:TEST_PHP_EXECUTABLE = "$php_dir\php.exe" + $env:REPORT_EXIT_STATUS = 1 + $env:XDEBUG_MODE = "" + $env:TEMP=$((Get-Item -LiteralPath $Env:TEMP).FullName) + $env:TMP=$((Get-Item -LiteralPath $Env:TMP).FullName) + $php_args = @( + '-n' + ) + if ((Select-String -Path 'config.w32' -Pattern 'ZEND_EXTENSION\(' -Quiet) -eq $true) { + $php_args += @( + "-d zend_extension=$currentDirectory\$($Config.build_directory)\php_$($Config.name).dll" + ) + } + $env:TEST_PHP_ARGS = $php_args -join ' ' + if ($null -eq $env:TEST_RUNNER) { + $env:TEST_RUNNER = 'run-tests.php' + } elseif(-not(Test-Path $env:TEST_RUNNER)) { + throw "Test runner $env:TEST_RUNNER does not exist." + } + $test_runner_args = @( + '-j8', + '-q', + '--offline', + '--show-diff', + '--show-slow 1000', + '--set-timeout 120', + '-g FAIL,XFAIL,BORK,WARN,LEAK,SKIP', + '--temp-source ' + $env:TEMP, + '--temp-target ' + $env:TEMP + ) + $phpExpression = "php $env:TEST_RUNNER " + ($test_runner_args -join ' ') + chcp 65001 + Write-Output "Running tests... $phpExpression" + Write-Output "TEST_PHP_ARGS $env:TEST_PHP_ARGS" + Write-Output "TEST_PHP_EXECUTABLE $env:TEST_PHP_EXECUTABLE" + Invoke-Expression $phpExpression + } + end { + } +} \ No newline at end of file diff --git a/extension/BuildPhpExtension/public/Invoke-PhpBuildExtension.ps1 b/extension/BuildPhpExtension/public/Invoke-PhpBuildExtension.ps1 index 0084d4d..3d2e520 100644 --- a/extension/BuildPhpExtension/public/Invoke-PhpBuildExtension.ps1 +++ b/extension/BuildPhpExtension/public/Invoke-PhpBuildExtension.ps1 @@ -66,6 +66,10 @@ function Invoke-PhpBuildExtension { Invoke-Build -Config $config + if($env:RUN_TESTS -eq 'true') { + Invoke-Tests -Config $config + } + Add-Package -Config $config Set-Location $currentDirectory diff --git a/extension/action.yml b/extension/action.yml index 4c5d74e..e240351 100644 --- a/extension/action.yml +++ b/extension/action.yml @@ -32,6 +32,10 @@ inputs: description: Run tests after building the extension required: false default: 'false' + test-runner: + description: Test runner to use + required: false + default: 'run-tests.php' artifact-naming-scheme: description: Naming schema for the artifacts, pie or pecl deprecationMessage: "This will be removed once pie is released" @@ -51,6 +55,7 @@ runs: LIBRARIES: ${{inputs.libs}} ARTIFACT_NAMING_SCHEME: ${{inputs.artifact-naming-scheme}} RUN_TESTS: ${{inputs.run-tests}} + TEST_RUNNER: ${{inputs.test-runner}} run: | Import-Module ${{ github.action_path }}\BuildPhpExtension -Force Invoke-PhpBuildExtension -ExtensionUrl "${{inputs.extension-url}}" `