Add conditional execution

Created on 8 June 2023, over 1 year ago
Updated 27 July 2023, over 1 year ago

Problem/Motivation

I'd like to be able to conditionally run parts of the recipe. My specific use case is to first ask the user for input:
Would you like to install the end-to-end tests for Cypress? (y/N)

That's handled by https://www.drupal.org/project/distributions_recipes/issues/3303126 Make it possible for recipes to prompt for input values Fixed .

Then, given the result (which might also be passed to the recipe as an argument), I'd like to optionally call a second script that installs the end-to-end tests.

Proposed resolution

This SO question has a few ways other projects have added conditions to their YAML files:
https://stackoverflow.com/questions/54194104/if-condition-possible-in-ya...

Something like this would be a great start:

- ask_user: "Install Cypress end-to-end tests? (y/N) "
  - var: $INSTALL_TESTS
  - default: "N"
- if: ('$INSTALL_TESTS == "Y"' || $INSTALL_TESTS == "y")
   - run_recipe: "CK_Install_Tests"

Even more ambitious would be to include IF/ELSE logic:

- ask_user: "Install Cypress or Playwright end-to-end tests? (cypress/playwright/NONE) "
  - var: $INSTALL_TESTS
  - default: "NONE"
- if: ('$INSTALL_TESTS == "cypress"')
    - run_recipe: "CK_Install_Cypress_Tests"
  - else if: ('$INSTALL_TESTS == "playwright"')
     - run_recipe: "CK_Install_Playwright_Tests"
Feature request
Status

Closed: won't fix

Version

10.0

Component

Code

Created by

🇺🇸United States aangel

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @aangel
  • Status changed to Closed: won't fix over 1 year ago
  • 🇺🇸United States thejimbirch Cape Cod, Massachusetts

    Updating as this was discussed in Slack.

    https://drupal.slack.com/archives/C2THUBAVA/p1686243538206249

    André Angelantoni
    Just watched the video. Nice work and the strategic designs decisions seems solid to me. Here is a use case I have.

    Once I get v1.0 of Automated Testing Kit released, I’m going to add E2E tests to Campaign Kit. When that’s done, I’d like try out Recipes. Looking ahead, now that E2E testing is so much easier, let’s assume that E2E tests (written in Cypress, Playwright, ) will increasingly be bundled with modules or distributions.

    Right now I have a setup script that copies or links the bundled support files and tests into their proper location for Cypress or Playwright to see them. The destination directories are typically in the root of the project (i.e. above web/docroot). BTW, the tests are not just for developers as there is nothing stopping DevOps from running them regularly when the site is live, too.

    This seems to be a prime candidate for a recipe.

    However, this should be optional. That means I’ll need two recipes: one to install the module and configure it and another that installs the tests and configures those. The user will need to run one then the other sequentially.

    It seems to me that two features would be excellent to make this easier: the ability to accept user input/accept an argument and conditional logic. It still makes sense to have two recipes but the first one would check the argument/user input before calling the second one.

    Would you like to install the end-to-end tests for Cypress? (y/N)
    Poking around, it seems others have introduced conditionals in yml files:
    https://stackoverflow.com/questions/54194104/if-condition-possible-in-ya...
    Thoughts?

    thejimbirch
    Hi André,
    The current idea, in order to keep recipes as simple as possible, would be to create dependent recipes.
    Recipe that has tests
    Recipe that has module install/configuration
    Recipe that installs both.

    bircher
    or simply make the test one appl the one with the modules first...

    André Angelantoni
    Sorry, just seeing that you responded.
    That will definitely work for version 1. I suspect that eventually more people will request an If/then structure so that people aren’t maintaining multiple recipes. (It seems to me to be the next logical progression.)
    Either way, looking forward to playing with it :-)

Production build 0.71.5 2024