cypress-io / github-action

GitHub Action for running Cypress end-to-end & component tests
https://on.cypress.io/guides/continuous-integration/github-actions
MIT License
1.35k stars 357 forks source link

Define Cypress custom script from the inputs #1216

Closed valyabogatyrova closed 1 month ago

valyabogatyrova commented 1 month ago

He team,

I'm trying to define the custom command to run based on the inputs

We support the test tags to run specific test or group of tests in diff specs and I have inputs based on that and after define the script to run tests. Could you advice what was missed as I cannot have predefined scripts in the package.json file to any possible situation of the entered data. Or it's impossible to run directly custom script in the actions?


  workflow_dispatch:
    inputs:
      spec_or_folder:
        description: 'Specify folder or separate spec to run'
        required: false
        default: 'cypress/e2e/**'
      tags_to_include:
        description: 'Run the tests based on the defined tags in the test'
        required: false
      tags_boolean_include_and:
        description: 'Include multiple tags into the run. Check it if you need use AND, default is OR'
        type: boolean
        required: false
        default: false

jobs:
  cypress-run:
    runs-on: ubuntu-latest
    name: Run Cypress Tests
    steps:      
    - name: Checkout repository
      uses: actions/checkout@v4
    - name: Install dependencies
      run: npm install
    - name: Run On Demand Cypress tests - with tags as AND
      if: ${{ !inputs.tags_boolean_include_and && inputs.tags_to_include != '' }}
      uses: cypress-io/github-action@v6
      with:
        command: CYPRESS_INCLUDE_TAGS=${{ inputs.tags_to_include }} npx cypress run ${{ inputs.spec_or_folder }} --browser chrome
MikeMcC399 commented 1 month ago

@valyabogatyrova

According to your workflow, you are not really using the functions of the action.

The action executes npm ci if it finds a package-lock.json, so this means there is probably a duplication of your npm install command.

    - name: Install dependencies
      run: npm install

The command option bypasses most functions of the action. See https://github.com/cypress-io/github-action/blob/master/README.md#custom-test-command. So the action has no influence on how your command is executed:

      with:
        command: CYPRESS_INCLUDE_TAGS=${{ inputs.tags_to_include }} npx cypress run ${{ inputs.spec_or_folder }} --browser chrome

This issue list is for bugs and enhancement requests to the action. Your post does not fall into this category however. Also, it looks like you may be using a plug-in to filter your selection, and again, questions for this usage would not belong here.

If you need community support for "how-to" questions you can reach out to the Cypress technical community on Discord Discord chat (click on button) where you can find many experienced users. Good luck!

valyabogatyrova commented 1 month ago

thanks for your review and advice! Note: the fix is very easy - just add CYPRESS_INCLUDE_TAGS to the env variables