acquia / blt

Acquia's toolset for automating Drupal 8 and 9 development, testing, and deployment.
https://docs.acquia.com/blt/
GNU General Public License v2.0
444 stars 397 forks source link

git hooks for composer checks fail when checking composer on host machine #4110

Closed shelane closed 4 years ago

shelane commented 4 years ago

I want to... Commit and push composer.json and composer.lock files.

It's not working because... Git commits and git push (as of 11.4.0) fail when checking composer on host machine when local machine only has composer inside of docker container.

Detailed error output

git --no-optional-locks -c color.branch=false -c color.diff=false -c color.status=false -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree push -v --set-upstream origin refs/heads/feature/DRUPAL8-3-module-updates:refs/heads/feature/DRUPAL8-3-module-updates 
Pushing to *****
Executing .git/hooks/pre-push...
> validate
> tests:composer:validate
Validating composer.json and composer.lock...
[ExecStack] composer validate --no-check-all --ansi
[ExecStack] Running composer validate --no-check-all --ansi in *****
sh: composer: command not found
[ExecStack]  Exit code 127  Time 0.005s

If this is simply a matter of the lock file being out of date, you may attempt to use `composer update --lock` to quickly generate a new hash in your lock file.
Otherwise, `composer update` is likely necessary.
[error]  composer.lock is invalid. 
[error]  composer.lock is invalid!
For troubleshooting guidance and support, see https://docs.acquia.com/blt/support/ 
The command failed. This often indicates a problem with your configuration. Review the command output above for more detailed errors, and consider re-running with verbose output for more information.
[error]  Command `tests:composer:validate ` exited with code 1.
For troubleshooting guidance and support, see https://docs.acquia.com/blt/support/ 
The command failed. This often indicates a problem with your configuration. Review the command output above for more detailed errors, and consider re-running with verbose output for more information.

 Your code has failed pre-push validation. 

error: failed to push some refs to '*****'
Completed with errors, see above

BLT doctor output

+---------------------------+--------------------------------------------------------+
| Property                  | Value                                                  |
+---------------------------+--------------------------------------------------------+
| %paths.%root              | /var/www/docroot                                       |
| %paths.%site              | sites/default                                          |
| %paths.%modules           | sites/all/modules                                      |
| %paths.%themes            | sites/all/themes                                       |
| %paths.%config-sync       | /var/www/config/default                                |
| %paths.%files             | sites/default/files                                    |
| %paths.%temp              | /tmp                                                   |
| %paths.%private           | /var/www/files-private                                 |
| admin-theme               | seven                                                  |
| alias-searchpaths.0       | /var/www/drush/sites                                   |
| base-profile              | lightning                                              |
| blt-version               | 11.4.0                                                 |
| bootstrap                 | Successful                                             |
| composer-version          | Composer version 1.9.0 2019-08-02 20:55:32             |
| config-sync               | /var/www/config/default                                |
| db-driver                 | mysql                                                  |
| db-hostname               | db                                                     |
| db-name                   | default                                                |
| db-password               | user                                                   |
| db-port                   | 3306                                                   |
| db-status                 | Connected                                              |
| db-username               | user                                                   |
| drupal-settings-file      | sites/default/settings.php                             |
| drupal-version            | 8.8.5                                                  |
| drush-alias-files.0       | /var/www/drush/sites/baasic.site.yml                   |
| drush-alias-files.1       | /var/www/drush/sites/carbon_economy.site.yml           |
| drush-alias-files.2       | /var/www/drush/sites/controlbanding.site.yml           |
| drush-alias-files.3       | /var/www/drush/sites/csl.site.yml                      |
| drush-alias-files.4       | /var/www/drush/sites/cyber_internship.site.yml         |
| drush-alias-files.5       | /var/www/drush/sites/data_science.site.yml             |
| drush-alias-files.6       | /var/www/drush/sites/default.site.yml                  |
| drush-alias-files.7       | /var/www/drush/sites/dus.site.yml                      |
| drush-alias-files.8       | /var/www/drush/sites/engineering.site.yml              |
| drush-alias-files.9       | /var/www/drush/sites/exascale.site.yml                 |
| drush-alias-files.10      | /var/www/drush/sites/fcoi.site.yml                     |
| drush-alias-files.11      | /var/www/drush/sites/forms.site.yml                    |
| drush-alias-files.12      | /var/www/drush/sites/heds_center.site.yml              |
| drush-alias-files.13      | /var/www/drush/sites/ipo.site.yml                      |
| drush-alias-files.14      | /var/www/drush/sites/kwla.site.yml                     |
| drush-alias-files.15      | /var/www/drush/sites/lasers.site.yml                   |
| drush-alias-files.16      | /var/www/drush/sites/ldrd_annual.site.yml              |
| drush-alias-files.17      | /var/www/drush/sites/library.site.yml                  |
| drush-alias-files.18      | /var/www/drush/sites/llns_champ.site.yml               |
| drush-alias-files.19      | /var/www/drush/sites/mara.site.yml                     |
| drush-alias-files.20      | /var/www/drush/sites/nanoscience.site.yml              |
| drush-alias-files.21      | /var/www/drush/sites/nci.site.yml                      |
| drush-alias-files.22      | /var/www/drush/sites/nexo.site.yml                     |
| drush-alias-files.23      | /var/www/drush/sites/nifuserguide.site.yml             |
| drush-alias-files.24      | /var/www/drush/sites/nuclear_particle_physics.site.yml |
| drush-alias-files.25      | /var/www/drush/sites/odc.site.yml                      |
| drush-alias-files.26      | /var/www/drush/sites/pls.site.yml                      |
| drush-alias-files.27      | /var/www/drush/sites/quantum.site.yml                  |
| drush-alias-files.28      | /var/www/drush/sites/responder.site.yml                |
| drush-alias-files.29      | /var/www/drush/sites/returntowork.site.yml             |
| drush-alias-files.30      | /var/www/drush/sites/rotc.site.yml                     |
| drush-alias-files.31      | /var/www/drush/sites/sc_programs.site.yml              |
| drush-alias-files.32      | /var/www/drush/sites/seaborg.site.yml                  |
| drush-alias-files.33      | /var/www/drush/sites/slpsolicitation.site.yml          |
| drush-alias-files.34      | /var/www/drush/sites/spotlight.site.yml                |
| drush-alias-files.35      | /var/www/drush/sites/summerstemintern.site.yml         |
| drush-alias-files.36      | /var/www/drush/sites/supplychain.site.yml              |
| drush-alias-files.37      | /var/www/drush/sites/training.site.yml                 |
| drush-alias-files.38      | /var/www/drush/sites/www.site.yml                      |
| drush-cache-directory     | /home/docker/.drush/cache                              |
| drush-conf.0              | /var/www/vendor/drush/drush/drush.yml                  |
| drush-conf.1              | /var/www/drush/drush.yml                               |
| drush-conf.2              | /var/www/docroot/sites/default/local.drush.yml         |
| drush-script              | /var/www/vendor/drush/drush/drush                      |
| drush-temp                | /tmp                                                   |
| drush-version             | 9.7.2                                                  |
| files                     | sites/default/files                                    |
| install-profile           | llnl_lightning                                         |
| modules                   | sites/all/modules                                      |
| php-bin                   | /usr/local/bin/php                                     |
| php-conf.1                | false                                                  |
| php-os                    | Linux                                                  |
| private                   | /var/www/files-private                                 |
| root                      | /var/www/docroot                                       |
| site                      | sites/default                                          |
| stacks.drupal-vm.inited   | false                                                  |
| stacks.dev-desktop.inited | false                                                  |
| temp                      | /tmp                                                   |
| theme                     | sienna                                                 |
| themes                    | sites/all/themes                                       |
| uri                       | http://default                                         |
+---------------------------+--------------------------------------------------------+
+---------------------------------------+--------------------------------------------------------------+
| Check                                 | Problem                                                      |
+---------------------------------------+--------------------------------------------------------------+
| BehatCheck:checkLocalConfig:exists    | tests/behat/local.yml is missing!                            |
|                                       |   Run `blt tests:behat:init:config` to generate it from      |
|                                       | example.local.yml.                                           |
| ComposerCheck:acquia/blt-require-dev  | acquia/blt-require-dev is not defined as a development       |
|                                       | dependency in composer.json                                  |
|                                       |   Move add acquia/blt-require-dev to the require-dev object  |
|                                       | in composer.json.                                            |
|                                       |   This is necessary for BLT to run development tasks.        |
| ComposerCheck:composer.autoload.psr-4 | The Composer configuration for autoload.psr-4 differs from   |
|                                       | BLT's default, recommended values.                           |
|                                       |   Change your configuration to match BLT's defaults in       |
|                                       |                                                              |
|                                       | vendor/acquia/blt/subtree-splits/blt-project/composer.json.  |
| NodeCheck:checkNodeVersionFileExists  | Neither .nvmrc nor .node-version file found in repo root.    |
| SimpleSamlPhpCheck:checkSimpleSamlPhp | /var/www/vendor/simplesamlphp/simplesamlphp/metadata/saml20- |
|                                       | idp-remote.php is missing. Run `blt                          |
|                                       | source:build:simplesamlphp-config`.                          |
| WebUriCheck:checkUriResponse          | Did not get a response from http://default                   |
|                                       | Is your *AMP stack running?                                  |
|                                       | Is your /etc/hosts file correctly configured?                |
|                                       | Is your web server configured to serve this URI from         |
|                                       | /var/www/docroot?                                            |
|                                       | Is options.uri set correctly in                              |
|                                       | /var/www/docroot/sites/default/local.drush.yml?              |
+---------------------------------------+--------------------------------------------------------------+
[error]  BLT Doctor discovered one or more critical issues.
For troubleshooting guidance and support, see https://docs.acquia.com/blt/support/ 

System information

Current work around: disabled git hooks pre-push and bypass git commit hooks when committing composer files.

mikemadison13 commented 4 years ago

Curious, are you by chance using a application such as Source Tree for Git? I have this issue pretty commonly, and it's to do with the way PHP versions are parsing code in Source tree (vs. if you do a commit directly in the command line).

See https://community.atlassian.com/t5/Bitbucket-questions/SourceTree-Hook-failing-because-paths-don-t-seem-to-be-set/qaq-p/274792

shelane commented 4 years ago

I am using SourceTree.

It actually looked like it was failing at:

[ExecStack] Running composer validate --no-check-all --ansi in *****
sh: composer: command not found

which the **** is my git remote location.

mikemadison13 commented 4 years ago

i would suggest trying to run the same command directly from your command line and see if it works there vs. in source tree. that's the behavior i see. it's actually "fine" from the terminal in my case, but something about the php version in source tree fails (every time).

lpeabody commented 4 years ago

@shelane Also keep in mind if you are using your default BLT git hooks, they are executing on the host git client (not git in the container) if using a GUI like SourceTree or Fork. You will need to override BLT's git hooks with your own copies that do effectively the same thing, but each hook runs its checks using container resources. I do this in my Metis project with Docksal:

blt.yml override specifying each hook should be installed from custom scripts stored in blt/scripts/git-hooks: https://github.com/lpeabody/Metis/blob/develop/blt/blt.yml#L30

Custom hook files https://github.com/lpeabody/Metis/tree/develop/blt/scripts/git-hooks

With that configuration and those files, when blt setup runs it installs the git hooks I've created (which include logic for getting the same results but executed with fin exec) instead of BLT's default git hooks.

shelane commented 4 years ago

Thanks @lpeabody , but it still has an issue in SourceTree. It now says fin command not found.

danepowell commented 4 years ago

Do you have Composer installed on the host machine? What happens when you run composer from the host (ignoring BLT for the moment)?

Composer must be properly configured on any environment touching BLT, including the host machine if you are working on a VM. I don't know that that can change. If you don't want to use Composer on the host, you'll need to disable the Git hooks.

no-response[bot] commented 4 years ago

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.