drainpipe icon indicating copy to clipboard operation
drainpipe copied to clipboard

Add a dependency on drupal:composer on all commands that use drush

Open deviantintegral opened this issue 3 years ago • 3 comments

If someone runs a drupal command, and composer's install is out of date, we should run composer automatically. We can do this by adding a dependency on the composer task in all drupal tasks.

This is most helpful on locals that have persistent checkouts, and not CI or other environments.

deviantintegral avatar Mar 31 '23 13:03 deviantintegral

Here's an example of a composer install task that automatically skips if composer is up to date:

  override:drupal:composer:
    desc: Install composer dependencies
    summary: |
      This command is typically used when a developer updates their local after
      pulling new changes from source control. Generally when bootstrapping a
      fresh clone of the site from git, you'll need to run `composer install`
      anyway to get task and drainpipe.
    cmds:
      - |
        # We use the COMPOSER_NO_DEV environment variable to control production
        # builds.
        # https://getcomposer.org/doc/03-cli.md#composer-no-dev
        # We set it in case task is using the "alternate" syntax, including
        # when we call task via `ddev task`.
        export COMPOSER_NO_DEV={{.COMPOSER_NO_DEV}}
        composer install --optimize-autoloader
    sources:
      - composer.json
      - composer.lock
    generates:
      - ./vendor/composer/installed.json
      - ./vendor/autoload.php
    status:
      - >
        {{if eq .COMPOSER_NO_DEV "1"}}
        test -f ./vendor/composer/installed.json && grep -q '"dev": false' ./vendor/composer/installed.json
        {{else}}
        test -f ./vendor/composer/installed.json && grep -q '"dev": true' ./vendor/composer/installed.json
        {{end}}

deviantintegral avatar Feb 02 '24 18:02 deviantintegral

as #169 we can't do this because these tasks also run in remote environments

justafish avatar Feb 19 '24 14:02 justafish

I think you still need to run composer to get drush in the first place, even when running in remote environments.

deviantintegral avatar Feb 19 '24 15:02 deviantintegral