setup-php
setup-php copied to clipboard
pick up PHP version from composer.json
Describe the feature
for example actions/setup-go@v3, pick up Golang version from go.mod
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: "go.mod"
- run: go version
I want to pick up PHP version from composer.json, like this
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version-file: 'composer.json'
- run: php --version
composer.json like this
{
"name": "foo/bar",
"version": "0.0.1",
"license": "MIT",
"require": {
"php": "^8.0|^8.1"
}
}
Version
- [x] I have checked releases, and the feature is missing in the latest patch version of
v2
.
Underlying issue
When PHP version up, I must do same change to composer.json and GHA workflow yaml files.
Describe alternatives
Additional context
Are you willing to submit a PR?
I can try!
@watarukura
go.mod
specifies the exact version, but it can be a range in composer.json
.
So it will need another input say php-version-preference
which takes an input highest
or lowest
, or minimum
or maximum
to resolve the range to an exact version. It can default to the highest version similar to how composer works.
If you would like to work on a PR to add this, please go ahead.
Similar actions like setup-node
and setup-python
have gone with pulling the version from a standalone file, that'd be great to see here rather than parsing out from composer.json which, as above, could be a range, and confusing.
In addition to allowing the file to be specified via php-version-file
, it'd also be good if there was a default file used if version has not been specified any other way e.g. .php-version
or .phpenv-version
.
Fwiw setup-node
supports .nvmrc
but does not default to it (and that's kinda annoying). The setup-python
action uses .python-version
if neither python-version
or python-version-file
is supplied and that is 👌🏼 when you're using the language across a few actions/steps and simply want consistency.
Symfony CLI uses .php-version
. Seems as good a choice as any. https://symfony.com/doc/current/setup/symfony_server.html#selecting-a-different-php-version