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

`project` not working #1174

Closed fhnaumann closed 4 months ago

fhnaumann commented 4 months ago

I have a monorepo and in one folder of main repo I have my website with cypress tests. I want to use this action to run e2e tests in the folder.

name: Cypress E2E

on: [push]

jobs:
  cypress-run:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          project: ./folder
          build: npm run build
          start: npm start

This workflow fails in the cypress run step with the following message:

Error: Action failed. Missing package manager lockfile. Expecting one of package-lock.json (npm), pnpm-lock.yaml (pnpm) or yarn.lock (yarn) in working-directory /home/runner/work/NewChallenges/NewChallenges

I suspect this is because the action tries to do stuff in the root folder and not the specified subfolder. How can I solve this?

MikeMcC399 commented 4 months ago

@fhnaumann

In which directory is your lockfile package-lock.json located?

fhnaumann commented 4 months ago

Its in a subfolder under the root.

root
| - app1
| - app2
     | - package-lock.json
     | - cypress (...)

I solved it by setting working-directory: app2/, though I don't really know why this works. As far as I know working-directory does nothing for actions that use uses:, only for run: commands. Somewhere deep in your example files I found this syntax. I don't use project: at all with this as it messes with the path.

MikeMcC399 commented 4 months ago

@fhnaumann

For your repo structure, with the lockfile in a sub-directory, the Cypress GitHub Action option working-directory is the correct option to use. The README documentation section working-directory describes how this works.

The Cypress GitHub Action option project expects to find a lockfile in the root of the repository. This is the reason for your original error message. The Cypress CLI documenation provides an example structure under cypress-io/cypress-test-nested-projects to demonstrate this.

Please let us know if you think that there are any errors in the documentation, otherwise I suggest to close this issue since you say that you have solved your issue by changing the workflow parameters.

fhnaumann commented 4 months ago

Thanks for your clarification. I don't know how I missed the big working-directory section in the README...

MikeMcC399 commented 4 months ago

@fhnaumann

Thanks for your clarification.

You're welcome! 🙂

I don't know how I missed the big working-directory section in the README...

The documentation for the project option could be improved to make it clearer. I will put that on my to-do list.