setup-php 2.15.0 → 2.17.1

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 (86) hide show
  1. package/README.md +157 -143
  2. package/lib/config.d.ts +3 -3
  3. package/lib/config.js +71 -71
  4. package/lib/config.js.map +1 -1
  5. package/lib/coverage.d.ts +5 -4
  6. package/lib/coverage.js +97 -87
  7. package/lib/coverage.js.map +1 -1
  8. package/lib/extensions.d.ts +4 -4
  9. package/lib/extensions.js +214 -210
  10. package/lib/extensions.js.map +1 -1
  11. package/lib/fetch.d.ts +1 -0
  12. package/lib/fetch.js +63 -0
  13. package/lib/fetch.js.map +1 -0
  14. package/lib/install.d.ts +2 -2
  15. package/lib/install.js +75 -80
  16. package/lib/install.js.map +1 -1
  17. package/lib/tools.d.ts +23 -24
  18. package/lib/tools.js +373 -386
  19. package/lib/tools.js.map +1 -1
  20. package/lib/utils.d.ts +21 -23
  21. package/lib/utils.js +261 -293
  22. package/lib/utils.js.map +1 -1
  23. package/package.json +21 -20
  24. package/src/config.ts +8 -8
  25. package/src/configs/brew_extensions +2 -0
  26. package/src/configs/composer.env +2 -0
  27. package/src/configs/ini/jit.ini +3 -0
  28. package/src/configs/ini/php.ini +2 -0
  29. package/src/configs/ini/xdebug.ini +1 -0
  30. package/src/configs/os_releases.csv +2 -0
  31. package/src/configs/php-versions.json +2 -2
  32. package/src/configs/php_packages +12 -0
  33. package/src/configs/{php.json → pm/php.json} +0 -0
  34. package/src/configs/{phpunit.json → pm/phpunit.json} +24 -24
  35. package/src/configs/tools.json +48 -26
  36. package/src/configs/tools_schema.json +11 -0
  37. package/src/coverage.ts +47 -55
  38. package/src/extensions.ts +23 -19
  39. package/src/fetch.ts +54 -0
  40. package/src/install.ts +27 -40
  41. package/src/scripts/darwin.sh +72 -39
  42. package/src/scripts/extensions/add_extensions.ps1 +194 -0
  43. package/src/scripts/extensions/add_extensions.sh +184 -0
  44. package/src/scripts/{ext → extensions}/blackfire.ps1 +0 -0
  45. package/src/scripts/{ext → extensions}/blackfire.sh +0 -0
  46. package/src/scripts/{ext → extensions}/couchbase.sh +0 -0
  47. package/src/scripts/{ext → extensions}/cubrid.sh +3 -3
  48. package/src/scripts/{ext → extensions}/extension_map.php +36 -13
  49. package/src/scripts/{ext → extensions}/firebird.ps1 +0 -0
  50. package/src/scripts/{ext → extensions}/firebird.sh +0 -0
  51. package/src/scripts/{ext → extensions}/gearman.sh +0 -0
  52. package/src/scripts/{ext → extensions}/geos.sh +0 -0
  53. package/src/scripts/{ext → extensions}/http.ps1 +0 -0
  54. package/src/scripts/{ext → extensions}/http.sh +4 -15
  55. package/src/scripts/{ext → extensions}/intl.sh +0 -0
  56. package/src/scripts/{ext → extensions}/ioncube.ps1 +2 -2
  57. package/src/scripts/{ext → extensions}/ioncube.sh +2 -2
  58. package/src/scripts/{ext → extensions}/oci.ps1 +39 -14
  59. package/src/scripts/{ext → extensions}/oci.sh +3 -3
  60. package/src/scripts/{ext → extensions}/patches/firebird.sh +0 -0
  61. package/src/scripts/{ext → extensions}/patches/geos.sh +0 -0
  62. package/src/scripts/{ext → extensions}/patches/http.sh +0 -0
  63. package/src/scripts/{ext → extensions}/patches/pdo_oci.sh +0 -0
  64. package/src/scripts/{ext → extensions}/patches/phpize.sh +0 -0
  65. package/src/scripts/{ext → extensions}/patches/protobuf.sh +0 -0
  66. package/src/scripts/{ext → extensions}/phalcon.ps1 +0 -0
  67. package/src/scripts/{ext → extensions}/phalcon.sh +4 -5
  68. package/src/scripts/{ext → extensions}/source.sh +23 -22
  69. package/src/scripts/extensions/sqlsrv.sh +15 -0
  70. package/src/scripts/linux.sh +71 -40
  71. package/src/scripts/tools/add_tools.ps1 +220 -10
  72. package/src/scripts/tools/add_tools.sh +166 -15
  73. package/src/scripts/tools/blackfire.sh +2 -1
  74. package/src/scripts/tools/grpc_php_plugin.ps1 +4 -4
  75. package/src/scripts/tools/grpc_php_plugin.sh +3 -3
  76. package/src/scripts/tools/ppa.sh +12 -9
  77. package/src/scripts/tools/protoc.ps1 +2 -2
  78. package/src/scripts/tools/protoc.sh +2 -2
  79. package/src/scripts/tools/symfony.ps1 +18 -0
  80. package/src/scripts/tools/symfony.sh +18 -0
  81. package/src/scripts/unix.sh +186 -0
  82. package/src/scripts/win32.ps1 +145 -356
  83. package/src/tools.ts +62 -82
  84. package/src/utils.ts +57 -145
  85. package/lib/sapi.js +0 -64
  86. package/src/scripts/common.sh +0 -366
@@ -1,10 +1,10 @@
1
1
  # Function to log result of a operation.
2
2
  add_license_log() {
3
- printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "$ext" "Click to read the $ext related license information"
3
+ printf "$GROUP\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "$ext" "Click to read the $ext related license information"
4
4
  printf "Oracle Instant Client package is required for %s extension.\n" "$ext"
5
5
  printf "It is provided under the Oracle Technology Network Development and Distribution License.\n"
6
6
  printf "Refer to: \033[35;1m%s \033[0m\n" "https://www.oracle.com/downloads/licenses/instant-client-lic.html"
7
- echo "::endgroup::"
7
+ echo "$END_GROUP"
8
8
  }
9
9
 
10
10
  # Function to install instantclient and SDK.
@@ -62,4 +62,4 @@ add_oci() {
62
62
  }
63
63
 
64
64
  # shellcheck source=.
65
- . "${scripts:?}"/ext/patches/phpize.sh
65
+ . "${scripts:?}"/extensions/patches/phpize.sh
File without changes
File without changes
File without changes
@@ -4,11 +4,10 @@ add_phalcon_helper() {
4
4
  if [ "$(uname -s)" = "Darwin" ]; then
5
5
  add_brew_extension "$extension" extension
6
6
  else
7
- if [ "$extension" = "phalcon4" ]; then
8
- install_packages "php${version:?}-psr" "php${version:?}-$extension"
9
- else
10
- install_packages "php${version:?}-$extension"
11
- fi
7
+ packages=("php${version:?}-$extension")
8
+ [ "$extension" = "phalcon4" ] && packages+=("php${version:?}-psr")
9
+ add_ppa ondrej/php >/dev/null 2>&1 || update_ppa ondrej/php
10
+ check_package "${packages[0]}" && install_packages "${packages[@]}"
12
11
  fi
13
12
  }
14
13
 
@@ -1,6 +1,6 @@
1
1
  # Function to parse extension environment variables
2
2
  parse_args() {
3
- extension=$1
3
+ local extension=$1
4
4
  suffix=$(echo "$2" | tr '[:lower:]' '[:upper:]')
5
5
  up_ext_name=$(echo "$extension" | tr '[:lower:]' '[:upper:]')
6
6
  var="${extension}_${suffix}"
@@ -12,7 +12,7 @@ parse_args() {
12
12
 
13
13
  # Function to log if a library is installed
14
14
  add_lib_log() {
15
- lib=$1
15
+ local lib=$1
16
16
  if check_lib "$lib"; then
17
17
  add_log "${tick:?}" "$lib" "Installed"
18
18
  else
@@ -22,7 +22,7 @@ add_lib_log() {
22
22
 
23
23
  # Function to check if a library is installed
24
24
  check_lib() {
25
- lib=$1
25
+ local lib=$1
26
26
  if [ "$(uname -s)" = "Linux" ]; then
27
27
  [ "x$(dpkg -s "$lib" 2>/dev/null | grep Status)" != "x" ]
28
28
  else
@@ -32,7 +32,7 @@ check_lib() {
32
32
 
33
33
  # Function to add a library on linux
34
34
  add_linux_libs() {
35
- lib=$1
35
+ local lib=$1
36
36
  if ! check_lib "$lib"; then
37
37
  install_packages "$lib" >/dev/null 2>&1 || true
38
38
  fi
@@ -41,7 +41,7 @@ add_linux_libs() {
41
41
 
42
42
  # Function to add a library on macOS
43
43
  add_darwin_libs() {
44
- lib=$1
44
+ local lib=$1
45
45
  if ! check_lib "$lib"; then
46
46
  brew install "$lib" >/dev/null 2>&1 || true
47
47
  if [[ "$lib" = *@* ]]; then
@@ -53,7 +53,7 @@ add_darwin_libs() {
53
53
 
54
54
  # Function to add required libraries
55
55
  add_libs() {
56
- all_libs=("$@")
56
+ local all_libs=("$@")
57
57
  for lib in "${all_libs[@]}"; do
58
58
  if [ "$(uname -s)" = "Linux" ]; then
59
59
  add_linux_libs "$lib"
@@ -65,26 +65,27 @@ add_libs() {
65
65
 
66
66
  # Function to run command in a group
67
67
  run_group() {
68
- command=$1
69
- log=$2
68
+ local command=$1
69
+ local log=$2
70
70
  echo "$command" | sudo tee ./run_group.sh >/dev/null 2>&1
71
- echo "::group::$log"
71
+ echo "$GROUP$log"
72
72
  . ./run_group.sh
73
73
  rm ./run_group.sh
74
- echo "::endgroup::"
74
+ echo "$END_GROUP"
75
75
  }
76
76
 
77
77
  patch_extension() {
78
- extension=$1
79
- if [ -e "${scripts:?}"/ext/patches/"$extension".sh ]; then
78
+ local extension=$1
79
+ if [ -e "${scripts:?}"/extensions/patches/"$extension".sh ]; then
80
80
  # shellcheck source=.
81
- . "${scripts:?}"/ext/patches/"$extension".sh
81
+ . "${scripts:?}"/extensions/patches/"$extension".sh
82
82
  patch_"${extension}"
83
83
  fi
84
84
  }
85
85
 
86
86
  fetch_extension() {
87
- fetch=$1
87
+ local extension=$1
88
+ local fetch=$2
88
89
  if [ "$fetch" = "clone" ]; then
89
90
  run_group "git clone -nv $url/$org/$repo /tmp/$repo-$release" "git clone"
90
91
  cd /tmp/"$repo-$release" || exit 1
@@ -109,13 +110,13 @@ fetch_extension() {
109
110
 
110
111
  # Function to install extension from a git repository
111
112
  add_extension_from_source() {
112
- extension="${1/pecl_/}"
113
- url=$2
114
- org=$3
115
- repo=$4
116
- release=$5
117
- prefix=$6
118
- fetch=${7:-clone}
113
+ local extension="${1/pecl_/}"
114
+ local url=$2
115
+ local org=$3
116
+ local repo=$4
117
+ local release=$5
118
+ local prefix=$6
119
+ local fetch=${7:-clone}
119
120
  slug="$extension-$release"
120
121
  source="$url/$org/$repo"
121
122
  libraries="$(parse_args "$extension" LIBS) $(parse_args "$extension" "$(uname -s)"_LIBS)"
@@ -127,7 +128,7 @@ add_extension_from_source() {
127
128
  (
128
129
  add_devtools phpize >/dev/null 2>&1
129
130
  disable_extension_helper "$extension"
130
- fetch_extension "$fetch"
131
+ fetch_extension "$extension" "$fetch"
131
132
  if ! [ "$(find . -maxdepth 1 -name '*.m4' -exec grep -H 'PHP_NEW_EXTENSION' {} \; | wc -l)" != "0" ]; then
132
133
  add_log "${cross:?}" "$source" "$source does not have a PHP extension"
133
134
  else
@@ -0,0 +1,15 @@
1
+ # Function to get sqlsrv and pdo_sqlsrv version.
2
+ get_sqlsrv_version() {
3
+ if [[ "${version:?}" =~ 7.[0-3] ]]; then
4
+ echo '5.9.0'
5
+ else
6
+ echo '5.10.0'
7
+ fi
8
+ }
9
+
10
+ # Function to install sqlsrv and pdo_sqlsrv.
11
+ add_sqlsrv() {
12
+ ext=$1
13
+ ext_version=$(get_sqlsrv_version)
14
+ add_pecl_extension "$ext" "$ext_version" extension
15
+ }
@@ -1,9 +1,13 @@
1
- # Function to setup environment for self-hosted runners.
2
- self_hosted_helper() {
1
+ # Function to add sudo
2
+ add_sudo() {
3
3
  if ! command -v sudo >/dev/null; then
4
- apt-get update
5
- apt-get install -y sudo || add_log "${cross:?}" "sudo" "Could not install sudo"
4
+ check_package sudo || apt-get update
5
+ apt-get install -y sudo
6
6
  fi
7
+ }
8
+
9
+ # Function to setup environment for self-hosted runners.
10
+ self_hosted_helper() {
7
11
  if ! command -v apt-fast >/dev/null; then
8
12
  sudo ln -sf /usr/bin/apt-get /usr/bin/apt-fast
9
13
  trap "sudo rm -f /usr/bin/apt-fast 2>/dev/null" exit
@@ -21,11 +25,14 @@ install_packages() {
21
25
  disable_extension_helper() {
22
26
  local extension=$1
23
27
  local disable_dependents=${2:-false}
28
+ get_extension_map
24
29
  if [ "$disable_dependents" = "true" ]; then
25
30
  disable_extension_dependents "$extension"
26
31
  fi
27
32
  sudo sed -Ei "/=(.*\/)?\"?$extension(.so)?$/d" "${ini_file[@]}" "$pecl_file"
28
- sudo find "$ini_dir"/.. -name "*$extension.ini" -not -path "*mods-available*" -delete >/dev/null 2>&1 || true
33
+ sudo find "$ini_dir"/.. -name "*$extension.ini" -not -path "*phar.ini" -not -path "*pecl.ini" -not -path "*mods-available*" -delete >/dev/null 2>&1 || true
34
+ mkdir -p /tmp/extdisabled/"$version"
35
+ echo '' | sudo tee /tmp/extdisabled/"$version"/"$extension" >/dev/null 2>&1
29
36
  }
30
37
 
31
38
  # Function to add PDO extension.
@@ -61,22 +68,16 @@ add_pdo_extension() {
61
68
 
62
69
  # Function to check if a package exists
63
70
  check_package() {
64
- sudo apt-cache policy "$1" 2>/dev/null | grep -q 'Candidate'
71
+ apt-cache policy "$1" 2>/dev/null | grep -q 'Candidate'
65
72
  }
66
73
 
67
- # Function to add extensions.
68
- add_extension() {
74
+ # Helper function to add an extension.
75
+ add_extension_helper() {
69
76
  local extension=$1
70
- prefix=$2
71
77
  package=php"$version"-"$extension"
72
- enable_extension "$extension" "$prefix"
73
- if check_extension "$extension"; then
74
- add_log "${tick:?}" "$extension" "Enabled"
75
- else
76
- add_ppa ondrej/php >/dev/null 2>&1 || update_ppa ondrej/php
77
- (check_package "$package" && install_packages "$package") || pecl_install "$extension"
78
- add_extension_log "$extension" "Installed and enabled"
79
- fi
78
+ add_ppa ondrej/php >/dev/null 2>&1 || update_ppa ondrej/php
79
+ (check_package "$package" && install_packages "$package") || pecl_install "$extension"
80
+ add_extension_log "$extension" "Installed and enabled"
80
81
  sudo chmod 777 "${ini_file[@]}"
81
82
  }
82
83
 
@@ -84,8 +85,9 @@ add_extension() {
84
85
  add_devtools() {
85
86
  tool=$1
86
87
  if ! command -v "$tool$version" >/dev/null; then
87
- install_packages "php$version-dev" "php$version-xml"
88
+ install_packages "php$version-dev"
88
89
  fi
90
+ add_extension xml extension >/dev/null 2>&1
89
91
  switch_version "phpize" "php-config"
90
92
  add_log "${tick:?}" "$tool" "Added $tool $semver"
91
93
  }
@@ -128,8 +130,9 @@ switch_version() {
128
130
  add_packaged_php() {
129
131
  if [ "$runner" = "self-hosted" ] || [ "${use_package_cache:-true}" = "false" ]; then
130
132
  add_ppa ondrej/php >/dev/null 2>&1 || update_ppa ondrej/php
131
- IFS=' ' read -r -a packages <<<"$(echo "cli curl mbstring xml intl" | sed "s/[^ ]*/php$version-&/g")"
133
+ IFS=' ' read -r -a packages <<<"$(sed "s/[^ ]*/php$version-&/g" "$src"/configs/php_packages | tr '\n' ' ')"
132
134
  install_packages "${packages[@]}"
135
+ add_pecl
133
136
  else
134
137
  run_script "php-ubuntu" "$version"
135
138
  fi
@@ -137,13 +140,13 @@ add_packaged_php() {
137
140
 
138
141
  # Function to update PHP.
139
142
  update_php() {
140
- initial_version=$(php_semver)
141
- add_packaged_php
142
- updated_version=$(php_semver)
143
+ initial_version="$(php_semver)$(php_extra_version)"
144
+ add_php
145
+ updated_version="$(php_semver)$(php_extra_version)"
143
146
  if [ "$updated_version" != "$initial_version" ]; then
144
147
  status="Updated to"
145
148
  else
146
- status="Switched to"
149
+ status="Found"
147
150
  fi
148
151
  }
149
152
 
@@ -155,6 +158,7 @@ add_php() {
155
158
  setup_old_versions
156
159
  else
157
160
  add_packaged_php
161
+ switch_version >/dev/null 2>&1
158
162
  fi
159
163
  status="Installed"
160
164
  }
@@ -175,23 +179,46 @@ php_extra_version() {
175
179
  fi
176
180
  }
177
181
 
182
+ # Function to set php.ini
183
+ add_php_config() {
184
+ php_lib_dir=/usr/lib/php/"$version"
185
+ current_ini="$php_lib_dir"/php.ini-current
186
+ current=$(cat "$current_ini" 2>/dev/null)
187
+ if [ "$current" = "$ini" ]; then
188
+ return;
189
+ fi
190
+ if [[ "$ini" = "production" && "x$current" != "xproduction" ]]; then
191
+ echo "${ini_file[@]}" | xargs -n 1 -P 6 sudo cp "$php_lib_dir"/php.ini-production
192
+ if [ -e "$php_lib_dir"/php.ini-production.cli ]; then
193
+ sudo cp "$php_lib_dir"/php.ini-production.cli "$ini_dir"/php.ini
194
+ fi
195
+ elif [ "$ini" = "development" ]; then
196
+ echo "${ini_file[@]}" | xargs -n 1 -P 6 sudo cp "$php_lib_dir"/php.ini-development
197
+ elif [ "$ini" = "none" ]; then
198
+ echo '' | sudo tee "${ini_file[@]}" >/dev/null 2>&1
199
+ fi
200
+ echo "$ini" | sudo tee "$current_ini" >/dev/null 2>&1
201
+ }
202
+
178
203
  # Function to Setup PHP
179
204
  setup_php() {
180
205
  step_log "Setup PHP"
181
206
  sudo mkdir -m 777 -p /var/run /run/php
182
- if [ "$(php-config --version 2>/dev/null | cut -c 1-3)" != "$version" ]; then
207
+ php_config="$(command -v php-config)"
208
+ if [[ -z "$php_config" ]] || [ "$(php_semver | cut -c 1-3)" != "$version" ]; then
183
209
  if [ ! -e "/usr/bin/php$version" ]; then
184
210
  add_php >/dev/null 2>&1
185
211
  else
212
+ if ! [[ "$version" =~ ${old_versions:?} ]]; then
213
+ switch_version >/dev/null 2>&1
214
+ fi
186
215
  if [ "${update:?}" = "true" ]; then
187
216
  update_php >/dev/null 2>&1
188
217
  else
189
218
  status="Switched to"
190
219
  fi
191
220
  fi
192
- if ! [[ "$version" =~ ${old_versions:?}|${nightly_versions:?} ]]; then
193
- switch_version >/dev/null 2>&1
194
- fi
221
+ php_config="$(command -v php-config)"
195
222
  else
196
223
  if [ "$update" = "true" ]; then
197
224
  update_php >/dev/null 2>&1
@@ -200,39 +227,43 @@ setup_php() {
200
227
  fi
201
228
  fi
202
229
  if ! command -v php"$version" >/dev/null; then
203
- add_log "$cross" "PHP" "Could not setup PHP $version"
230
+ add_log "${cross:?}" "PHP" "Could not setup PHP $version"
204
231
  exit 1
205
232
  fi
206
- semver=$(php_semver)
207
- extra_version=$(php_extra_version)
208
- ext_dir=$(php -i | grep "extension_dir => /" | sed -e "s|.*=> s*||")
209
- scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||")
210
- ini_dir=$(php --ini | grep "(php.ini)" | sed -e "s|.*: s*||")
233
+ ext_dir="/usr/$(grep -Po "extension_dir=..[^/]*/\K[^'\"]*" "$php_config")"
234
+ ini_dir="$(php_ini_path)"
235
+ scan_dir="$ini_dir"/conf.d
211
236
  pecl_file="$scan_dir"/99-pecl.ini
237
+ semver="$(php_semver)"
238
+ extra_version="$(php_extra_version)"
212
239
  export ext_dir
213
240
  mapfile -t ini_file < <(sudo find "$ini_dir/.." -name "php.ini" -exec readlink -m {} +)
214
241
  link_pecl_file
215
242
  configure_php
243
+ set_output "php-version" "$semver"
216
244
  sudo rm -rf /usr/local/bin/phpunit >/dev/null 2>&1
217
245
  sudo chmod 777 "${ini_file[@]}" "$pecl_file" "${tool_path_dir:?}"
218
- sudo cp "$dist"/../src/configs/*.json "$RUNNER_TOOL_CACHE/"
219
- echo "::set-output name=php-version::$semver"
246
+ sudo cp "$src"/configs/pm/*.json "$RUNNER_TOOL_CACHE/"
220
247
  add_log "${tick:?}" "PHP" "$status PHP $semver$extra_version"
221
248
  }
222
249
 
223
250
  # Variables
224
- version=$1
225
- dist=$2
251
+ version=${1:-'8.1'}
252
+ ini=${2:-'production'}
253
+ src=${0%/*}/..
226
254
  debconf_fix="DEBIAN_FRONTEND=noninteractive"
227
255
  apt_install="sudo $debconf_fix apt-fast install -y --no-install-recommends"
228
- scripts="${dist}"/../src/scripts
256
+ scripts="$src"/scripts
257
+
258
+ add_sudo >/dev/null 2>&1
229
259
 
230
260
  . /etc/os-release
231
261
  # shellcheck source=.
232
- . "${scripts:?}"/ext/source.sh
262
+ . "${scripts:?}"/unix.sh
233
263
  . "${scripts:?}"/tools/ppa.sh
234
264
  . "${scripts:?}"/tools/add_tools.sh
235
- . "${scripts:?}"/common.sh
265
+ . "${scripts:?}"/extensions/source.sh
266
+ . "${scripts:?}"/extensions/add_extensions.sh
236
267
  read_env
237
268
  self_hosted_setup
238
269
  setup_php
@@ -1,29 +1,239 @@
1
+ # Variables
2
+ $composer_bin = "$env:APPDATA\Composer\vendor\bin"
3
+ $composer_json = "$env:APPDATA\Composer\composer.json"
4
+ $composer_lock = "$env:APPDATA\Composer\composer.lock"
5
+
6
+ # Function to configure composer.
7
+ Function Edit-ComposerConfig() {
8
+ Param(
9
+ [Parameter(Position = 0, Mandatory = $true)]
10
+ [ValidateNotNull()]
11
+ [ValidateLength(1, [int]::MaxValue)]
12
+ [string]
13
+ $tool_path
14
+ )
15
+ Copy-Item $tool_path -Destination "$tool_path.phar"
16
+ php -r "try {`$p=new Phar('$tool_path.phar', 0);exit(0);} catch(Exception `$e) {exit(1);}"
17
+ if ($? -eq $False) {
18
+ Add-Log "$cross" "composer" "Could not download composer"
19
+ exit 1;
20
+ }
21
+ New-Item -ItemType Directory -Path $composer_bin -Force > $null 2>&1
22
+ if (-not(Test-Path $composer_json)) {
23
+ Set-Content -Path $composer_json -Value "{}"
24
+ }
25
+ Add-EnvPATH $src\configs\composer.env
26
+ Add-Path $composer_bin
27
+ if (Test-Path env:COMPOSER_TOKEN) {
28
+ Add-Env COMPOSER_AUTH ('{"github-oauth": {"github.com": "' + $env:COMPOSER_TOKEN + '"}}')
29
+ }
30
+ }
31
+
32
+ # Function to extract tool version.
33
+ Function Get-ToolVersion() {
34
+ Param (
35
+ [Parameter(Position = 0, Mandatory = $true)]
36
+ $tool,
37
+ [Parameter(Position = 1, Mandatory = $true)]
38
+ $param
39
+ )
40
+ $alp = "[a-zA-Z0-9]"
41
+ $version_regex = "[0-9]+((\.{1}$alp+)+)(\.{0})(-$alp+){0,1}"
42
+ if($tool -eq 'composer') {
43
+ $composer_branch_alias = Select-String -Pattern "const\sBRANCH_ALIAS_VERSION" -Path $bin_dir\composer -Raw | Select-String -Pattern $version_regex | ForEach-Object { $_.matches.Value }
44
+ if ($composer_branch_alias) {
45
+ $composer_version = $composer_branch_alias + '+' + (Select-String -Pattern "const\sVERSION" -Path $bin_dir\composer -Raw | Select-String -Pattern "[a-zA-Z0-9]+" -AllMatches | ForEach-Object { $_.matches[2].Value })
46
+ } else {
47
+ $composer_version = Select-String -Pattern "const\sVERSION" -Path $bin_dir\composer -Raw | Select-String -Pattern $version_regex | ForEach-Object { $_.matches.Value }
48
+ }
49
+ Set-Variable -Name 'composer_version' -Value $composer_version -Scope Global
50
+ return "$composer_version"
51
+ }
52
+ return . $tool $param 2> $null | ForEach-Object { $_ -replace "composer $version_regex", '' } | Select-String -Pattern $version_regex | Select-Object -First 1 | ForEach-Object { $_.matches.Value }
53
+ }
54
+
55
+ # Helper function to configure tools.
1
56
  Function Add-ToolsHelper() {
2
57
  Param (
3
58
  [Parameter(Position = 0, Mandatory = $true)]
4
59
  [ValidateNotNull()]
5
60
  $tool
6
61
  )
62
+ $extensions = @();
7
63
  if($tool -eq "codeception") {
8
- Copy-Item $composer_bin\codecept.bat -Destination $composer_bin\codeception.bat
64
+ $extensions += @('json', 'mbstring')
65
+ Copy-Item $env:codeception_bin\codecept.bat -Destination $env:codeception_bin\codeception.bat
9
66
  } elseif($tool -eq "composer") {
10
67
  Edit-ComposerConfig $bin_dir\$tool
11
68
  } elseif($tool -eq "cs2pr") {
12
69
  (Get-Content $bin_dir/cs2pr).replace('exit(9)', 'exit(0)') | Set-Content $bin_dir/cs2pr
13
70
  } elseif($tool -eq "phan") {
14
- Add-Extension fileinfo >$null 2>&1
15
- Add-Extension ast >$null 2>&1
71
+ $extensions += @('fileinfo', 'ast')
72
+ } elseif($tool -eq "phinx") {
73
+ $extensions += @('mbstring')
16
74
  } elseif($tool -eq "phive") {
17
- Add-Extension xml >$null 2>&1
75
+ $extensions += @('curl', 'mbstring', 'xml')
76
+ } elseif($tool -match "phpc(df|s)") {
77
+ $extensions += @('tokenizer', 'xmlwriter', 'simplexml')
78
+ } elseif($tool -match "php-cs-fixer") {
79
+ $extensions += @('json', 'tokenizer')
18
80
  } elseif($tool -eq "phpDocumentor") {
81
+ $extensions+=('ctype', 'hash', 'json', 'fileinfo', 'iconv', 'mbstring', 'simplexml', 'xml')
19
82
  Add-Extension fileinfo >$null 2>&1
20
83
  Copy-Item $bin_dir\phpDocumentor.bat -Destination $bin_dir\phpdoc.bat
21
- } elseif($tool -eq "symfony-cli") {
22
- Add-ToProfile $current_profile "symfony" "New-Alias symfony $bin_dir\symfony-cli.exe"
23
- Add-ToProfile $current_profile "symfony_cli" "New-Alias symfony-cli $bin_dir\symfony-cli.exe"
24
- } elseif($tool -match "vapor-cli") {
25
- Copy-Item $composer_bin\vapor.bat -Destination $composer_bin\vapor-cli.bat
84
+ } elseif($tool -eq "phpunit") {
85
+ $extensions += @('dom', 'json', 'libxml', 'mbstring', 'xml', 'xmlwriter')
86
+ } elseif($tool -eq "phpunit-bridge") {
87
+ $extensions += @('dom', 'pdo', 'tokenizer', 'xmlwriter')
88
+ } elseif($tool -eq "vapor-cli") {
89
+ $extensions += @('fileinfo', 'json', 'mbstring', 'zip', 'simplexml')
90
+ Copy-Item $env:vapor_cli_bin\vapor.bat -Destination $env:vapor_cli_bin\vapor-cli.bat
26
91
  } elseif($tool -eq "wp-cli") {
27
92
  Copy-Item $bin_dir\wp-cli.bat -Destination $bin_dir\wp.bat
28
93
  }
29
- }
94
+ foreach($extension in $extensions) {
95
+ Add-Extension $extension >$null 2>&1
96
+ }
97
+ }
98
+
99
+ # Function to add tools.
100
+ Function Add-Tool() {
101
+ Param (
102
+ [Parameter(Position = 0, Mandatory = $true)]
103
+ [ValidateNotNull()]
104
+ $urls,
105
+ [Parameter(Position = 1, Mandatory = $true)]
106
+ [ValidateNotNull()]
107
+ $tool,
108
+ [Parameter(Position = 2, Mandatory = $true)]
109
+ [ValidateNotNull()]
110
+ $ver_param
111
+ )
112
+ if (Test-Path $bin_dir\$tool) {
113
+ Copy-Item $bin_dir\$tool -Destination $bin_dir\$tool.old -Force
114
+ }
115
+ $tool_path = "$bin_dir\$tool"
116
+ foreach ($url in $urls){
117
+ if (($url | Split-Path -Extension) -eq ".exe") {
118
+ $tool_path = "$tool_path.exe"
119
+ }
120
+ try {
121
+ $status_code = (Invoke-WebRequest -Passthru -Uri $url -OutFile $tool_path).StatusCode
122
+ } catch {
123
+ if($url -match '.*github.com.*releases.*latest.*') {
124
+ try {
125
+ $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])
126
+ $status_code = (Invoke-WebRequest -Passthru -Uri $url -OutFile $tool_path).StatusCode
127
+ } catch { }
128
+ }
129
+ }
130
+ if($status_code -eq 200 -and (Test-Path $tool_path)) {
131
+ break
132
+ }
133
+ }
134
+
135
+ if (((Get-ChildItem -Path $bin_dir/* | Where-Object Name -Match "^$tool(.exe|.phar)*$").Count -gt 0)) {
136
+ $bat_content = @()
137
+ $bat_content += "@ECHO off"
138
+ $bat_content += "setlocal DISABLEDELAYEDEXPANSION"
139
+ $bat_content += "SET BIN_TARGET=%~dp0/" + $tool
140
+ $bat_content += "php %BIN_TARGET% %*"
141
+ Set-Content -Path $bin_dir\$tool.bat -Value $bat_content
142
+ Add-ToolsHelper $tool
143
+ Add-ToProfile $current_profile $tool "New-Alias $tool $bin_dir\$tool.bat" >$null 2>&1
144
+ $tool_version = Get-ToolVersion $tool $ver_param
145
+ Add-Log $tick $tool "Added $tool $tool_version"
146
+ } else {
147
+ if($tool -eq "composer") {
148
+ $env:fail_fast = 'true'
149
+ } elseif (Test-Path $bin_dir\$tool.old) {
150
+ Copy-Item $bin_dir\$tool.old -Destination $bin_dir\$tool -Force
151
+ }
152
+ Add-Log $cross $tool "Could not add $tool"
153
+ }
154
+ }
155
+
156
+ Function Add-ComposertoolHelper() {
157
+ Param (
158
+ [Parameter(Position = 0, Mandatory = $true)]
159
+ [string]
160
+ $tool,
161
+ [Parameter(Position = 1, Mandatory = $true)]
162
+ [string]
163
+ $release,
164
+ [Parameter(Position = 2, Mandatory = $true)]
165
+ [string]
166
+ $prefix,
167
+ [Parameter(Position = 3, Mandatory = $true)]
168
+ [string]
169
+ $scope,
170
+ [Parameter(Position = 4, Mandatory = $false)]
171
+ [string]
172
+ $composer_args
173
+ )
174
+ if($scope -eq 'global') {
175
+ if(Test-Path $composer_lock) {
176
+ Remove-Item -Path $composer_lock -Force
177
+ }
178
+ composer global require $prefix$release $composer_args >$null 2>&1
179
+ return composer global show $prefix$tool 2>&1 | findstr '^versions'
180
+ } else {
181
+ $release_stream = [System.IO.MemoryStream]::New([System.Text.Encoding]::ASCII.GetBytes($release))
182
+ $scoped_dir_suffix = (Get-FileHash -InputStream $release_stream -Algorithm sha256).Hash
183
+ $scoped_dir = "$composer_bin\_tools\$tool-$scoped_dir_suffix"
184
+ $unix_scoped_dir = $scoped_dir.replace('\', '/')
185
+ if(-not(Test-Path $scoped_dir)) {
186
+ New-Item -ItemType Directory -Force -Path $scoped_dir > $null 2>&1
187
+ composer require $prefix$release -d $unix_scoped_dir $composer_args >$null 2>&1
188
+ }
189
+ [System.Environment]::SetEnvironmentVariable(($tool.replace('-', '_') + '_bin'), "$scoped_dir\vendor\bin")
190
+ Add-Path $scoped_dir\vendor\bin
191
+ return composer show $prefix$tool -d $unix_scoped_dir 2>&1 | findstr '^versions'
192
+ }
193
+ }
194
+
195
+ # Function to setup a tool using composer.
196
+ Function Add-Composertool() {
197
+ Param (
198
+ [Parameter(Position = 0, Mandatory = $true)]
199
+ [ValidateNotNull()]
200
+ [ValidateLength(1, [int]::MaxValue)]
201
+ [string]
202
+ $tool,
203
+ [Parameter(Position = 1, Mandatory = $true)]
204
+ [ValidateNotNull()]
205
+ [ValidateLength(1, [int]::MaxValue)]
206
+ [string]
207
+ $release,
208
+ [Parameter(Position = 2, Mandatory = $true)]
209
+ [ValidateNotNull()]
210
+ [ValidateLength(1, [int]::MaxValue)]
211
+ [string]
212
+ $prefix,
213
+ [Parameter(Position = 3, Mandatory = $true)]
214
+ [ValidateNotNull()]
215
+ [ValidateLength(1, [int]::MaxValue)]
216
+ [string]
217
+ $scope
218
+ )
219
+ if($composer_version.split('.')[0] -ne "1") {
220
+ $composer_args = "--ignore-platform-req=ext-*"
221
+ if($tool -match "prestissimo|composer-prefetcher") {
222
+ Write-Output "::warning:: Skipping $tool, as it does not support Composer $composer_version. Specify composer:v1 in tools to use $tool"
223
+ Add-Log $cross $tool "Skipped"
224
+ Return
225
+ }
226
+ }
227
+ Enable-PhpExtension -Extension curl, mbstring, openssl -Path $php_dir
228
+ $log = Add-ComposertoolHelper $tool $release $prefix $scope $composer_args
229
+ if(Test-Path $composer_bin\composer) {
230
+ Copy-Item -Path "$bin_dir\composer" -Destination "$composer_bin\composer" -Force
231
+ }
232
+ Add-ToolsHelper $tool
233
+ if($log) {
234
+ $tool_version = Get-ToolVersion "Write-Output" "$log"
235
+ Add-Log $tick $tool "Added $tool $tool_version"
236
+ } else {
237
+ Add-Log $cross $tool "Could not setup $tool"
238
+ }
239
+ }