Skip to content

Commit c55a37e

Browse files
committed
Fix version constraint parsing from package.xml
1 parent 7beb7fe commit c55a37e

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

extension-matrix/src/php-versions.sh

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,16 @@ function compare_versions_using_composer() {
5959
states="$(curl -sL https://www.php.net/releases/states.php)"
6060
php_versions="$(echo "$states" | jq -r 'to_entries[] | .key as $major | .value | to_entries[] | .key' | sort -Vu | tr '\n' ',')"
6161
constraint=$(jq -r .require.php "$composer_json")
62-
63-
rm -rf "$directory"
64-
65-
php "$SCRIPT_DIR"/semver/semver.phar "$constraint" "$php_versions"
62+
php "$SCRIPT_DIR"/semver/semver.phar composer.json "$constraint" "$php_versions"
6663
}
6764

6865
function compare_versions_using_package_xml() {
6966
local directory=$1
7067
local package_xml=$2
71-
min_version=$(grep '<min>' "$package_xml" | head -1 | sed -e 's/<[^>]*>//g' | cut -d'.' -f1,2 | xargs)
72-
max_version=$(grep '<max>' "$package_xml" | head -1 | sed -e 's/<[^>]*>//g' | cut -d'.' -f1,2 | xargs)
73-
68+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
7469
states="$(curl -sL https://www.php.net/releases/states.php)"
75-
IFS=' ' read -r -a php_versions <<< "$(echo "$states" | jq -r 'to_entries[] | .key as $major | .value | to_entries[] | .key' | sort -Vu | tr '\n' ' ')"
76-
77-
[[ -z "$max_version" ]] && max_version="${php_versions[-1]}"
78-
79-
rm -rf "$directory"
80-
81-
filter_versions "$min_version" "$max_version" "${php_versions[@]}"
70+
php_versions="$(echo "$states" | jq -r 'to_entries[] | .key as $major | .value | to_entries[] | .key' | sort -Vu | tr '\n' ',')"
71+
php "$SCRIPT_DIR"/semver/semver.phar package.xml "$package_xml" "$php_versions"
8272
}
8373

8474
function get_php_versions() {
@@ -90,8 +80,10 @@ function get_php_versions() {
9080
package_xml=$(find "$directory" -name package.xml)
9181
if [ -n "$composer_json" ]; then
9282
compare_versions_using_composer "$directory" "$composer_json"
83+
rm -rf "$directory"
9384
elif [ -n "$package_xml" ]; then
9485
compare_versions_using_package_xml "$directory" "$package_xml"
86+
rm -rf "$directory"
9587
else
9688
echo "No composer.json with type php-ext or package.xml found"
9789
exit 1

extension-matrix/src/semver/app.php

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,35 @@
66
use Composer\Semver\VersionParser;
77

88
if ($argc < 3) {
9-
echo "Usage: php app.php '<constraint>' '<version1,version2,...>'\n";
9+
echo "Usage: php app.php '<file>' '<constraint>' '<version1,version2,...>'\n";
1010
exit(1);
1111
}
1212

13-
$constraint = $argv[1];
14-
$versions = array_filter(explode(',', preg_replace('/\s+/', '', $argv[2])));
13+
$file = $argv[1];
14+
if($file === 'composer.json') {
15+
$constraint = $argv[2];
16+
} else if($file === 'package.xml') {
17+
$package_xml = $argv[2];
18+
$xml = simplexml_load_file($package_xml);
19+
$xml->registerXPathNamespace("p", "http://pear.php.net/dtd/package-2.0");
20+
$min = $xml->xpath("//p:php/p:min")[0] ?? null;
21+
$max = $xml->xpath("//p:php/p:max")[0] ?? null;
22+
$constraint = '';
23+
if($min) {
24+
$constraint .= '>=' . $min;
25+
}
26+
if($max) {
27+
$constraint .= ',<=' . $max;
28+
}
29+
$constraint = ltrim($constraint, ',');
30+
} else {
31+
echo "File not found";
32+
exit(1);
33+
}
1534

16-
if(count($versions)) {
35+
$versions = array_filter(explode(',', preg_replace('/\s+/', '', $argv[3])));
36+
37+
if (count($versions)) {
1738
$versionParser = new VersionParser();
1839
$constraint = $versionParser->parseConstraints($constraint);
1940

@@ -26,4 +47,7 @@
2647
}
2748

2849
echo implode(',', $satisfiedVersions);
29-
}
50+
} else {
51+
echo "No versions provided";
52+
exit(1);
53+
}
236 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)