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
442 stars 394 forks source link

Pre-push git hook always exits with status 1 when using Docker to execute validate command #4015

Closed lpeabody closed 4 years ago

lpeabody commented 4 years ago

Describe the bug When executing blt in a non-TTY environment the validate command seems to always fail. This affects the pre-push git hook.

I work with Docksal, and commands are run in interactive vs non-interactive mode by doing the following:

fin exec ... vs fin exec -T ...

fin exec will also detect if the command is being executed in a non-TTY environment (i.e. in a pre-push git commit hook), and if it is then passing -T does not need to be done.

I am also using a GUI for working with Git, which uses git on the host and not in the container.

With that bit of knowledge out of the way, here's the output generated by the hook (again, this is executed on the host):

$ git push --progress --verbose origin refs/heads/develop:refs/heads/develop --tags

Executing .git/hooks/pre-push...
> validate
> tests:composer:validate
Pushing to git@github.com:lpeabody/Metis.git
[ExecStack] composer validate --no-check-all --ansi
Validating composer.json and composer.lock...
[ExecStack] Running composer validate --no-check-all --ansi in /var/www
./composer.json is valid
> tests:php:lint
Linting PHP files...
[ExecStack] Done in 1.203s
> tests:phpcs:sniff:all
............................................................  60 / 531 (11%)
............................................................ 120 / 531 (23%)
............................................................ 180 / 531 (34%)
............................................................ 240 / 531 (45%)
............................................................ 300 / 531 (56%)
............................................................ 360 / 531 (68%)
............................................................ 420 / 531 (79%)
............................................................ 480 / 531 (90%)
...................................................          531 / 531 (100%)

Time: 742ms; Memory: 14MB

> tests:yaml:lint:all
Validating yaml syntax for all custom modules and exported config...
Iterating over fileset files.yaml...
> tests:twig:lint:all
Validating twig syntax for all custom modules and themes...
All Twig files contain valid syntax.
> tests:deprecated:modules
[ExecStack] '/var/www/vendor/bin/phpcs'
[ExecStack] /var/www/vendor/bin/drupal-check -d /var/www/docroot/modules/custom
[ExecStack] Running /var/www/vendor/bin/drupal-check -d /var/www/docroot/modules/custom in /var/www
Checking for Deprecated Code in docroot/modules/custom

In Process.php line 1037:

  TTY mode requires /dev/tty to be read/writable.  

[ExecStack]  Exit code 1  Time 0.098s
[notice] Review Deprecation warnings and re-run.
[error]  Drupal Check in docroot/modules/custom failed.
check [--drupal-root [DRUPAL-ROOT]] [--format [FORMAT]] [-d|--deprecations] [-a|--analysis] [-s|--style] [--memory-limit [MEMORY-LIMIT]] [--no-progress] [--] <path> (<path>)...
For troubleshooting guidance and support, see https://docs.acquia.com/blt/support/ 

 Your code has failed pre-push validation. 
[error]  Command `tests:deprecated:modules ` exited with code 1. This most likely indicates a problem with your configuration, and is not a BLT bug.
For troubleshooting guidance and support, see https://docs.acquia.com/blt/support/ 
Enumerating objects: 15, done.
Delta compression using up to 8 threads
Total 8 (delta 5), reused 0 (delta 0)
remote: Resolving deltas:   0% (0/5)        
remote: Resolving deltas:  20% (1/5)        
remote: Resolving deltas:  40% (2/5)        
remote: Resolving deltas:  60% (3/5)        
remote: Resolving deltas:  80% (4/5)        
remote: Resolving deltas: 100% (5/5)        
remote: Resolving deltas: 100% (5/5), completed with 5 local objects.        
To github.com:lpeabody/Metis.git
   8521973..7567d7e  develop → develop
updating local tracking ref 'refs/remotes/origin/develop'

This is the contents of the pre-push hook:

#!/usr/bin/env bash

ROOT_DIR="$(pwd)/"

echo "Executing .git/hooks/pre-push..."
fin exec -T /var/www/vendor/bin/blt internal:git-hook:execute:pre-push --no-interaction

# Return the status of the last run command.
exit $?

The part that stands out is:

[ExecStack] Running /var/www/vendor/bin/drupal-check -d /var/www/docroot/modules/custom in /var/www
Checking for Deprecated Code in docroot/modules/custom

In Process.php line 1037:

  TTY mode requires /dev/tty to be read/writable.  

[ExecStack]  Exit code 1  Time 0.098s

I checked the permissions on /dev/tty in the container and see the following:

crw-rw-rw- 1 root root 5, 0 Feb 14 15:42 /dev/tty

So, things look okay, and I'm not sure where things might be going awry.

To Reproduce Steps to reproduce the behavior, ideally starting from a fresh install of BLT:

  1. In a non-interactive environment, execute /path/to/vendor/blt validate.
  2. Verify it exits with status 1.
  3. Re-run the command in an interactive enviroment.
  4. Verify it exits with status 0.

Expected behavior blt validate runs consistently in interactive and non-interactive environments.

Detailed error output blt -vvv validate outputs a lot so I put the contents in a gist. https://gist.github.com/lpeabody/32178a032b9aebca0701a23b7d37e2df

BLT doctor output

[les.peabody@~/Projects/metis (develop)]
-> fin exec blt doctor
+---------------------------+------------------------------------------------+
| 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/default                 |
| admin-theme               | seven                                          |
| alias-searchpaths.0       | /var/www/drush/sites                           |
| blt-version               | 11.1.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.2                                          |
| drush-alias-files.0       | /var/www/drush/sites/docksal.site.yml          |
| drush-cache-directory     | /home/docker/.drush/cache                      |
| drush-conf.0              | /home/docker/.drush/drush.yml                  |
| drush-conf.1              | /var/www/vendor/drush/drush/drush.yml          |
| drush-conf.2              | /var/www/drush/drush.yml                       |
| drush-conf.3              | /var/www/docroot/sites/default/local.drush.yml |
| drush-script              | /var/www/vendor/drush/drush/drush              |
| drush-temp                | /tmp                                           |
| drush-version             | 10.2.0                                         |
| files                     | sites/default/files                            |
| install-profile           | metis                                          |
| modules                   | sites/all/modules                              |
| php-bin                   | /usr/local/bin/php                             |
| php-conf.1                | false                                          |
| php-os                    | Linux                                          |
| private                   | /var/www/files-private/default                 |
| root                      | /var/www/docroot                               |
| site                      | sites/default                                  |
| stacks.drupal-vm.inited   | false                                          |
| stacks.dev-desktop.inited | false                                          |
| temp                      | /tmp                                           |
| theme                     | bartik                                         |
| themes                    | sites/all/themes                               |
| uri                       | http://default                                 |
+---------------------------+------------------------------------------------+
+---------------------------------------+--------------------------------------------------------------+
| Check                                 | Problem                                                      |
+---------------------------------------+--------------------------------------------------------------+
| BehatCheck:checkBaseUrl:uri           | base_url in tests/behat/local.yml does not match the site    |
|                                       | URI.                                                         |
|                                       |   Behat base_url is set to                                   |
|                                       | http://metis.docksal.                                        |
|                                       |   Drush site URI is set to                                   |
|                                       | http://default.                                              |
| 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.  |
| ConfigCheck:checkGitConfig            | Git repositories are not defined in blt.yml.                 |
|                                       |   Add values for git.remotes to blt.yml to enabled automated |
|                                       | deployment.                                                  |
| NodeCheck:checkNodeVersionFileExists  | Neither .nvmrc nor .node-version file found in repo root.    |
| 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

lpeabody commented 4 years ago

The culprit is drupal-check and the issue is already open here https://github.com/mglaman/drupal-check/issues/131 and here https://github.com/acquia/blt/issues/3996, so, closing this down.