Skip to content

Commit 2167ab3

Browse files
committed
Simplify PHP version determination logic
1 parent 689a882 commit 2167ab3

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

.github/workflows/docker.yml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,23 +101,16 @@ jobs:
101101
run: |
102102
tar -xzf simplesamlphp-version-full.tar.gz simplesamlphp-${{ env.VERSION }}/composer.json --strip-components=1
103103
working-directory: ${{ github.workspace }}
104-
- name: Determine latest supported PHP version
104+
- name: Determine minimum supported PHP version
105105
id: php_version
106106
run: |
107107
export PATH="$PATH:$HOME/.composer/vendor/bin"
108+
# Extract the PHP version constraint from composer.json
108109
PHP_CONSTRAINT=$(jq -r '.require.php' composer.json)
109-
# Fetch all PHP releases from php.net (JSON)
110-
RELEASES=$(curl -s 'https://www.php.net/releases/index.php?json&max=1000')
111-
# Extract all version fields, reduce to major.minor, deduplicate, and sort
112-
VERSIONS=$(echo "$RELEASES" | jq -r '.[] | select(.version != null) | .version' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | awk -F. '{print $1 "." $2}' | sort -Vu)
113-
# Use composer/semver to find the highest matching version
114-
MATCH=$(echo "$VERSIONS" | xargs -I{} semver "$PHP_CONSTRAINT" {} | tail -n1)
115-
if [ -z "$MATCH" ]; then
116-
# fallback to highest version if no match
117-
PHP_VERSION=$(echo "$VERSIONS" | tail -n1)
118-
else
119-
PHP_VERSION=$MATCH
120-
fi
110+
# Use composer/semver to get the minimum version that satisfies the constraint
111+
MIN_VERSION=$(semver "$PHP_CONSTRAINT" | head -n1)
112+
# Reduce to major.minor (e.g., 8.2 from 8.2.23)
113+
PHP_VERSION=$(echo "$MIN_VERSION" | awk -F. '{print $1 "." $2}')
121114
echo "PHP_VERSION=$PHP_VERSION" >> $GITHUB_ENV
122115
echo "php_version=$PHP_VERSION" >> $GITHUB_OUTPUT
123116
working-directory: ${{ github.workspace }}

0 commit comments

Comments
 (0)