Skip to content

Commit 5e1466f

Browse files
committed
Improve PHP version compatibility testing.
1 parent d012b88 commit 5e1466f

File tree

1 file changed

+56
-3
lines changed

1 file changed

+56
-3
lines changed

package-checks.sh

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
set -e
23

34
# Update readme.txt.
45
# $1 lineMatch value.
@@ -17,11 +18,60 @@ updateCloudflareStreamPHP() {
1718
# Test PHP version compatibility
1819
versions=(7.0 7.1 7.2 7.3 7.4 8.0 8.1 8.2 8.3 8.4)
1920

20-
for version in ${versions[@]}; do
21-
echo "Testing project compatibility against PHP $version"
22-
#phpcs -p -s -v --runtime-set testVersion $version- --standard=PHPCompatibilityWP --severity=1 ./ --extensions=php | grep -E 'ERROR|WARNING'
21+
# Check for phpcs
22+
if ! command -v phpcs &>/dev/null; then
23+
echo "Error: phpcs is not installed or not in your PATH."
24+
exit 1
25+
fi
26+
27+
if ! phpcs -i | grep -q 'PHPCompatibilityWP'; then
28+
echo "Error: PHPCompatibilityWP standard is not installed for phpcs."
29+
exit 1
30+
fi
31+
32+
incompatible_versions=()
33+
compatible_versions=()
34+
fatal_error_detected=0
35+
36+
# Test compatibility against versions specified in $versions
37+
for version in "${versions[@]}"; do
38+
echo "------------------------------------------"
39+
echo "Testing PHP compatibility: $version+"
40+
set +e
41+
phpcs --standard=PHPCompatibilityWP --extensions=php --runtime-set testVersion "$version-" ./ > phpcs_output.txt 2>&1
42+
result=$?
43+
set -e
44+
45+
if grep -q 'ERROR: Passing an array of values to a property' phpcs_output.txt; then
46+
echo "❌ Ruleset syntax error detected for PHP $version. Please update your PHPCompatibility ruleset or downgrade PHP_CodeSniffer."
47+
cat phpcs_output.txt
48+
fatal_error_detected=1
49+
break
50+
elif grep -qE 'ERROR|WARNING' phpcs_output.txt; then
51+
echo "❌ Incompatibilities found for PHP $version:"
52+
grep -E 'ERROR|WARNING' phpcs_output.txt
53+
incompatible_versions+=("$version")
54+
else
55+
echo "✅ Compatible with PHP $version+"
56+
compatible_versions+=("$version")
57+
fi
58+
rm phpcs_output.txt
2359
done
2460

61+
echo
62+
if (( fatal_error_detected )); then
63+
echo "A fatal ruleset/configuration error was detected. Please resolve before trusting the results above."
64+
elif ((${#incompatible_versions[@]} == 0)); then
65+
echo "🎉 All tested PHP versions are compatible!"
66+
else
67+
echo "❌ Incompatible PHP versions: ${incompatible_versions[*]}"
68+
if ((${#compatible_versions[@]} > 0)); then
69+
echo "✅ Lowest compatible PHP version: ${compatible_versions[0]}"
70+
else
71+
echo "❌ No compatible PHP versions found."
72+
fi
73+
fi
74+
2575
# Update minimum required PHP version
2676
echo
2777
lineMatch="Requires PHP:"
@@ -44,6 +94,9 @@ if [[ $pluginVer =~ [0-9] ]]; then
4494
echo "Updating plugin version from $currentVer to $pluginVer."
4595
updateReadme "$lineMatch" "$pluginVer"
4696
updateCloudflareStreamPHP "$lineMatch" "$pluginVer"
97+
# Update version in package.json and package-lock.json using sed
98+
sed -i "s/\"version\": \".*\"/\"version\": \"$pluginVer\"/" package.json
99+
sed -i "s/\"version\": \".*\"/\"version\": \"$pluginVer\"/" package-lock.json
47100
else
48101
echo "Skipping..."
49102
fi

0 commit comments

Comments
 (0)