Skip to content

Commit fc2a04c

Browse files
detect if php installatin is required or not
1 parent 4e4027e commit fc2a04c

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

action.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ runs:
2525
- uses: actions/checkout@v4
2626

2727
- id: read-php-version
28-
name: "Read PHP Version"
28+
name: "Read PHP Version in Composer"
2929
shell: bash
3030
working-directory: ${{ inputs.working_directory }}
3131
run: |
@@ -48,7 +48,29 @@ runs:
4848
echo "No PHP version detected"
4949
exit 0;
5050
51+
- id: read-system-php-version
52+
name: "Read System PHP Version"
53+
shell: bash
54+
if: ${{ steps.read-php-version.outputs.php_version == '' }}
55+
run: |
56+
php_version=$(php -v | head -n 1 | cut -d ' ' -f 2 | cut -d '.' -f 1,2)
57+
echo "No composer.json detected, falling back to system PHP version $php_version"
58+
echo "php_version=$php_version" >> $GITHUB_OUTPUT
59+
60+
- id: decide-php-version
61+
name: "Decide PHP Version"
62+
shell: bash
63+
run: |
64+
echo "Requested PHP Version: ${{ steps.read-php-version.outputs.php_version }}"
65+
echo "System PHP Version: ${{ steps.read-system-php-version.outputs.php_version }}"
66+
if [ "${{ steps.read-php-version.outputs.php_version }}" != "" ] && [ "${{ steps.read-php-version.outputs.php_version }}" != "${{ steps.read-system-php-version.outputs.php_version }}" ]; then
67+
echo "Switching PHP version to ${{ steps.read-php-version.outputs.php_version }}"
68+
else
69+
echo "Keeping system PHP version ${{ steps.read-system-php-version.outputs.php_version }}"
70+
fi
71+
5172
- uses: shivammathur/setup-php@v2
73+
if: ${{ steps.read-system-php-version.outputs.php_version != '' || steps.read-php-version.outputs.php_version != steps.read-system-php-version.outputs.php_version }}
5274
with:
5375
php-version: ${{ steps.read-php-version.outputs.php_version }}
5476
tools: ${{ inputs.php_tools }}

0 commit comments

Comments
 (0)