Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are composer global packages installed correctly? #7289

Closed
natanmoraes opened this issue Feb 7, 2017 · 16 comments
Closed

Are composer global packages installed correctly? #7289

natanmoraes opened this issue Feb 7, 2017 · 16 comments

Comments

@natanmoraes
Copy link

When I run composer global require drupal/coder, the vendor files are installed in ~/.config/composer.

See build screenshot:

screenshot from 2017-02-07 14 40 20

I was expecting they would be installed under ~/.composer.

Is this by design?

My .travis.yml file:

language: php
sudo: required
dist: trusty

php:
  - 5.6

install:
  # Remove xdebug to make composer faster.
  - phpenv config-rm xdebug.ini
  # add composer's global bin directory to the path
  # see: https://github.com/drush-ops/drush#install---composer
  - export PATH="$HOME/.config/composer/vendor/bin:$PATH"

  # Install PHP_CodeSniffer and Drupal config
  - composer global require drupal/coder
  - phpcs --config-set installed_paths ~/.config/composer/vendor/drupal/coder/coder_sniffer

before_script:
  # This slows things down but it ensures all remote branches are fetched.
  - git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
  - git fetch --unshallow
  - git fetch origin

script: ./scripts/travis-build.sh
@MarkVaughn
Copy link

Any luck with this? Trying the same thing with global install

@BanzaiMan BanzaiMan added the php label Mar 22, 2017
@BanzaiMan
Copy link
Contributor

Do you have a build log URL that shows the problem you are describing here?

@MarkVaughn
Copy link

At first I the install had
- composer global require "squizlabs/php_codesniffer=*"
and the script had
- phpcs --standard=custom_ruleset.xml --encoding=utf-8 -np src
Which resulted in

phpcs: command not found

After researching a bit more I changed the install bit to

- pear install pear/PHP_CodeSniffer
- phpenv rehash

Which ended up working fine.
I'm assuming composer global require doesn't work because the ..pathto/.composer/vendor/bin is probably not in the path.

@BanzaiMan
Copy link
Contributor

Do you have a build log URL that we can take a look at, so that we can determine if there is anything for us to fix?

@MarkVaughn
Copy link

The log is on the .com version of travis. But if you got admin access: build id is 42453136, install on line 398, error on line 453 the commands are as mentioned in my previous post

@BanzaiMan
Copy link
Contributor

@MarkVaughn Thanks for the info.

Your log indicates:

Changed current directory to /home/travis/.composer

which is different from what @natanmoraes wrote originally.

In addition, it is not clear from your log how you are invoking composer commands; it is also not clear where phpcs is installed by Composer, or whether or not the directory in question is on your $PATH.

I also see that the build 2759 on the same PR fixed the issue. How was it fixed?

@MarkVaughn
Copy link

As mentioned in my previous post, this is the command:
composer global require "squizlabs/php_codesniffer=*"

But i fixed it by switching to

pear install pear/PHP_CodeSniffer
phpenv rehash

Essentially ditching global composer for pear.

When doing global composer installs the executables would be located in /home/travis/.composer/vendor/bin which I'm assuming is not in the $PATH

@stale
Copy link

stale bot commented Apr 13, 2018

Thanks for contributing to this issue. As it has been 90 days since the last activity, we are automatically closing the issue. This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable. If that's not the case, please do feel free to either reopen this issue or open a new one. We'll gladly take a look again! You can read more here: https://blog.travis-ci.com/2018-03-09-closing-old-issues

@stale stale bot added the stale label Apr 13, 2018
@stale stale bot closed this as completed Apr 14, 2018
@robbieaverill
Copy link

Hi team, I've just noticed this happening on some of our builds as well (switching from ~/.composer to ~/.config/composer). @BanzaiMan do you know why this changes? I'm happy to update all of our Travis config files, but hopefully it won't change back again to the former path =)

@raoulduke
Copy link

Having the same issue. Any global composer installation results in ~/.config/composer as the installation directory. It can be seen in the output after your command:

Changed current directory to /home/travis/.config/composer

@robbieaverill
Copy link

The output of composer global --help says:

Use this command as a wrapper to run other Composer commands
within the global context of COMPOSER_HOME.

You can use this to install CLI utilities globally, all you need
is to add the COMPOSER_HOME/vendor/bin dir to your PATH env var.

COMPOSER_HOME is c:\Users\AppData\Roaming\Composer on Windows
and /home//.composer on unix systems.
If your system uses freedesktop.org standards, then it will first check
XDG_CONFIG_HOME or default to /home//.config/composer

If the Travis PHP images have changed distro recently then that would explain the change

@raoulduke
Copy link

@robbieaverill I'm used to /home/<user>/.composer on unix systems, but I'm assuming from that output it means Travis is using the freedesktop.org specifications. Might be worth noting this in the build environment docs.

@robbieaverill
Copy link

composer global exec [binaryname] [args] looks like a promising option to avoid needing to specify the path at all, but it doesn't seem to work for me on my laptop =(

@raoulduke
Copy link

@robbieaverill Use composer global exec -- "your command and options".

Example on my vagrant box:

$ composer global exec -v --  "phpcs -n --standard=PSR2 /home/vagrant/code/test"
Changed current directory to /home/vagrant/.composer
> __exec_command: phpcs -n --standard=PSR2 /home/vagrant/code/test

@robbieaverill
Copy link

Ah I see, I had to make it verbose to get output. So this could be a decent replacement for running global binaries via the composer global install path (which is variable)

rodrigoprimo added a commit to rodrigoprimo/woocommerce that referenced this issue Dec 5, 2018
Due to an unknown change in Travis environment, WooCommerce unit tests stopped working with the following error (see for example https://travis-ci.org/woocommerce/woocommerce/jobs/463470674#L876):

Fatal error: Class PHPUnit_Util_Test may not inherit from final class (PHPUnit\Util\Test) in /tmp/wordpress-tests-lib/includes/phpunit6-compat.php on line 18

This error is happening because Travis started ignoring the PHPUnit version that we install manually via Composer (https://github.com/woocommerce/woocommerce/blob/f7bc3fb85195df8f96c70d2846b0104ee224fef2/tests/bin/travis.sh#L6) and started using the PHPUnit version that is shipped with each of its PHP docker images. This means that for the docker images running PHP 7.2 and 7.3, PHPUnit 7 is used but the WordPress unit test framework is not compatible with PHPUnit 7 (see WordPress core ticket https://core.trac.wordpress.org/ticket/43218) and produces the error above. I believe that this is happening because Travis changed the directory where it installs composer global packages from `$HOME/.composer/` to `$HOME/.config/composer/` (travis-ci/travis-ci#7289 (comment)) and we add `$HOME/.composer/vendor/bin:$PATH` to the `$PATH`.

To fix this, instead of changing the directory that we add to the `$PATH`, I'm using `composer exec`. This way we don't have to worry if the composer directory changes again in the future.
rodrigoprimo added a commit to rodrigoprimo/woocommerce that referenced this issue Dec 5, 2018
Due to an unknown change in Travis environment, WooCommerce unit tests stopped working with the following error (see for example https://travis-ci.org/woocommerce/woocommerce/jobs/463470674#L876):

Fatal error: Class PHPUnit_Util_Test may not inherit from final class (PHPUnit\Util\Test) in /tmp/wordpress-tests-lib/includes/phpunit6-compat.php on line 18

This error is happening because Travis started ignoring the PHPUnit version that we install manually via Composer (https://github.com/woocommerce/woocommerce/blob/f7bc3fb85195df8f96c70d2846b0104ee224fef2/tests/bin/travis.sh#L6) and started using the PHPUnit version that is shipped with each of its PHP docker images. This means that for the docker images running PHP 7.2 and 7.3, PHPUnit 7 is used but the WordPress unit test framework is not compatible with PHPUnit 7 (see WordPress core ticket https://core.trac.wordpress.org/ticket/43218) and produces the error above. I believe that this is happening because Travis changed the directory where it installs composer global packages from `$HOME/.composer/` to `$HOME/.config/composer/` (travis-ci/travis-ci#7289 (comment)) and we add `$HOME/.composer/vendor/bin:$PATH` to the `$PATH`.

To fix this, instead of changing the directory that we add to the `$PATH`, I'm using `composer exec`. This way we don't have to worry if the composer directory changes again in the future.
rodrigoprimo added a commit to rodrigoprimo/woocommerce that referenced this issue Dec 5, 2018
Due to a recent change in the Travis environment, WooCommerce unit tests stopped working with the following error (see for example https://travis-ci.org/woocommerce/woocommerce/jobs/463470674#L876) in the PHP 7.2 and 7.3 build jobs:

Fatal error: Class PHPUnit_Util_Test may not inherit from final class (PHPUnit\Util\Test) in /tmp/wordpress-tests-lib/includes/phpunit6-compat.php on line 18

This error is happening because Travis started ignoring the PHPUnit version that we install manually via Composer (https://github.com/woocommerce/woocommerce/blob/f7bc3fb85195df8f96c70d2846b0104ee224fef2/tests/bin/travis.sh#L6) and started using the PHPUnit version that is shipped with each of its PHP docker images. This means that for the docker images running PHP 7.2 and 7.3, PHPUnit 7 is used but the WordPress unit test framework is not compatible with PHPUnit 7 (see WordPress core ticket https://core.trac.wordpress.org/ticket/43218) and produces the error above. I believe that this is happening because Travis changed the directory where it installs composer global packages from `$HOME/.composer/` to `$HOME/.config/composer/` (travis-ci/travis-ci#7289 (comment)) and we add `$HOME/.composer/vendor/bin:$PATH` to the `$PATH`. So this commit simply updates the path in the line where we add it to the `$PATH`.

I tried to use `composer exec` instead of updating `$PATH` but that didn't work for PHP 5.2.
rodrigoprimo added a commit to rodrigoprimo/woocommerce that referenced this issue Dec 6, 2018
Due to a recent change in the Travis environment, WooCommerce unit tests stopped working with the following error (see for example https://travis-ci.org/woocommerce/woocommerce/jobs/463470674#L876) in the PHP 7.2 and 7.3 build jobs:

Fatal error: Class PHPUnit_Util_Test may not inherit from final class (PHPUnit\Util\Test) in /tmp/wordpress-tests-lib/includes/phpunit6-compat.php on line 18

This error is happening because Travis started ignoring the PHPUnit version that we install manually via Composer (https://github.com/woocommerce/woocommerce/blob/f7bc3fb85195df8f96c70d2846b0104ee224fef2/tests/bin/travis.sh#L6) and started using the PHPUnit version that is shipped with each of its PHP docker images. This means that for the docker images running PHP 7.2 and 7.3, PHPUnit 7 is used but the WordPress unit test framework is not compatible with PHPUnit 7 (see WordPress core ticket https://core.trac.wordpress.org/ticket/43218) and produces the error above. I believe that this is happening because Travis changed the directory where it installs composer global packages from `$HOME/.composer/` to `$HOME/.config/composer/` (travis-ci/travis-ci#7289 (comment)) and we add `$HOME/.composer/vendor/bin:$PATH` to the `$PATH`. So this commit simply updates the path in the line where we add it to the `$PATH`.

I tried to use `composer exec` instead of updating `$PATH` but that didn't work for PHP 5.2.
stevenrombauts pushed a commit to joomlatools/joomlatools-composer that referenced this issue Dec 30, 2018
Due to a recent change in the Travis build environment, the
path to Composer's global bin directory has changed.

The suggested fix is to use 'composer exec' instead of
relying on the hardcoded path.

See: travis-ci/travis-ci#7289
@aphofstede
Copy link

This worked for me: export PATH="$PATH:$HOME/.config/composer/vendor/bin:$HOME/.composer/vendor/bin"

hakito added a commit to hakito/travis that referenced this issue May 5, 2019
In the migrated build environment global composer installs go to ~/.config/composer instead of ~/.composer  travis-ci/travis-ci#7289
hakito added a commit to hakito/travis that referenced this issue May 5, 2019
travis-ci now installs global composer packages to ~/.config/composer

See travis-ci/travis-ci#7289
fiasco added a commit to drutiny/drutiny that referenced this issue Aug 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants