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