composer icon indicating copy to clipboard operation
composer copied to clipboard

php_version argument is ignored?

Open AttLii opened this issue 2 years ago • 13 comments

Hey,

I’m using following workflow to run my phpunit tests:

name: Pull Request
on: [pull_request]
jobs:
  phpunit:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: php-actions/composer@v6
        with:
          php_version: 7.4
          version: 2
      - run: composer test

When I print out php version inside tests with phpversion() or PHP_VERSION, the output is 8.0.12. I created a test print here, see "Run composer test" step. Am I using this action wrong or is it something in your action?

AttLii avatar Nov 18 '21 09:11 AttLii

Thanks for the report. From a first glance it looks like there's a bug, which I'll work fast to fix as a patch on the v6 tag.

I'll let you know when I've investigated.

Cheers, Greg.

g105b avatar Nov 20 '21 16:11 g105b

same problem for me

euberdeveloper avatar Nov 26 '21 15:11 euberdeveloper

Any news? I still see the problem

euberdeveloper avatar Dec 11 '21 17:12 euberdeveloper

Sorry, I've been totally busy with client work over the last couple of weeks. I'll bump this up my priority list to not take much longer.

g105b avatar Dec 12 '21 11:12 g105b

same problem here

mbretter avatar Dec 13 '21 18:12 mbretter

Are there any news? I am using this action to automatically create a zip with the prod code every time I create a new GitHub release and send it to a customer

euberdeveloper avatar Dec 22 '21 01:12 euberdeveloper

Also, on the .bash code, I can see

if [ "$ACTION_VERSION" == "latest" ]
then
	phar_url="${phar_url}/composer-stable.phar"
else
	phar_url="${phar_url}/composer-${ACTION_VERSION}.phar"
fi

While there is no track of ACTION_PHP_VERSION in the code.

So with the "version" var one could choose the composer version, whole the php_version var is not used at all in the bash code

euberdeveloper avatar Dec 22 '21 01:12 euberdeveloper

I have seen now that it executes https://raw.githubusercontent.com/php-actions/php-build/330b13bbb1eadd05bbb627477c1549cd7e62e406/php-build.bash, which uses ACTION_PHP_VERSION, so I don't know why it wouldn't consider it

euberdeveloper avatar Dec 22 '21 02:12 euberdeveloper

You guys (@euberdeveloper, @mbretter and @AttLii) are looking at two different PHP binaries actually:

  • The step using php-actions/composer@v6 builds its own PHP in a Docker container and this in fact correctly uses the php_version argument.
  • The run: composer test step invokes the PHP that comes with the Ubuntu that you get by runs-on: ubuntu-latest.

You can easily confirm that by running the action from https://gist.github.com/mj/e6a81b52d72940fd8773a1264cf2da26.

mj avatar Jan 04 '22 21:01 mj

That's a good shout, @mj. I wonder what you think would be the best idea to help people avoid this in the future? It might just be something for the documentation to deal with.

g105b avatar Jan 05 '22 09:01 g105b

Is there a way to avoid this behaviour, I mean like use the specified version also for the run command?

This would be good for instance if you want to run more than a command with composer and the specified PHP version

I agree on this to be added to the documentation

euberdeveloper avatar Jan 05 '22 11:01 euberdeveloper

The analysis by @mj seems correct - if you have a separate run step, then it will use the PHP from the system. The solution is not to use a separate run step to run Composer but instead to tweak the configuration of the php-actions/phpunit step.

However, this is not the cause for the 8.1 vs 8.0 problem reported in #73. (Will elaborate there in a moment)

osma avatar Jan 21 '22 10:01 osma

I have a solution that I've used on a project internally - we needed to test a live deployment succeeded, and this task required running an arbitrary command on the same PHP version that was used to deploy.

I used Docker to run the same image, and mounted the project directory as a volume... this isn't a very elegant solution, so I am planning on releasing a new repository to php-actions, "command" (or something named better...), which will work exactly like these other repos, but allow you to run arbitrary php scripts or shell commands within the same php-build container.

Let me know what you think, or any ideas you have for what to name this project and I'll put something together soon.

g105b avatar Feb 09 '22 10:02 g105b

This functionality will be developed here: https://github.com/php-actions/command

g105b avatar Nov 09 '22 15:11 g105b