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

Cypress Actions keep failing #912

Closed ErhartFabian closed 1 year ago

ErhartFabian commented 1 year ago

I have this problem when I try to use github actions (cypress) in a first personal project

Run cypress-io/github-action@v4
Received 37748736 of 167729172 (22.5%), 36.0 MBs/sec
Received 167729172 of 167729172 (100.0%), 82.1 MBs/sec
Cache Size: ~160 MB (167729172 B)
/usr/bin/tar -z -xf /home/runner/work/_temp/5a4c5741-a5c2-422b-8437-76f45454ea64/cache.tgz -P -C /home/runner/work/first-project-cypress/first-project-cypress
Cache restored successfully
Received 12136133 of 12136133 (100.0%), [27](https://github.com/ErhartFabian/first-project-cypress/actions/runs/4955941314/jobs/8865828574#step:3:28).7 MBs/sec
Cache Size: ~12 MB (12136133 B)
/usr/bin/tar -z -xf /home/runner/work/_temp/c7c0f32f-91cd-4f0c-add0-bbb70b057d06/cache.tgz -P -C /home/runner/work/first-project-cypress/first-project-cypress
Cache restored successfully
/usr/local/bin/yarn --frozen-lockfile
yarn install v1.22.19
warning package.json: No license field
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
warning No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
Done in 2.91s.
/usr/local/bin/npx cypress cache list
┌─────────┬──────────────┐
│ version │ last used    │
├─────────┼──────────────┤
│ 12.9.0  │ a minute ago │
└─────────┴──────────────┘
start server "npm start command "npm start"
current working directory "/home/runner/work/first-project-cypress/first-project-cypress"
waiting on "http://localhost:3000" with timeout of 60 seconds
/usr/local/bin/npm start
npm ERR! Missing script: "start"
npm ERR! 
npm ERR! Did you mean one of these?
npm ERR!     npm star # Mark your favorite packages
npm ERR!     npm stars # View packages marked as favorites
npm ERR! 
npm ERR! To see a list of scripts, run:
npm ERR!   npm run

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2023-05-12T06_35_42_263Z-debug-0.log
/home/runner/work/_actions/cypress-io/github-action/v4/dist/index.js:4323
                error = new Error(`The process '${this.toolPath}' failed with exit code ${this.processExitCode}`);
                        ^

Error: The process '/usr/local/bin/npm' failed with exit code 1
    at ExecState._setResult (/home/runner/work/_actions/cypress-io/github-action/v4/dist/index.js:4323:25)
    at ExecState.CheckComplete (/home/runner/work/_actions/cypress-io/github-action/v4/dist/index.js:4306:18)
    at ChildProcess.<anonymous> (/home/runner/work/_actions/cypress-io/github-action/v4/dist/index.js:4200:27)
    at ChildProcess.emit (node:events:527:[28](https://github.com/ErhartFabian/first-project-cypress/actions/runs/4955941314/jobs/8865828574#step:3:29))
    at maybeClose (node:internal/child_process:1092:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:[30](https://github.com/ErhartFabian/first-project-cypress/actions/runs/4955941314/jobs/8865828574#step:3:31)2:5)

does anyone know how to solve it?

MikeMcC399 commented 1 year ago

@ErhartFabian

I can see multiple issues in your logs. I suggest that you look at the examples to see how the action should be used. Fork and clone the repository then run the examples.

  1. You are using an old version v4. The current version is v5.
  2. yarn is telling you
    yarn install v1.22.19
    warning package.json: No license field
    warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
    warning No license field
  3. Missing script
    /usr/local/bin/npm start
    npm ERR! Missing script: "start"
    npm ERR! 
    npm ERR! Did you mean one of these?
    npm ERR!     npm star # Mark your favorite packages
    npm ERR!     npm stars # View packages marked as favorites
    npm ERR! 
    npm ERR! To see a list of scripts, run:
    npm ERR!   npm run

You may need to invest some time in taking some Cypress training to understand how the pieces fit together.

https://docs.cypress.io/guides/continuous-integration/github-actions contains some instructions for getting started with the github-action, however it does assume a working knowledge of Cypress.

There is also a Discord chat available to get help.

MikeMcC399 commented 1 year ago

To be more explicit about the examples you can compare with

https://github.com/cypress-io/github-action/blob/master/.github/workflows/example-start.yml

uses

  start:
    # example with web application build,
    # server start and waiting for the server
    # to respond before running tests
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Cypress tests
        uses: ./
        with:
          working-directory: examples/start
          build: npm run build
          start: npm start
          wait-on: 'http://localhost:3000'

and it calls on https://github.com/cypress-io/github-action/blob/master/examples/start/package.json with

  "scripts": {
    "test": "cypress run",
    "build": "echo building ... server ... done!",
    "start": "serve public",
    "start2": "serve -p 8000 public"
  },

In order to fix your problems you need to decide whether you want to be using npm or Yarn and then delete the lock file which you are not using.

You need to add a start script to package.json.

Unless you think that there is a bug in github-action I would also suggest to close this issue.

ErhartFabian commented 1 year ago

@MikeMcC399 thanks! I think that I would use discord, I read the document on cypress but it does not mention anything on the script part of the package.json file thanks for your help!

MikeMcC399 commented 1 year ago

@ErhartFabian

There is a lot to learn when you start with Cypress.

You can find scripts mentioned in the documentation on https://docs.cypress.io/guides/continuous-integration/introduction

ErhartFabian commented 1 year ago

@MikeMcC399 I resolve the package-lock.json and used the script example but I´m still having problems, hope somebody help me on discord :(

MikeMcC399 commented 1 year ago

@ErhartFabian

It seems that you have some knowledge gaps and you would probably benefit from following a training course.