|
| 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 |
0 commit comments