setup-php 2.12.0 → 2.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +977 -936
  3. package/package.json +66 -56
  4. package/src/config.ts +82 -82
  5. package/src/configs/brew_extensions +30 -0
  6. package/src/configs/os_releases.csv +17 -0
  7. package/src/configs/php-versions.json +6 -5
  8. package/src/configs/{php.json → pm/php.json} +29 -29
  9. package/src/configs/{phpunit.json → pm/phpunit.json} +24 -24
  10. package/src/configs/tools.json +256 -234
  11. package/src/configs/tools_schema.json +114 -103
  12. package/src/coverage.ts +169 -142
  13. package/src/extensions.ts +363 -349
  14. package/src/install.ts +79 -82
  15. package/src/scripts/common.sh +366 -314
  16. package/src/scripts/darwin.sh +257 -248
  17. package/src/scripts/ext/blackfire.ps1 +32 -32
  18. package/src/scripts/ext/blackfire.sh +22 -21
  19. package/src/scripts/ext/couchbase.sh +43 -43
  20. package/src/scripts/ext/cubrid.sh +60 -60
  21. package/src/scripts/ext/extension_map.php +109 -0
  22. package/src/scripts/ext/firebird.ps1 +19 -19
  23. package/src/scripts/ext/firebird.sh +39 -35
  24. package/src/scripts/ext/gearman.sh +22 -22
  25. package/src/scripts/ext/geos.sh +17 -17
  26. package/src/scripts/ext/http.ps1 +54 -54
  27. package/src/scripts/ext/http.sh +120 -120
  28. package/src/scripts/ext/intl.sh +23 -23
  29. package/src/scripts/ext/ioncube.ps1 +33 -32
  30. package/src/scripts/ext/ioncube.sh +21 -19
  31. package/src/scripts/ext/oci.ps1 +60 -60
  32. package/src/scripts/ext/oci.sh +65 -63
  33. package/src/scripts/ext/patches/firebird.sh +11 -11
  34. package/src/scripts/ext/patches/geos.sh +7 -7
  35. package/src/scripts/ext/patches/http.sh +11 -11
  36. package/src/scripts/ext/patches/pdo_oci.sh +6 -6
  37. package/src/scripts/ext/patches/phpize.sh +26 -26
  38. package/src/scripts/ext/patches/protobuf.sh +4 -4
  39. package/src/scripts/ext/phalcon.ps1 +54 -55
  40. package/src/scripts/ext/phalcon.sh +59 -59
  41. package/src/scripts/ext/source.sh +144 -144
  42. package/src/scripts/linux.sh +239 -280
  43. package/src/scripts/tools/add_tools.ps1 +28 -25
  44. package/src/scripts/tools/add_tools.sh +27 -19
  45. package/src/scripts/tools/blackfire.ps1 +19 -21
  46. package/src/scripts/tools/blackfire.sh +40 -35
  47. package/src/scripts/tools/grpc_php_plugin.ps1 +21 -21
  48. package/src/scripts/tools/grpc_php_plugin.sh +58 -61
  49. package/src/scripts/tools/ppa.sh +189 -0
  50. package/src/scripts/tools/protoc.ps1 +38 -38
  51. package/src/scripts/tools/protoc.sh +28 -28
  52. package/src/scripts/win32.ps1 +566 -471
  53. package/src/tools.ts +538 -509
  54. package/src/utils.ts +503 -497
  55. package/.eslintrc.json +0 -16
  56. package/.github/CODE_OF_CONDUCT.md +0 -76
  57. package/.github/CONTRIBUTING.md +0 -70
  58. package/.github/FUNDING.yml +0 -7
  59. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -42
  60. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -26
  61. package/.github/PULL_REQUEST_TEMPLATE.md +0 -37
  62. package/.github/SECURITY.md +0 -29
  63. package/.github/workflows/docs.yml +0 -77
  64. package/.github/workflows/node-workflow.yml +0 -51
  65. package/.github/workflows/workflow.yml +0 -78
  66. package/.idea/workspace.xml +0 -113
  67. package/.prettierrc.json +0 -12
  68. package/__tests__/config.test.ts +0 -52
  69. package/__tests__/coverage.test.ts +0 -110
  70. package/__tests__/extensions.test.ts +0 -261
  71. package/__tests__/install.test.ts +0 -175
  72. package/__tests__/tools.test.ts +0 -490
  73. package/__tests__/utils.test.ts +0 -303
  74. package/action.yml +0 -29
  75. package/dist/index.js +0 -3001
  76. package/examples/bedrock.yml +0 -32
  77. package/examples/blackfire-player.yml +0 -31
  78. package/examples/blackfire.yml +0 -31
  79. package/examples/cakephp-mysql.yml +0 -114
  80. package/examples/cakephp-postgres.yml +0 -112
  81. package/examples/cakephp.yml +0 -92
  82. package/examples/codeigniter.yml +0 -34
  83. package/examples/laravel-mysql.yml +0 -74
  84. package/examples/laravel-postgres.yml +0 -74
  85. package/examples/laravel.yml +0 -42
  86. package/examples/lumen-mysql.yml +0 -74
  87. package/examples/lumen-postgres.yml +0 -74
  88. package/examples/lumen.yml +0 -38
  89. package/examples/phalcon-mysql.yml +0 -74
  90. package/examples/phalcon-postgres.yml +0 -73
  91. package/examples/sage.yml +0 -57
  92. package/examples/slim-framework.yml +0 -34
  93. package/examples/symfony-mysql.yml +0 -57
  94. package/examples/symfony-postgres.yml +0 -55
  95. package/examples/symfony.yml +0 -39
  96. package/examples/yii2-mysql.yml +0 -73
  97. package/examples/yii2-postgres.yml +0 -71
  98. package/examples/zend-framework.yml +0 -36
  99. package/jest.config.js +0 -12
  100. package/lib/config.js +0 -72
  101. package/lib/config.js.map +0 -1
  102. package/lib/coverage.js +0 -88
  103. package/lib/coverage.js.map +0 -1
  104. package/lib/extensions.js +0 -201
  105. package/lib/extensions.js.map +0 -1
  106. package/lib/install.js +0 -82
  107. package/lib/install.js.map +0 -1
  108. package/lib/sapi.js +0 -64
  109. package/lib/tools.js +0 -387
  110. package/lib/tools.js.map +0 -1
  111. package/lib/utils.js +0 -292
  112. package/lib/utils.js.map +0 -1
  113. package/tsconfig.json +0 -18
@@ -1,471 +1,566 @@
1
- param (
2
- [Parameter(Position = 0, Mandatory = $true)]
3
- [ValidateNotNull()]
4
- [ValidateLength(1, [int]::MaxValue)]
5
- [string]
6
- $version = '7.4',
7
- [Parameter(Position = 1, Mandatory = $true)]
8
- [ValidateNotNull()]
9
- [ValidateLength(1, [int]::MaxValue)]
10
- [string]
11
- $dist
12
- )
13
-
14
- # Function to log start of a operation.
15
- Function Step-Log($message) {
16
- printf "\n\033[90;1m==> \033[0m\033[37;1m%s \033[0m\n" $message
17
- }
18
-
19
- # Function to log result of a operation.
20
- Function Add-Log($mark, $subject, $message) {
21
- if ($mark -eq $tick) {
22
- printf "\033[32;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" $mark $subject $message
23
- } else {
24
- printf "\033[31;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" $mark $subject $message
25
- if($env:fail_fast -eq 'true') {
26
- exit 1;
27
- }
28
- }
29
- }
30
-
31
- # Function to add a line to a powershell profile safely.
32
- Function Add-ToProfile {
33
- param(
34
- [Parameter(Position = 0, Mandatory = $true)]
35
- [ValidateNotNull()]
36
- [ValidateLength(1, [int]::MaxValue)]
37
- [string]
38
- $input_profile,
39
- [Parameter(Position = 1, Mandatory = $true)]
40
- [ValidateNotNull()]
41
- [ValidateLength(1, [int]::MaxValue)]
42
- [string]
43
- $search,
44
- [Parameter(Position = 2, Mandatory = $true)]
45
- [ValidateNotNull()]
46
- [ValidateLength(1, [int]::MaxValue)]
47
- [string]
48
- $value
49
- )
50
- if($null -eq (Get-Content $input_profile | findstr $search)) {
51
- Add-Content -Path $input_profile -Value $value
52
- }
53
- }
54
-
55
- # Function to fetch PATH from the registry.
56
- Function Get-PathFromRegistry {
57
- $env:Path = [System.Environment]::GetEnvironmentVariable("Path","User") + ";" +
58
- [System.Environment]::GetEnvironmentVariable("Path","Machine")
59
- Add-ToProfile $current_profile 'Get-PathFromRegistry' 'Function Get-PathFromRegistry { $env:Path = [System.Environment]::GetEnvironmentVariable("Path", "User") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "Machine") }; Get-PathFromRegistry'
60
- }
61
-
62
- # Function to add a location to PATH.
63
- Function Add-Path {
64
- param(
65
- [string]$PathItem
66
- )
67
- $newPath = (Get-ItemProperty -Path 'hkcu:\Environment' -Name PATH).Path.replace("$PathItem;", '')
68
- $newPath = $PathItem + ';' + $newPath
69
- Set-ItemProperty -Path 'hkcu:\Environment' -Name Path -Value $newPath
70
- Get-PathFromRegistry
71
- }
72
-
73
- # Function to make sure printf is in PATH.
74
- Function Add-Printf {
75
- if (-not(Test-Path "C:\Program Files\Git\usr\bin\printf.exe")) {
76
- if(Test-Path "C:\msys64\usr\bin\printf.exe") {
77
- New-Item -Path $bin_dir\printf.exe -ItemType SymbolicLink -Value C:\msys64\usr\bin\printf.exe
78
- } else {
79
- Invoke-WebRequest -Uri "$github/shivammathur/printf/releases/latest/download/printf-x64.zip" -OutFile "$bin_dir\printf.zip"
80
- Expand-Archive -Path $bin_dir\printf.zip -DestinationPath $bin_dir -Force
81
- }
82
- } else {
83
- New-Item -Path $bin_dir\printf.exe -ItemType SymbolicLink -Value "C:\Program Files\Git\usr\bin\printf.exe"
84
- }
85
- }
86
-
87
- # Function to get a clean Powershell profile.
88
- Function Get-CleanPSProfile {
89
- if(-not(Test-Path -LiteralPath $profile)) {
90
- New-Item -Path $profile -ItemType "file" -Force
91
- }
92
- Set-Content $current_profile -Value ''
93
- Add-ToProfile $profile $current_profile.replace('\', '\\') ". $current_profile"
94
- }
95
-
96
- # Function to install a powershell package from GitHub.
97
- Function Install-PSPackage() {
98
- param(
99
- [Parameter(Position = 0, Mandatory = $true)]
100
- $package,
101
- [Parameter(Position = 1, Mandatory = $true)]
102
- $psm1_path,
103
- [Parameter(Position = 2, Mandatory = $true)]
104
- $url,
105
- [Parameter(Position = 3, Mandatory = $true)]
106
- $cmdlet
107
- )
108
- $module_path = "$bin_dir\$psm1_path.psm1"
109
- if(-not (Test-Path $module_path -PathType Leaf)) {
110
- $zip_file = "$bin_dir\$package.zip"
111
- Invoke-WebRequest -Uri $url -OutFile $zip_file
112
- Expand-Archive -Path $zip_file -DestinationPath $bin_dir -Force
113
- }
114
- Import-Module $module_path
115
- Add-ToProfile $current_profile "$package-search" "Import-Module $module_path"
116
-
117
- if($null -eq (Get-Command $cmdlet -ErrorAction SilentlyContinue)) {
118
- Install-Module -Name $cmdlet -Force
119
- }
120
- }
121
-
122
- Function Add-ExtensionPrerequisites{
123
- Param (
124
- [Parameter(Position = 0, Mandatory = $true)]
125
- [ValidateNotNull()]
126
- [ValidateLength(1, [int]::MaxValue)]
127
- [string]
128
- $extension
129
- )
130
- $deps_dir = "$ext_dir\$extension-vc$installed.VCVersion-$arch"
131
- $extensions_with_dependencies = ('imagick')
132
- if($extensions_with_dependencies.Contains($extension)) {
133
- if(-not(Test-Path $deps_dir)) {
134
- New-Item $deps_dir -Type Directory 2>&1 | Out-Null
135
- Install-PhpExtensionPrerequisite -Extension $extension -InstallPath $deps_dir -PhpPath $php_dir
136
- }
137
- Get-ChildItem -Recurse -Path $deps_dir | ForEach-Object {
138
- New-Item -Itemtype SymbolicLink -Path $php_dir -Name $_.Name -Target $_.FullName -Force >$null 2>&1
139
- }
140
- }
141
- }
142
-
143
- # Function to add PHP extensions.
144
- Function Add-Extension {
145
- Param (
146
- [Parameter(Position = 0, Mandatory = $true)]
147
- [ValidateNotNull()]
148
- [ValidateLength(1, [int]::MaxValue)]
149
- [string]
150
- $extension,
151
- [Parameter(Position = 1, Mandatory = $false)]
152
- [ValidateNotNull()]
153
- [ValidateSet('stable', 'beta', 'alpha', 'devel', 'snapshot')]
154
- [string]
155
- $stability = 'stable',
156
- [Parameter(Position = 2, Mandatory = $false)]
157
- [ValidateNotNull()]
158
- [ValidatePattern('^\d+(\.\d+){0,2}$')]
159
- [string]
160
- $extension_version = ''
161
- )
162
- try {
163
- $extension_info = Get-PhpExtension -Path $php_dir | Where-Object { $_.Name -eq $extension -or $_.Handle -eq $extension }
164
- if ($null -ne $extension_info) {
165
- switch ($extension_info.State) {
166
- 'Builtin' {
167
- Add-Log $tick $extension "Enabled"
168
- }
169
- 'Enabled' {
170
- Add-Log $tick $extension "Enabled"
171
- }
172
- default {
173
- Add-ExtensionPrerequisites $extension
174
- Enable-PhpExtension -Extension $extension_info.Handle -Path $php_dir
175
- Add-Log $tick $extension "Enabled"
176
- }
177
- }
178
- }
179
- else {
180
- Add-ExtensionPrerequisites $extension
181
- if($extension_version -ne '') {
182
- Install-PhpExtension -Extension $extension -Version $extension_version -MinimumStability $stability -MaximumStability $stability -Path $php_dir -NoDependencies
183
- } else {
184
- Install-PhpExtension -Extension $extension -MinimumStability $stability -MaximumStability $stability -Path $php_dir -NoDependencies
185
- }
186
-
187
- Add-Log $tick $extension "Installed and enabled"
188
- }
189
- }
190
- catch {
191
- Add-Log $cross $extension "Could not install $extension on PHP $($installed.FullVersion)"
192
- }
193
- }
194
-
195
- # Function to remove PHP extensions.
196
- Function Remove-Extension() {
197
- Param (
198
- [Parameter(Position = 0, Mandatory = $true)]
199
- [ValidateNotNull()]
200
- [ValidateLength(1, [int]::MaxValue)]
201
- [string]
202
- $extension
203
- )
204
- if(php -m | findstr -i $extension) {
205
- try {
206
- Disable-PhpExtension $extension $php_dir
207
- if (Test-Path $ext_dir\php_$extension.dll) {
208
- Remove-Item $ext_dir\php_$extension.dll
209
- }
210
- Add-Log $tick ":$extension" "Removed"
211
- } catch {
212
- Add-Log $cross ":$extension" "Could not remove $extension on PHP $($installed.FullVersion)"
213
- }
214
- } else {
215
- Add-Log $tick ":$extension" "Could not find $extension on PHP $($installed.FullVersion)"
216
- }
217
- }
218
-
219
- Function Edit-ComposerConfig() {
220
- Param(
221
- [Parameter(Position = 0, Mandatory = $true)]
222
- [ValidateNotNull()]
223
- [ValidateLength(1, [int]::MaxValue)]
224
- [string]
225
- $tool_path
226
- )
227
- Copy-Item $tool_path -Destination "$tool_path.phar"
228
- php -r "try {`$p=new Phar('$tool_path.phar', 0);exit(0);} catch(Exception `$e) {exit(1);}"
229
- if ($? -eq $False) {
230
- Add-Log "$cross" "composer" "Could not download composer"
231
- exit 1;
232
- }
233
- if (-not(Test-Path $composer_json)) {
234
- Set-Content -Path $composer_json -Value "{}"
235
- }
236
- composer -q config -g process-timeout 0
237
- Write-Output $composer_bin | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8
238
- if (Test-Path env:COMPOSER_TOKEN) {
239
- composer -q config -g github-oauth.github.com $env:COMPOSER_TOKEN
240
- }
241
- }
242
-
243
- # Function to extract tool version.
244
- Function Get-ToolVersion() {
245
- Param (
246
- [Parameter(Position = 0, Mandatory = $true)]
247
- $tool,
248
- [Parameter(Position = 1, Mandatory = $true)]
249
- $param
250
- )
251
- $alp = "[a-zA-Z0-9]"
252
- $version_regex = "[0-9]+((\.{1}$alp+)+)(\.{0})(-$alp+){0,1}"
253
- if($tool -eq 'composer') {
254
- if ($param -eq 'snapshot') {
255
- $composer_version = (Select-String -Pattern "const\sBRANCH_ALIAS_VERSION" -Path $bin_dir\composer -Raw | Select-String -Pattern $version_regex | ForEach-Object { $_.matches.Value }) + '+' + (Select-String -Pattern "const\sVERSION" -Path $bin_dir\composer -Raw | Select-String -Pattern "[a-zA-Z0-9]+" -AllMatches | ForEach-Object { $_.matches[2].Value })
256
- } else {
257
- $composer_version = Select-String -Pattern "const\sVERSION" -Path $bin_dir\composer -Raw | Select-String -Pattern $version_regex | ForEach-Object { $_.matches.Value }
258
- }
259
- Set-Variable -Name 'composer_version' -Value $composer_version -Scope Global
260
- return "$composer_version"
261
- }
262
- return . $tool $param 2> $null | ForEach-Object { $_ -replace "composer $version_regex", '' } | Select-String -Pattern $version_regex | Select-Object -First 1 | ForEach-Object { $_.matches.Value }
263
- }
264
-
265
- # Function to add tools.
266
- Function Add-Tool() {
267
- Param (
268
- [Parameter(Position = 0, Mandatory = $true)]
269
- [ValidateNotNull()]
270
- $url,
271
- [Parameter(Position = 1, Mandatory = $true)]
272
- [ValidateNotNull()]
273
- $tool,
274
- [Parameter(Position = 2, Mandatory = $true)]
275
- [ValidateNotNull()]
276
- $ver_param
277
- )
278
- if (Test-Path $bin_dir\$tool) {
279
- Remove-Item $bin_dir\$tool
280
- }
281
- if($url.Count -gt 1) {
282
- $url = $url[0]
283
- }
284
- $tool_path = "$bin_dir\$tool"
285
- if (($url | Split-Path -Extension) -eq ".exe") {
286
- $tool_path = "$tool_path.exe"
287
- }
288
- try {
289
- Invoke-WebRequest -Uri $url -OutFile $tool_path
290
- } catch {
291
- if($url -match '.*github.com.*releases.*latest.*') {
292
- try {
293
- $url = $url.replace("releases/latest/download", "releases/download/" + ([regex]::match((Invoke-WebRequest -Uri ($url.split('/release')[0] + "/releases")).Content, "([0-9]+\.[0-9]+\.[0-9]+)/" + ($url.Substring($url.LastIndexOf("/") + 1))).Groups[0].Value).split('/')[0])
294
- Invoke-WebRequest -Uri $url -OutFile $tool_path
295
- } catch { }
296
- }
297
- }
298
- if (((Get-ChildItem -Path $bin_dir/* | Where-Object Name -Match "^$tool(.exe|.phar)*$").Count -gt 0)) {
299
- $bat_content = @()
300
- $bat_content += "@ECHO off"
301
- $bat_content += "setlocal DISABLEDELAYEDEXPANSION"
302
- $bat_content += "SET BIN_TARGET=%~dp0/" + $tool
303
- $bat_content += "php %BIN_TARGET% %*"
304
- Set-Content -Path $bin_dir\$tool.bat -Value $bat_content
305
- Add-ToolsHelper $tool
306
- Add-ToProfile $current_profile $tool "New-Alias $tool $bin_dir\$tool.bat" >$null 2>&1
307
- $tool_version = Get-ToolVersion $tool $ver_param
308
- Add-Log $tick $tool "Added $tool $tool_version"
309
- } else {
310
- Add-Log $cross $tool "Could not add $tool"
311
- }
312
- }
313
-
314
- # Function to setup a tool using composer.
315
- Function Add-Composertool() {
316
- Param (
317
- [Parameter(Position = 0, Mandatory = $true)]
318
- [ValidateNotNull()]
319
- [ValidateLength(1, [int]::MaxValue)]
320
- [string]
321
- $tool,
322
- [Parameter(Position = 1, Mandatory = $true)]
323
- [ValidateNotNull()]
324
- [ValidateLength(1, [int]::MaxValue)]
325
- [string]
326
- $release,
327
- [Parameter(Position = 2, Mandatory = $true)]
328
- [ValidateNotNull()]
329
- [ValidateLength(1, [int]::MaxValue)]
330
- [string]
331
- $prefix
332
- )
333
- if($tool -match "prestissimo|composer-prefetcher" -and $composer_version.split('.')[0] -ne "1") {
334
- Write-Output "::warning:: Skipping $tool, as it does not support Composer $composer_version. Specify composer:v1 in tools to use $tool"
335
- Add-Log $cross $tool "Skipped"
336
- Return
337
- }
338
- if(Test-Path $composer_lock) {
339
- Remove-Item -Path $composer_lock -Force
340
- }
341
- (composer global require $prefix$release 2>&1 | Tee-Object -FilePath $env:APPDATA\Composer\composer.log) >$null 2>&1
342
- $json = findstr $prefix$tool $env:APPDATA\Composer\composer.json
343
- $log = findstr $prefix$tool $env:APPDATA\Composer\composer.log
344
- if(Test-Path $composer_bin\composer) {
345
- Copy-Item -Path "$bin_dir\composer" -Destination "$composer_bin\composer" -Force
346
- }
347
- Add-ToolsHelper $tool
348
- if($json) {
349
- $tool_version = Get-ToolVersion "Write-Output" "$log"
350
- Add-Log $tick $tool "Added $tool $tool_version"
351
- } else {
352
- Add-Log $cross $tool "Could not setup $tool"
353
- }
354
- }
355
-
356
- # Function to handle request to add PECL.
357
- Function Add-Pecl() {
358
- Add-Log $tick "PECL" "Use extensions input to setup PECL extensions on windows"
359
- }
360
-
361
- # Variables
362
- $tick = ([char]8730)
363
- $cross = ([char]10007)
364
- $php_dir = 'C:\tools\php'
365
- $ext_dir = "$php_dir\ext"
366
- $bin_dir = $php_dir
367
- $github = 'https://github.com'
368
- $php_builder = "$github/shivammathur/php-builder-windows"
369
- $composer_bin = "$env:APPDATA\Composer\vendor\bin"
370
- $composer_json = "$env:APPDATA\Composer\composer.json"
371
- $composer_lock = "$env:APPDATA\Composer\composer.lock"
372
- $current_profile = "$env:TEMP\setup-php.ps1"
373
- $ProgressPreference = 'SilentlyContinue'
374
- $jit_versions = '8.[0-9]'
375
- $nightly_versions = '8.[1-9]'
376
- $cert_source='CurrentUser'
377
- $enable_extensions = ('openssl', 'curl', 'mbstring')
378
-
379
- $arch = 'x64'
380
- if(-not([Environment]::Is64BitOperatingSystem) -or $version -lt '7.0') {
381
- $arch = 'x86'
382
- }
383
-
384
- $ts = $env:PHPTS -eq 'ts'
385
- if($env:PHPTS -ne 'ts') {
386
- $env:PHPTS = 'nts'
387
- }
388
- if($env:RUNNER -eq 'self-hosted') {
389
- $bin_dir = 'C:\tools\bin'
390
- $php_dir = "$php_dir$version"
391
- $ext_dir = "$php_dir\ext"
392
- $cert_source='Curl'
393
- Get-CleanPSProfile >$null 2>&1
394
- New-Item $bin_dir -Type Directory 2>&1 | Out-Null
395
- Add-Path -PathItem $bin_dir
396
- if($version -lt 5.6) {
397
- Add-Log $cross "PHP" "PHP $version is not supported on self-hosted runner"
398
- Start-Sleep 1
399
- exit 1
400
- }
401
- if ((Get-InstalledModule).Name -notcontains 'VcRedist') {
402
- Install-Module -Name VcRedist -Force
403
- }
404
- New-Item $php_dir -Type Directory 2>&1 | Out-Null
405
- Add-Path -PathItem $php_dir
406
- setx PHPROOT $php_dir >$null 2>&1
407
- } else {
408
- $current_profile = "$PSHOME\Profile.ps1"
409
- if(-not(Test-Path -LiteralPath $current_profile)) {
410
- New-Item -Path $current_profile -ItemType "file" -Force >$null 2>&1
411
- }
412
- }
413
-
414
- . $dist\..\src\scripts\tools\add_tools.ps1
415
-
416
- Add-Printf >$null 2>&1
417
- Step-Log "Setup PhpManager"
418
- Install-PSPackage PhpManager PhpManager\PhpManager "$github/mlocati/powershell-phpmanager/releases/latest/download/PhpManager.zip" Get-Php >$null 2>&1
419
- Add-Log $tick "PhpManager" "Installed"
420
-
421
- Step-Log "Setup PHP"
422
- $installed = $null
423
- if (Test-Path -LiteralPath $php_dir -PathType Container) {
424
- try {
425
- $installed = Get-Php -Path $php_dir
426
- } catch { }
427
- }
428
- $status = "Installed"
429
- $extra_version = ""
430
- if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version -replace '^(\d+(\.\d+)*).*', '$1.'))) -or $ts -ne $installed.ThreadSafe) {
431
- if ($version -lt '7.0' -and (Get-InstalledModule).Name -notcontains 'VcRedist') {
432
- Install-PSPackage VcRedist VcRedist-main\VcRedist\VcRedist "$github/aaronparker/VcRedist/archive/main.zip" Get-VcList >$null 2>&1
433
- }
434
- try {
435
- if ($version -match $nightly_versions) {
436
- Invoke-WebRequest -UseBasicParsing -Uri $php_builder/releases/latest/download/Get-PhpNightly.ps1 -OutFile $php_dir\Get-PhpNightly.ps1 > $null 2>&1
437
- & $php_dir\Get-PhpNightly.ps1 -Architecture $arch -ThreadSafe $ts -Path $php_dir > $null 2>&1
438
- $extra_version = " ($(Get-Content $php_dir\COMMIT))"
439
- } else {
440
- Install-Php -Version $version -Architecture $arch -ThreadSafe $ts -InstallVC -Path $php_dir -TimeZone UTC -InitialPhpIni Production -Force > $null 2>&1
441
- }
442
- } catch { }
443
- } else {
444
- if($version -match $jit_versions) {
445
- ('opcache.enable=1', 'opcache.jit_buffer_size=256M', 'opcache.jit=1235') | ForEach-Object { $p=$_.split('='); Set-PhpIniKey -Key $p[0] -Value $p[1] -Path $php_dir }
446
- }
447
- if($env:update -eq 'true') {
448
- Update-Php $php_dir >$null 2>&1
449
- $status = "Updated to"
450
- } else {
451
- $status = "Found"
452
- }
453
- }
454
-
455
- $installed = Get-Php -Path $php_dir
456
- if($installed.MajorMinorVersion -ne $version) {
457
- Add-Log $cross "PHP" "Could not setup PHP $version"
458
- exit 1
459
- }
460
- ('date.timezone=UTC', 'memory_limit=-1', 'xdebug.mode=coverage') | ForEach-Object { $p=$_.split('='); Set-PhpIniKey -Key $p[0] -Value $p[1] -Path $php_dir }
461
- if($version -lt "5.5") {
462
- ('libeay32.dll', 'ssleay32.dll') | ForEach-Object { Invoke-WebRequest -Uri "$php_builder/releases/download/openssl-1.0.2u/$_" -OutFile $php_dir\$_ >$null 2>&1 }
463
- } else {
464
- $enable_extensions += ('opcache')
465
- }
466
- Enable-PhpExtension -Extension $enable_extensions -Path $php_dir
467
- Update-PhpCAInfo -Path $php_dir -Source $cert_source
468
- Copy-Item -Path $dist\..\src\configs\*.json -Destination $env:RUNNER_TOOL_CACHE
469
- New-Item -ItemType Directory -Path $composer_bin -Force 2>&1 | Out-Null
470
- Write-Output "::set-output name=php-version::$($installed.FullVersion)"
471
- Add-Log $tick "PHP" "$status PHP $($installed.FullVersion)$extra_version"
1
+ param (
2
+ [Parameter(Position = 0, Mandatory = $true)]
3
+ [ValidateNotNull()]
4
+ [ValidateLength(1, [int]::MaxValue)]
5
+ [string]
6
+ $version = '8.1',
7
+ [Parameter(Position = 1, Mandatory = $true)]
8
+ [ValidateNotNull()]
9
+ [ValidateLength(1, [int]::MaxValue)]
10
+ [string]
11
+ $dist
12
+ )
13
+
14
+ # Function to log start of a operation.
15
+ Function Step-Log($message) {
16
+ printf "\n\033[90;1m==> \033[0m\033[37;1m%s \033[0m\n" $message
17
+ }
18
+
19
+ # Function to log result of a operation.
20
+ Function Add-Log($mark, $subject, $message) {
21
+ if ($mark -eq $tick) {
22
+ printf "\033[32;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" $mark $subject $message
23
+ } else {
24
+ printf "\033[31;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" $mark $subject $message
25
+ if($env:fail_fast -eq 'true') {
26
+ exit 1;
27
+ }
28
+ }
29
+ }
30
+
31
+ # Function to add a line to a powershell profile safely.
32
+ Function Add-ToProfile {
33
+ param(
34
+ [Parameter(Position = 0, Mandatory = $true)]
35
+ [ValidateNotNull()]
36
+ [ValidateLength(1, [int]::MaxValue)]
37
+ [string]
38
+ $input_profile,
39
+ [Parameter(Position = 1, Mandatory = $true)]
40
+ [ValidateNotNull()]
41
+ [ValidateLength(1, [int]::MaxValue)]
42
+ [string]
43
+ $search,
44
+ [Parameter(Position = 2, Mandatory = $true)]
45
+ [ValidateNotNull()]
46
+ [ValidateLength(1, [int]::MaxValue)]
47
+ [string]
48
+ $value
49
+ )
50
+ if($null -eq (Get-Content $input_profile | findstr $search)) {
51
+ Add-Content -Path $input_profile -Value $value
52
+ }
53
+ }
54
+
55
+ # Function to fetch PATH from the registry.
56
+ Function Get-PathFromRegistry {
57
+ $env:Path = [System.Environment]::GetEnvironmentVariable("Path","User") + ";" +
58
+ [System.Environment]::GetEnvironmentVariable("Path","Machine")
59
+ Add-ToProfile $current_profile 'Get-PathFromRegistry' 'Function Get-PathFromRegistry { $env:Path = [System.Environment]::GetEnvironmentVariable("Path", "User") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "Machine") }; Get-PathFromRegistry'
60
+ }
61
+
62
+ # Function to add a location to PATH.
63
+ Function Add-Path {
64
+ param(
65
+ [string]$PathItem
66
+ )
67
+ $newPath = (Get-ItemProperty -Path 'hkcu:\Environment' -Name PATH).Path.replace("$PathItem;", '')
68
+ $newPath = $PathItem + ';' + $newPath
69
+ Set-ItemProperty -Path 'hkcu:\Environment' -Name Path -Value $newPath
70
+ Get-PathFromRegistry
71
+ }
72
+
73
+ # Function to make sure printf is in PATH.
74
+ Function Add-Printf {
75
+ if (-not(Test-Path "C:\Program Files\Git\usr\bin\printf.exe")) {
76
+ if(Test-Path "C:\msys64\usr\bin\printf.exe") {
77
+ New-Item -Path $bin_dir\printf.exe -ItemType SymbolicLink -Value C:\msys64\usr\bin\printf.exe -Force > $null 2>&1
78
+ } else {
79
+ Invoke-WebRequest -Uri "$github/shivammathur/printf/releases/latest/download/printf-x64.zip" -OutFile "$bin_dir\printf.zip"
80
+ Expand-Archive -Path $bin_dir\printf.zip -DestinationPath $bin_dir -Force
81
+ }
82
+ } else {
83
+ New-Item -Path $bin_dir\printf.exe -ItemType SymbolicLink -Value "C:\Program Files\Git\usr\bin\printf.exe" -Force > $null 2>&1
84
+ }
85
+ }
86
+
87
+ # Function to get a clean Powershell profile.
88
+ Function Get-CleanPSProfile {
89
+ if(-not(Test-Path -LiteralPath $profile)) {
90
+ New-Item -Path $profile -ItemType "file" -Force > $null 2>&1
91
+ }
92
+ Set-Content $current_profile -Value ''
93
+ Add-ToProfile $profile $current_profile.replace('\', '\\') ". $current_profile"
94
+ }
95
+
96
+ # Function to install a powershell package from GitHub.
97
+ Function Install-PSPackage() {
98
+ param(
99
+ [Parameter(Position = 0, Mandatory = $true)]
100
+ $package,
101
+ [Parameter(Position = 1, Mandatory = $true)]
102
+ $psm1_path,
103
+ [Parameter(Position = 2, Mandatory = $true)]
104
+ $url,
105
+ [Parameter(Position = 3, Mandatory = $true)]
106
+ $cmdlet
107
+ )
108
+ $module_path = "$bin_dir\$psm1_path.psm1"
109
+ if(-not (Test-Path $module_path -PathType Leaf)) {
110
+ $zip_file = "$bin_dir\$package.zip"
111
+ Invoke-WebRequest -Uri $url -OutFile $zip_file
112
+ Expand-Archive -Path $zip_file -DestinationPath $bin_dir -Force
113
+ }
114
+ Import-Module $module_path
115
+ Add-ToProfile $current_profile "$package-search" "Import-Module $module_path"
116
+
117
+ if($null -eq (Get-Command $cmdlet -ErrorAction SilentlyContinue)) {
118
+ Install-Module -Name $cmdlet -Force
119
+ }
120
+ }
121
+
122
+ # Function to link dependencies to PHP directory.
123
+ Function Set-ExtensionPrerequisites
124
+ {
125
+ Param (
126
+ [Parameter(Position = 0, Mandatory = $true)]
127
+ [ValidateNotNull()]
128
+ [ValidateLength(1, [int]::MaxValue)]
129
+ [string]
130
+ $deps_dir
131
+ )
132
+ $deps = Get-ChildItem -Recurse -Path $deps_dir
133
+ if ($deps.Count -ne 0) {
134
+ # Symlink dependencies instead of adding the directory to PATH ...
135
+ # as other actions change the PATH thus breaking extensions.
136
+ $deps | ForEach-Object {
137
+ New-Item -Itemtype SymbolicLink -Path $php_dir -Name $_.Name -Target $_.FullName -Force > $null 2>&1
138
+ }
139
+ } else {
140
+ Remove-Item $deps_dir -Recurse -Force
141
+ }
142
+ }
143
+
144
+ # Function to add CA certificates to PHP.
145
+ Function Add-PhpCAInfo {
146
+ try {
147
+ Update-PhpCAInfo -Path $php_dir -Source Curl
148
+ } catch {
149
+ Add-Log $cross PHP "Could not fetch CA certificate bundle from Curl"
150
+ Update-PhpCAInfo -Path $php_dir -Source CurrentUser
151
+ }
152
+ }
153
+
154
+ # Function to add PHP extensions.
155
+ Function Add-Extension {
156
+ Param (
157
+ [Parameter(Position = 0, Mandatory = $true)]
158
+ [ValidateNotNull()]
159
+ [ValidateLength(1, [int]::MaxValue)]
160
+ [string]
161
+ $extension,
162
+ [Parameter(Position = 1, Mandatory = $false)]
163
+ [ValidateNotNull()]
164
+ [ValidateSet('stable', 'beta', 'alpha', 'devel', 'snapshot')]
165
+ [string]
166
+ $stability = 'stable',
167
+ [Parameter(Position = 2, Mandatory = $false)]
168
+ [ValidateNotNull()]
169
+ [ValidatePattern('^\d+(\.\d+){0,2}$')]
170
+ [string]
171
+ $extension_version = ''
172
+ )
173
+ try {
174
+ $extension_info = Get-PhpExtension -Path $php_dir | Where-Object { $_.Name -eq $extension -or $_.Handle -eq $extension }
175
+ $deps_dir = "$ext_dir\$extension-vc$($installed.VCVersion)-$arch"
176
+ New-Item $deps_dir -Type Directory -Force > $null 2>&1
177
+ if ($null -ne $extension_info) {
178
+ switch ($extension_info.State) {
179
+ 'Builtin' {
180
+ Add-Log $tick $extension "Enabled"
181
+ }
182
+ 'Enabled' {
183
+ Add-Log $tick $extension "Enabled"
184
+ }
185
+ default {
186
+ Enable-ExtensionDependencies $extension
187
+ Enable-PhpExtension -Extension $extension_info.Handle -Path $php_dir
188
+ Set-ExtensionPrerequisites $deps_dir
189
+ Add-Log $tick $extension "Enabled"
190
+ }
191
+ }
192
+ }
193
+ else {
194
+ $params = @{ Extension = $extension; MinimumStability = $stability; MaximumStability = $stability; Path = $php_dir; AdditionalFilesPath = $deps_dir; NoDependencies = $true }
195
+ if($extension_version -ne '') {
196
+ $params["Version"] = $extension_version
197
+ }
198
+ Install-PhpExtension @params
199
+ Set-ExtensionPrerequisites $deps_dir
200
+ Add-Log $tick $extension "Installed and enabled"
201
+ }
202
+ }
203
+ catch {
204
+ Add-Log $cross $extension "Could not install $extension on PHP $($installed.FullVersion)"
205
+ }
206
+ }
207
+
208
+ # Function to get a map of extensions and their dependent shared extensions.
209
+ Function Get-ExtensionMap {
210
+ php -d'error_reporting=0' $dist\..\src\scripts\ext\extension_map.php
211
+ }
212
+
213
+ # Function to enable extension dependencies which are also extensions.
214
+ Function Enable-ExtensionDependencies {
215
+ Param (
216
+ [Parameter(Position = 0, Mandatory = $true)]
217
+ [ValidateNotNull()]
218
+ [ValidateLength(1, [int]::MaxValue)]
219
+ [string]
220
+ $extension
221
+ )
222
+ if (-not(Test-Path $env:TEMP\map.orig)) {
223
+ Get-ExtensionMap | Set-Content -Path $env:TEMP\map.orig
224
+ }
225
+ $entry = findstr /r "$extension`:.*" $env:TEMP\map.orig
226
+ if($entry) {
227
+ $entry.split(':')[1].trim().split(' ') | ForEach-Object {
228
+ if (-not(php -m | findstr -i $_)) {
229
+ Enable-PhpExtension -Extension $_ -Path $php_dir
230
+ }
231
+ }
232
+ }
233
+ }
234
+
235
+ # Function to disable dependent extensions.
236
+ Function Disable-DependentExtensions() {
237
+ Param (
238
+ [Parameter(Position = 0, Mandatory = $true)]
239
+ [ValidateNotNull()]
240
+ [ValidateLength(1, [int]::MaxValue)]
241
+ [string]
242
+ $extension
243
+ )
244
+ Get-ExtensionMap | Select-String -Pattern ".*:.*\s$extension(\s|$)" | ForEach-Object {
245
+ $dependent = $_.Matches[0].Value.split(':')[0];
246
+ Disable-ExtensionHelper -Extension $dependent -DisableDependents
247
+ Add-Log $tick ":$extension" "Disabled $dependent as it depends on $extension"
248
+ }
249
+ }
250
+
251
+ # Helper function to disable an extension.
252
+ Function Disable-ExtensionHelper() {
253
+ Param (
254
+ [Parameter(Position = 0, Mandatory = $true)]
255
+ [ValidateNotNull()]
256
+ [ValidateLength(1, [int]::MaxValue)]
257
+ [string]
258
+ $extension,
259
+ [switch] $DisableDependents
260
+ )
261
+ if($DisableDependents) {
262
+ Disable-DependentExtensions $extension
263
+ }
264
+ Disable-PhpExtension -Extension $extension -Path $php_dir
265
+ }
266
+
267
+ # Function to disable an extension.
268
+ Function Disable-Extension() {
269
+ Param (
270
+ [Parameter(Position = 0, Mandatory = $true)]
271
+ [ValidateNotNull()]
272
+ [ValidateLength(1, [int]::MaxValue)]
273
+ [string]
274
+ $extension,
275
+ [Parameter(Position = 1, Mandatory = $false)]
276
+ [ValidateNotNull()]
277
+ [ValidateLength(1, [int]::MaxValue)]
278
+ [string]
279
+ $DisableDependents
280
+ )
281
+ if(php -m | findstr -i $extension) {
282
+ if(Test-Path $ext_dir\php_$extension.dll) {
283
+ try {
284
+ $params = @{ Extension = $extension; DisableDependents = ($DisableDependents -ne 'false') }
285
+ Disable-ExtensionHelper @params
286
+ Add-Log $tick ":$extension" "Disabled"
287
+ } catch {
288
+ Add-Log $cross ":$extension" "Could not disable $extension on PHP $($installed.FullVersion)"
289
+ }
290
+ } else {
291
+ Add-Log $cross ":$extension" "Could not disable $extension on PHP $($installed.FullVersion) as it not a shared extension"
292
+ }
293
+ } elseif(Test-Path $ext_dir\php_$extension.dll) {
294
+ Add-Log $tick ":$extension" "Disabled"
295
+ } else {
296
+ Add-Log $tick ":$extension" "Could not find $extension on PHP $($installed.FullVersion)"
297
+ }
298
+ }
299
+
300
+ # Function to disable shared extensions.
301
+ Function Disable-AllShared() {
302
+ (Get-Content $php_dir\php.ini) | Where-Object {$_ -notmatch '^(zend_)?extension\s*='} | Set-Content $php_dir\php.ini
303
+ Add-Log $tick "none" "Disabled all shared extensions"
304
+ }
305
+
306
+ # Function to configure composer.
307
+ Function Edit-ComposerConfig() {
308
+ Param(
309
+ [Parameter(Position = 0, Mandatory = $true)]
310
+ [ValidateNotNull()]
311
+ [ValidateLength(1, [int]::MaxValue)]
312
+ [string]
313
+ $tool_path
314
+ )
315
+ Copy-Item $tool_path -Destination "$tool_path.phar"
316
+ php -r "try {`$p=new Phar('$tool_path.phar', 0);exit(0);} catch(Exception `$e) {exit(1);}"
317
+ if ($? -eq $False) {
318
+ Add-Log "$cross" "composer" "Could not download composer"
319
+ exit 1;
320
+ }
321
+ if (-not(Test-Path $composer_json)) {
322
+ Set-Content -Path $composer_json -Value "{}"
323
+ }
324
+ composer -q config -g process-timeout 0
325
+ Write-Output $composer_bin | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8
326
+ if (Test-Path env:COMPOSER_TOKEN) {
327
+ composer -q config -g github-oauth.github.com $env:COMPOSER_TOKEN
328
+ }
329
+ }
330
+
331
+ # Function to extract tool version.
332
+ Function Get-ToolVersion() {
333
+ Param (
334
+ [Parameter(Position = 0, Mandatory = $true)]
335
+ $tool,
336
+ [Parameter(Position = 1, Mandatory = $true)]
337
+ $param
338
+ )
339
+ $alp = "[a-zA-Z0-9]"
340
+ $version_regex = "[0-9]+((\.{1}$alp+)+)(\.{0})(-$alp+){0,1}"
341
+ if($tool -eq 'composer') {
342
+ if ($param -eq 'snapshot') {
343
+ $composer_version = (Select-String -Pattern "const\sBRANCH_ALIAS_VERSION" -Path $bin_dir\composer -Raw | Select-String -Pattern $version_regex | ForEach-Object { $_.matches.Value }) + '+' + (Select-String -Pattern "const\sVERSION" -Path $bin_dir\composer -Raw | Select-String -Pattern "[a-zA-Z0-9]+" -AllMatches | ForEach-Object { $_.matches[2].Value })
344
+ } else {
345
+ $composer_version = Select-String -Pattern "const\sVERSION" -Path $bin_dir\composer -Raw | Select-String -Pattern $version_regex | ForEach-Object { $_.matches.Value }
346
+ }
347
+ Set-Variable -Name 'composer_version' -Value $composer_version -Scope Global
348
+ return "$composer_version"
349
+ }
350
+ return . $tool $param 2> $null | ForEach-Object { $_ -replace "composer $version_regex", '' } | Select-String -Pattern $version_regex | Select-Object -First 1 | ForEach-Object { $_.matches.Value }
351
+ }
352
+
353
+ # Function to add tools.
354
+ Function Add-Tool() {
355
+ Param (
356
+ [Parameter(Position = 0, Mandatory = $true)]
357
+ [ValidateNotNull()]
358
+ $url,
359
+ [Parameter(Position = 1, Mandatory = $true)]
360
+ [ValidateNotNull()]
361
+ $tool,
362
+ [Parameter(Position = 2, Mandatory = $true)]
363
+ [ValidateNotNull()]
364
+ $ver_param
365
+ )
366
+ if (Test-Path $bin_dir\$tool) {
367
+ Remove-Item $bin_dir\$tool
368
+ }
369
+ if($url.Count -gt 1) {
370
+ $url = $url[0]
371
+ }
372
+ $tool_path = "$bin_dir\$tool"
373
+ if (($url | Split-Path -Extension) -eq ".exe") {
374
+ $tool_path = "$tool_path.exe"
375
+ }
376
+ try {
377
+ Invoke-WebRequest -Uri $url -OutFile $tool_path
378
+ } catch {
379
+ if($url -match '.*github.com.*releases.*latest.*') {
380
+ try {
381
+ $url = $url.replace("releases/latest/download", "releases/download/" + ([regex]::match((Invoke-WebRequest -Uri ($url.split('/release')[0] + "/releases")).Content, "([0-9]+\.[0-9]+\.[0-9]+)/" + ($url.Substring($url.LastIndexOf("/") + 1))).Groups[0].Value).split('/')[0])
382
+ Invoke-WebRequest -Uri $url -OutFile $tool_path
383
+ } catch { }
384
+ }
385
+ }
386
+ if (((Get-ChildItem -Path $bin_dir/* | Where-Object Name -Match "^$tool(.exe|.phar)*$").Count -gt 0)) {
387
+ $bat_content = @()
388
+ $bat_content += "@ECHO off"
389
+ $bat_content += "setlocal DISABLEDELAYEDEXPANSION"
390
+ $bat_content += "SET BIN_TARGET=%~dp0/" + $tool
391
+ $bat_content += "php %BIN_TARGET% %*"
392
+ Set-Content -Path $bin_dir\$tool.bat -Value $bat_content
393
+ Add-ToolsHelper $tool
394
+ Add-ToProfile $current_profile $tool "New-Alias $tool $bin_dir\$tool.bat" >$null 2>&1
395
+ $tool_version = Get-ToolVersion $tool $ver_param
396
+ Add-Log $tick $tool "Added $tool $tool_version"
397
+ } else {
398
+ Add-Log $cross $tool "Could not add $tool"
399
+ }
400
+ }
401
+
402
+ # Function to setup a tool using composer.
403
+ Function Add-Composertool() {
404
+ Param (
405
+ [Parameter(Position = 0, Mandatory = $true)]
406
+ [ValidateNotNull()]
407
+ [ValidateLength(1, [int]::MaxValue)]
408
+ [string]
409
+ $tool,
410
+ [Parameter(Position = 1, Mandatory = $true)]
411
+ [ValidateNotNull()]
412
+ [ValidateLength(1, [int]::MaxValue)]
413
+ [string]
414
+ $release,
415
+ [Parameter(Position = 2, Mandatory = $true)]
416
+ [ValidateNotNull()]
417
+ [ValidateLength(1, [int]::MaxValue)]
418
+ [string]
419
+ $prefix
420
+ )
421
+ if($tool -match "prestissimo|composer-prefetcher" -and $composer_version.split('.')[0] -ne "1") {
422
+ Write-Output "::warning:: Skipping $tool, as it does not support Composer $composer_version. Specify composer:v1 in tools to use $tool"
423
+ Add-Log $cross $tool "Skipped"
424
+ Return
425
+ }
426
+ if(Test-Path $composer_lock) {
427
+ Remove-Item -Path $composer_lock -Force
428
+ }
429
+ (composer global require $prefix$release 2>&1 | Tee-Object -FilePath $env:APPDATA\Composer\composer.log) >$null 2>&1
430
+ $json = findstr $prefix$tool $env:APPDATA\Composer\composer.json
431
+ $log = findstr $prefix$tool $env:APPDATA\Composer\composer.log
432
+ if(Test-Path $composer_bin\composer) {
433
+ Copy-Item -Path "$bin_dir\composer" -Destination "$composer_bin\composer" -Force
434
+ }
435
+ Add-ToolsHelper $tool
436
+ if($json) {
437
+ $tool_version = Get-ToolVersion "Write-Output" "$log"
438
+ Add-Log $tick $tool "Added $tool $tool_version"
439
+ } else {
440
+ Add-Log $cross $tool "Could not setup $tool"
441
+ }
442
+ }
443
+
444
+ # Function to handle request to add PECL.
445
+ Function Add-Pecl() {
446
+ Add-Log $tick "PECL" "Use extensions input to setup PECL extensions on windows"
447
+ }
448
+
449
+ # Variables
450
+ $tick = ([char]8730)
451
+ $cross = ([char]10007)
452
+ $php_dir = 'C:\tools\php'
453
+ $ext_dir = "$php_dir\ext"
454
+ $bin_dir = $php_dir
455
+ $github = 'https://github.com'
456
+ $php_builder = "$github/shivammathur/php-builder-windows"
457
+ $composer_bin = "$env:APPDATA\Composer\vendor\bin"
458
+ $composer_json = "$env:APPDATA\Composer\composer.json"
459
+ $composer_lock = "$env:APPDATA\Composer\composer.lock"
460
+ $current_profile = "$env:TEMP\setup-php.ps1"
461
+ $ProgressPreference = 'SilentlyContinue'
462
+ $jit_versions = '8.[0-9]'
463
+ $nightly_versions = '8.[1-9]'
464
+ $enable_extensions = ('openssl', 'curl', 'mbstring')
465
+
466
+ $arch = 'x64'
467
+ if(-not([Environment]::Is64BitOperatingSystem) -or $version -lt '7.0') {
468
+ $arch = 'x86'
469
+ }
470
+
471
+ $ts = $env:PHPTS -eq 'ts'
472
+ if($env:PHPTS -ne 'ts') {
473
+ $env:PHPTS = 'nts'
474
+ }
475
+ if($env:RUNNER -eq 'self-hosted') {
476
+ $bin_dir = 'C:\tools\bin'
477
+ $php_dir = "$php_dir$version"
478
+ $ext_dir = "$php_dir\ext"
479
+ Get-CleanPSProfile >$null 2>&1
480
+ New-Item $bin_dir -Type Directory -Force > $null 2>&1
481
+ Add-Path -PathItem $bin_dir
482
+ if($version -lt 5.6) {
483
+ Add-Log $cross "PHP" "PHP $version is not supported on self-hosted runner"
484
+ Start-Sleep 1
485
+ exit 1
486
+ }
487
+ if ((Get-InstalledModule).Name -notcontains 'VcRedist') {
488
+ Install-Module -Name VcRedist -Force
489
+ }
490
+ New-Item $php_dir -Type Directory -Force > $null 2>&1
491
+ Add-Path -PathItem $php_dir
492
+ setx PHPROOT $php_dir >$null 2>&1
493
+ } else {
494
+ $current_profile = "$PSHOME\Profile.ps1"
495
+ if(-not(Test-Path -LiteralPath $current_profile)) {
496
+ New-Item -Path $current_profile -ItemType "file" -Force >$null 2>&1
497
+ }
498
+ }
499
+
500
+ . $dist\..\src\scripts\tools\add_tools.ps1
501
+
502
+ Add-Printf >$null 2>&1
503
+ Step-Log "Setup PhpManager"
504
+ Install-PSPackage PhpManager PhpManager\PhpManager "$github/mlocati/powershell-phpmanager/releases/latest/download/PhpManager.zip" Get-Php >$null 2>&1
505
+ Add-Log $tick "PhpManager" "Installed"
506
+
507
+ Step-Log "Setup PHP"
508
+ $installed = $null
509
+ if (Test-Path -LiteralPath $php_dir -PathType Container) {
510
+ try {
511
+ if(Test-Path $php_dir\php.ini) {
512
+ Rename-Item -Path $php_dir\php.ini -NewName 'php.ini.bak'
513
+ }
514
+ $installed = Get-Php -Path $php_dir -ErrorAction SilentlyContinue 2>$null 3>$null
515
+ if(Test-Path $php_dir\php.ini.bak) {
516
+ Rename-Item -Path $php_dir\php.ini.bak -NewName 'php.ini'
517
+ }
518
+ } catch { }
519
+ }
520
+ $status = "Installed"
521
+ $extra_version = ""
522
+ if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version -replace '^(\d+(\.\d+)*).*', '$1.'))) -or $ts -ne $installed.ThreadSafe) {
523
+ if ($version -lt '7.0' -and (Get-InstalledModule).Name -notcontains 'VcRedist') {
524
+ Install-PSPackage VcRedist VcRedist-main\VcRedist\VcRedist "$github/aaronparker/VcRedist/archive/main.zip" Get-VcList >$null 2>&1
525
+ }
526
+ try {
527
+ if ($version -match $nightly_versions) {
528
+ Invoke-WebRequest -UseBasicParsing -Uri $php_builder/releases/latest/download/Get-PhpNightly.ps1 -OutFile $php_dir\Get-PhpNightly.ps1 > $null 2>&1
529
+ & $php_dir\Get-PhpNightly.ps1 -Architecture $arch -ThreadSafe $ts -Path $php_dir -Version $version > $null 2>&1
530
+ if(Test-Path $php_dir\COMMIT) {
531
+ $extra_version = " ($( Get-Content $php_dir\COMMIT ))"
532
+ }
533
+ } else {
534
+ Install-Php -Version $version -Architecture $arch -ThreadSafe $ts -InstallVC -Path $php_dir -TimeZone UTC -InitialPhpIni Production -Force > $null 2>&1
535
+ }
536
+ } catch { }
537
+ } else {
538
+ Set-PhpIniKey -Key 'extension_dir' -Value $ext_dir -Path $php_dir
539
+ if($version -match $jit_versions) {
540
+ ('opcache.enable=1', 'opcache.jit_buffer_size=256M', 'opcache.jit=1235') | ForEach-Object { $p=$_.split('='); Set-PhpIniKey -Key $p[0] -Value $p[1] -Path $php_dir }
541
+ }
542
+ if($env:update -eq 'true') {
543
+ Update-Php $php_dir >$null 2>&1
544
+ $status = "Updated to"
545
+ } else {
546
+ $status = "Found"
547
+ }
548
+ }
549
+
550
+ $installed = Get-Php -Path $php_dir
551
+ if($installed.MajorMinorVersion -ne $version) {
552
+ Add-Log $cross "PHP" "Could not setup PHP $version"
553
+ exit 1
554
+ }
555
+ ('date.timezone=UTC', 'memory_limit=-1', 'xdebug.mode=coverage') | ForEach-Object { $p=$_.split('='); Set-PhpIniKey -Key $p[0] -Value $p[1] -Path $php_dir }
556
+ if($version -lt "5.5") {
557
+ ('libeay32.dll', 'ssleay32.dll') | ForEach-Object { Invoke-WebRequest -Uri "$php_builder/releases/download/openssl-1.0.2u/$_" -OutFile $php_dir\$_ >$null 2>&1 }
558
+ } else {
559
+ $enable_extensions += ('opcache')
560
+ }
561
+ Enable-PhpExtension -Extension $enable_extensions -Path $php_dir
562
+ Add-PhpCAInfo
563
+ Copy-Item -Path $dist\..\src\configs\pm\*.json -Destination $env:RUNNER_TOOL_CACHE
564
+ New-Item -ItemType Directory -Path $composer_bin -Force > $null 2>&1
565
+ Write-Output "::set-output name=php-version::$($installed.FullVersion)"
566
+ Add-Log $tick "PHP" "$status PHP $($installed.FullVersion)$extra_version"