setup-php 2.32.0 → 2.34.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.
@@ -53,8 +53,11 @@ read_env() {
53
53
  [ "${debug:-${DEBUG:-false}}" = "true" ] && debug=debug && update=true || debug=release
54
54
  [[ "${phpts:-${PHPTS:-nts}}" = "ts" || "${phpts:-${PHPTS:-nts}}" = "zts" ]] && ts=zts && update=true || ts=nts
55
55
  fail_fast="${fail_fast:-${FAIL_FAST:-false}}"
56
- [[ -z "${ImageOS}" && -z "${ImageVersion}" || -n ${ACT} ]] && _runner=self-hosted || _runner=github
56
+ [[ ( -z "$ImageOS" && -z "$ImageVersion" ) ||
57
+ ( -n "$RUNNER_ENVIRONMENT" && "$RUNNER_ENVIRONMENT" = "self-hosted" ) ||
58
+ -n "$ACT" || -n "$CONTAINER" ]] && _runner=self-hosted || _runner=github
57
59
  runner="${runner:-${RUNNER:-$_runner}}"
60
+ tool_path_dir="${setup_php_tools_dir:-${SETUP_PHP_TOOLS_DIR:-/usr/local/bin}}"
58
61
 
59
62
  if [[ "$runner" = "github" && $_runner = "self-hosted" ]]; then
60
63
  fail_fast=true
@@ -75,6 +78,45 @@ read_env() {
75
78
  export runner
76
79
  export update
77
80
  export ts
81
+ export tool_path_dir
82
+ }
83
+
84
+ # Function to create a lock.
85
+ acquire_lock() {
86
+ lock_path="$1"
87
+ while true; do
88
+ if sudo mkdir "$lock_path" 2>/dev/null; then
89
+ echo $$ | sudo tee "$lock_path/pid" >/dev/null
90
+ return 0
91
+ else
92
+ if sudo test -f "$lock_path/pid"; then
93
+ lock_pid=$(sudo cat "$lock_path/pid")
94
+ if ! ps -p "$lock_pid" >/dev/null 2>&1; then
95
+ sudo rm -rf "$lock_path"
96
+ continue
97
+ fi
98
+ fi
99
+ sleep 1
100
+ fi
101
+ done
102
+ }
103
+
104
+ # Function to release the lock.
105
+ release_lock() {
106
+ lock_path="$1"
107
+ sudo rm -rf "$lock_path"
108
+ }
109
+
110
+ # Function to get the SHA256 hash of a string.
111
+ get_sha256() {
112
+ local input=$1
113
+ if command -v sha256sum >/dev/null 2>&1; then
114
+ printf '%s' "$input" | sha256sum | cut -d' ' -f1
115
+ elif command -v shasum >/dev/null 2>&1; then
116
+ printf '%s' "$input" | shasum -a 256 | cut -d' ' -f1
117
+ elif command -v openssl >/dev/null 2>&1; then
118
+ printf '%s' "$input" | openssl dgst -sha256 | cut -d' ' -f2
119
+ fi
78
120
  }
79
121
 
80
122
  # Function to download a file using cURL.
@@ -89,23 +131,23 @@ get() {
89
131
  if [ "$mode" = "-s" ]; then
90
132
  sudo curl "${curl_opts[@]}" "${links[0]}"
91
133
  else
92
- lock_path="$file_path.lock"
93
- until sudo mkdir "$lock_path" 2>/dev/null; do
94
- sleep 1
95
- done
96
- if [ "$execute" = "-e" ]; then
97
- until [ -z "$(fuser "$file_path" 2>/dev/null)" ]; do
98
- sleep 1
99
- done
134
+ if [ "$runner" = "self-hosted" ]; then
135
+ lock_path="/tmp/sp-lck-$(get_sha256 "$file_path")"
136
+ acquire_lock "$lock_path"
137
+ if [ "$execute" = "-e" ]; then
138
+ until [ -z "$(fuser "$file_path" 2>/dev/null)" ]; do
139
+ sleep 1
140
+ done
141
+ fi
142
+ trap 'release_lock "$lock_path"' EXIT SIGINT SIGTERM
100
143
  fi
101
- trap 'sudo rm -rf "$lock_path"' EXIT SIGINT SIGTERM
102
144
  for link in "${links[@]}"; do
103
145
  status_code=$(sudo curl -w "%{http_code}" -o "$file_path" "${curl_opts[@]}" "$link")
104
146
  [ "$status_code" = "200" ] && break
105
147
  done
106
148
  [ "$execute" = "-e" ] && sudo chmod a+x "$file_path"
107
149
  [ "$mode" = "-v" ] && echo "$status_code"
108
- sudo rm -rf "$lock_path" >/dev/null 2>&1 || true
150
+ [ "$runner" = "self-hosted" ] && release_lock "$lock_path"
109
151
  fi
110
152
  }
111
153
 
package/src/tools.ts CHANGED
@@ -401,6 +401,9 @@ export async function addPhive(data: RS): Promise<string> {
401
401
  case /7\.2/.test(data['php_version']):
402
402
  data['version'] = '0.14.5';
403
403
  break;
404
+ case /7\.3|7\.4/.test(data['php_version']):
405
+ data['version'] = '0.15.3';
406
+ break;
404
407
  case /^latest$/.test(data['version']):
405
408
  data['version'] = await getLatestVersion(data);
406
409
  break;
@@ -422,6 +425,9 @@ export async function addPHPUnitTools(data: RS): Promise<string> {
422
425
  'latest';
423
426
  }
424
427
  data['url'] = await getPharUrl(data);
428
+ if (data['url'].match(/-\d+/)) {
429
+ data['url'] += ',' + data['url'].replace(/-(\d+)\.\d+\.\d+/, '-$1');
430
+ }
425
431
  return await addArchive(data);
426
432
  }
427
433
 
package/src/utils.ts CHANGED
@@ -48,8 +48,11 @@ export async function getInput(
48
48
  /**
49
49
  * Function to get manifest URL
50
50
  */
51
- export async function getManifestURL(): Promise<string> {
52
- return 'https://raw.githubusercontent.com/shivammathur/setup-php/develop/src/configs/php-versions.json';
51
+ export async function getManifestURLS(): Promise<string[]> {
52
+ return [
53
+ 'https://raw.githubusercontent.com/shivammathur/setup-php/develop/src/configs/php-versions.json',
54
+ 'https://setup-php.com/php-versions.json'
55
+ ];
53
56
  }
54
57
 
55
58
  /**
@@ -60,9 +63,13 @@ export async function getManifestURL(): Promise<string> {
60
63
  export async function parseVersion(version: string): Promise<string> {
61
64
  switch (true) {
62
65
  case /^(latest|lowest|highest|nightly|\d+\.x)$/.test(version):
63
- return JSON.parse((await fetch.fetch(await getManifestURL()))['data'])[
64
- version
65
- ];
66
+ for (const manifestURL of await getManifestURLS()) {
67
+ const fetchResult = await fetch.fetch(manifestURL);
68
+ if (fetchResult['data'] ?? false) {
69
+ return JSON.parse(fetchResult['data'])[version];
70
+ }
71
+ }
72
+ throw new Error(`Could not fetch the PHP version manifest.`);
66
73
  default:
67
74
  switch (true) {
68
75
  case version.length > 1: