mirror of
https://github.com/shivammathur/setup-php.git
synced 2026-09-25 11:17:05 +07:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 03ff514b6d | |||
| d20463ddb1 |
@@ -0,0 +1,62 @@
|
|||||||
|
import {execFileSync} from 'node:child_process';
|
||||||
|
import * as fs from 'node:fs';
|
||||||
|
|
||||||
|
describe('macOS installed PHP version comparison', () => {
|
||||||
|
const functions = fs
|
||||||
|
.readFileSync('src/scripts/darwin.sh', 'utf8')
|
||||||
|
.split('# Variables')[0];
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
['8.7.0-dev', '8.7.0', 'Found'],
|
||||||
|
['8.6.0-dev', '8.6.0', 'Found'],
|
||||||
|
['8.7.0-dev', '8.7.0-dev', 'Found'],
|
||||||
|
['8.5.9', '8.5.9', 'Found'],
|
||||||
|
['8.5.9', '8.5.11', 'Upgraded'],
|
||||||
|
['8.6.0RC1', '8.6.0', 'Upgraded'],
|
||||||
|
['8.7.0-dev', '8.7.1', 'Upgraded']
|
||||||
|
])('handles runtime %s with formula %s', (runtime, formula, expected) => {
|
||||||
|
// Exercise setup_php's real selection path while isolating system writes
|
||||||
|
// and the configuration stage from this version-comparison regression.
|
||||||
|
const output = execFileSync(
|
||||||
|
'bash',
|
||||||
|
[
|
||||||
|
'-c',
|
||||||
|
`${functions}
|
||||||
|
version="$REQUESTED"
|
||||||
|
debug=release ts=nts old_versions='^5\\.[3-5]$'
|
||||||
|
src=/unused RUNNER_TOOL_CACHE=/unused tool_path_dir=/unused tick=ok cross=error
|
||||||
|
step_log() { :; }
|
||||||
|
check_pre_installed() { :; }
|
||||||
|
get_brewed_php() { echo "$RUNTIME"; }
|
||||||
|
php_semver() { echo "$RUNTIME"; }
|
||||||
|
brew() { test "$1" = info || exit 2; echo "$FORMULA"; }
|
||||||
|
jq() { cat; }
|
||||||
|
add_php() { printf '%s\n' "$1" >&3; }
|
||||||
|
php-config() { :; }
|
||||||
|
sed() { echo /unused; }
|
||||||
|
sudo() { :; }
|
||||||
|
php_ini_path() { echo /unused; }
|
||||||
|
get_scan_dir() { echo /unused; }
|
||||||
|
php_extra_version() { :; }
|
||||||
|
configure_php() { :; }
|
||||||
|
link_opcache() { :; }
|
||||||
|
set_output() { :; }
|
||||||
|
add_log() { printf '%s\n' "$*"; }
|
||||||
|
setup_php 3>&1
|
||||||
|
`
|
||||||
|
],
|
||||||
|
{
|
||||||
|
encoding: 'utf8',
|
||||||
|
env: {
|
||||||
|
...process.env,
|
||||||
|
REQUESTED: runtime.split('.').slice(0, 2).join('.'),
|
||||||
|
RUNTIME: runtime,
|
||||||
|
FORMULA: formula
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
expect(output).toContain(`${expected} PHP ${runtime}`);
|
||||||
|
if (expected === 'Upgraded') expect(output).toContain('upgrade\n');
|
||||||
|
else expect(output).not.toContain('upgrade\n');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -33,7 +33,7 @@ setInterval(()=>{
|
|||||||
'bash',
|
'bash',
|
||||||
[
|
[
|
||||||
'-c',
|
'-c',
|
||||||
'. "$CACHE_SCRIPT"; add_env() { printf "env %s %s\\n" "$1" "$2"; }; (exit 0) & extension_cache_pid=$!; finish_extension_cache_downloads; test "$extension_cache_memcached_dependencies" = "igbinary msgpack"'
|
'. "$CACHE_SCRIPT"; add_env() { printf "env %s %s\\n" "$1" "$2"; }; enable_extensions() { printf "enable batch %s\\n" "$*"; }; enable_extension() { printf "enable module %s\\n" "$1"; }; php() { echo refreshed; }; (exit 0) & extension_cache_pid=$!; finish_extension_cache_downloads; test "$extension_cache_memcached_dependencies" = "igbinary msgpack"; test "$(cat /tmp/php${version}_extensions)" = refreshed; rm /tmp/php${version}_extensions'
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
encoding: 'utf8',
|
encoding: 'utf8',
|
||||||
@@ -45,6 +45,7 @@ setInterval(()=>{
|
|||||||
SETUP_PHP_NODE: process.execPath,
|
SETUP_PHP_NODE: process.execPath,
|
||||||
SETUP_PHP_EXTENSION_PACKS: 'imagick mongodb memcached',
|
SETUP_PHP_EXTENSION_PACKS: 'imagick mongodb memcached',
|
||||||
extension_cache_dir: cache,
|
extension_cache_dir: cache,
|
||||||
|
version: 'cache-test-' + path.basename(directory),
|
||||||
verbose: ''
|
verbose: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,6 +55,12 @@ setInterval(()=>{
|
|||||||
expect(output).toContain('mongodb cache unavailable');
|
expect(output).toContain('mongodb cache unavailable');
|
||||||
expect(output).toContain('env SASL_PATH /cache/imagick');
|
expect(output).toContain('env SASL_PATH /cache/imagick');
|
||||||
expect(output).not.toContain('env SASL_PATH /cache/mongodb');
|
expect(output).not.toContain('env SASL_PATH /cache/mongodb');
|
||||||
|
expect(output).toContain('enable batch imagick igbinary msgpack');
|
||||||
|
expect(output).toContain('enable module memcached');
|
||||||
|
expect(output).not.toContain('enable batch mongodb');
|
||||||
|
expect(output.indexOf('enable batch')).toBeLessThan(
|
||||||
|
output.indexOf('enable module memcached')
|
||||||
|
);
|
||||||
expect(fs.existsSync(cache)).toBe(false);
|
expect(fs.existsSync(cache)).toBe(false);
|
||||||
} finally {
|
} finally {
|
||||||
fs.rmSync(directory, {recursive: true, force: true});
|
fs.rmSync(directory, {recursive: true, force: true});
|
||||||
|
|||||||
@@ -286,7 +286,8 @@ setup_php() {
|
|||||||
status="Installed"
|
status="Installed"
|
||||||
elif [[ "${existing_version:0:3}" = "$version" && "${update:?}" = "true" ]]; then
|
elif [[ "${existing_version:0:3}" = "$version" && "${update:?}" = "true" ]]; then
|
||||||
brew_php_version="$(brew info --json "php@$version" 2>/dev/null | jq -r '.[].versions.stable')"
|
brew_php_version="$(brew info --json "php@$version" 2>/dev/null | jq -r '.[].versions.stable')"
|
||||||
if [ "$brew_php_version" != "$existing_version" ]; then
|
# Homebrew records development snapshots without PHP's runtime -dev suffix.
|
||||||
|
if [ "$brew_php_version" != "$existing_version" ] && [ "$brew_php_version" != "${existing_version%-dev}" ]; then
|
||||||
add_php "upgrade" "$existing_version" >/dev/null 2>&1 || {
|
add_php "upgrade" "$existing_version" >/dev/null 2>&1 || {
|
||||||
add_log "${cross:?}" "PHP" "Could not upgrade PHP $version"
|
add_log "${cross:?}" "PHP" "Could not upgrade PHP $version"
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ finish_extension_cache_downloads() {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
local extension variable value index
|
local extension variable value index
|
||||||
local cache_install_names=() cache_install_pids=()
|
local cache_install_names=() cache_install_pids=() cache_enable_names=()
|
||||||
for extension in $SETUP_PHP_EXTENSION_PACKS; do
|
for extension in $SETUP_PHP_EXTENSION_PACKS; do
|
||||||
[ -s "$extension_cache_dir/$extension.json" ] || continue
|
[ -s "$extension_cache_dir/$extension.json" ] || continue
|
||||||
# Packs own separate directories and module names. Extract and validate them
|
# Packs own separate directories and module names. Extract and validate them
|
||||||
@@ -55,6 +55,9 @@ finish_extension_cache_downloads() {
|
|||||||
# can be removed before the action enables its requested extensions.
|
# can be removed before the action enables its requested extensions.
|
||||||
if [ "$extension" = memcached ]; then
|
if [ "$extension" = memcached ]; then
|
||||||
extension_cache_memcached_dependencies='igbinary msgpack'
|
extension_cache_memcached_dependencies='igbinary msgpack'
|
||||||
|
cache_enable_names+=(igbinary msgpack)
|
||||||
|
else
|
||||||
|
cache_enable_names+=("$extension")
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
cat "$extension_cache_dir/$extension.install.log"
|
cat "$extension_cache_dir/$extension.install.log"
|
||||||
@@ -63,6 +66,15 @@ finish_extension_cache_downloads() {
|
|||||||
done
|
done
|
||||||
rm -rf "$extension_cache_dir"
|
rm -rf "$extension_cache_dir"
|
||||||
extension_cache_dir=
|
extension_cache_dir=
|
||||||
|
# Use the normal enabling rules, but overlap independent modules and refresh
|
||||||
|
# the loaded-module list once so later extension checks do not repeat php -m.
|
||||||
|
if [ "${#cache_enable_names[@]}" -gt 0 ]; then
|
||||||
|
enable_extensions "${cache_enable_names[@]}"
|
||||||
|
if [ -n "${extension_cache_memcached_dependencies:-}" ]; then
|
||||||
|
enable_extension memcached extension
|
||||||
|
fi
|
||||||
|
php -m > "/tmp/php${version}_extensions"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
enable_extension_cache_dependencies() {
|
enable_extension_cache_dependencies() {
|
||||||
|
|||||||
Reference in New Issue
Block a user