github-action icon indicating copy to clipboard operation
github-action copied to clipboard

Hard coded Node.js version

Open RobinKnipe opened this issue 3 years ago • 6 comments

The config in action.yml overrides any previously set node version (e.g. via actions/setup-node): https://github.com/cypress-io/github-action/blob/ffbc3616ae4754115d05d414810ff4a8e48fc6de/action.yml#L87

This causes failures if the project requires a more recent version, or it depends on a recent version of @cypress/react >= v5.7.0

Ideally the action should use any version of node already available, or have a configuration switch to explicitly set the desired version (similar to actions/setup-node).

RobinKnipe avatar Jan 23 '22 14:01 RobinKnipe

I can second this issue. It seems to be happening because of this commit, combined with the fact that this action uses the Cypress node API rather than executing it as a CLI command.

Not sure exactly how to fix this, but a temporary workaround seems to be adding a command-prefix, which triggers invoking the tests with the CLI. Eg:

- name: Cypress Tests
  uses: cypress-io/github-action@v2
  with:
    record: true
    command-prefix: "--"

This is a backdoor that ends up running a cypress command like:

npx -- cypress run ...

Not sure what the side effects of this are (we're still testing it now), but I can confirm that when run this way, it invokes with the system node version rather than the action's node version.

rbayliss avatar Jan 25 '22 16:01 rbayliss

@rbayliss good shout. In case it's of interest, I found a similar workaround by explicitly adding a command config, even if it just does a basic cypress run, i.e. command: npx cypress run will also use a preconfigured node version instead of the hard-coded v12.

RobinKnipe avatar Jan 25 '22 16:01 RobinKnipe

Just wanted to note that the nature of this issue is about to change a bit, since the bump to Node 16 just got merged into this action: https://github.com/cypress-io/github-action/pull/484. We're likely to still be dealing with unexpected node versions, but probably not v12 anymore.

rbayliss avatar Jan 31 '22 20:01 rbayliss

This issue is still present in Cypress 10:-(. I use Node 14.x, but some how cypress was falling back to Node 12.x

h2oearth avatar Jun 02 '22 09:06 h2oearth

Also facing this issue with Cypress 10.

willitsw avatar Jun 06 '22 17:06 willitsw

@h2oearth @willitsw guys please check if you're using a container with an old node version. This is the case in the cypress github action example code.

container: cypress/browsers:node12.18.3-chrome87-ff82

Here is a list with the available node versions, up to node 17 as of today https://github.com/cypress-io/cypress-docker-images/tree/master/browsers

einSelbst avatar Jun 25 '22 22:06 einSelbst

This issue hasn't been addressed. It is not covered in the README documentation and the workflow .github/workflows/example-node-versions.yml doesn't notice the problem even though the only version of Node.js used is 16.13.0 despite the matrix definition node: [14, 16, 18].

Are there any plans to fix this in any way, either by removing it as an option from the documentation or by making it work according to the documentation?

MikeMcC399 avatar Dec 05 '22 16:12 MikeMcC399

Before the cypress-io/github-action@v5 step, I'm setting up Node to v18 and installing our dependencies.

In the log I noticed that the reported Node Version is v16:

Cache restored successfully
/opt/hostedtoolcache/node/18.16.1/x64/bin/npm ci

added 192 packages, and audited 193 packages in 3s

47 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
/opt/hostedtoolcache/node/18.16.1/x64/bin/npx cypress cache list
┌─────────┬───────────────────┐
│ version │ last used         │
├─────────┼───────────────────┤
│ 12.16.0 │ a few seconds ago │
└─────────┴───────────────────┘

DevTools listening on ws://127.0.0.1:41219/devtools/browser/53789577-c80b-4b36-9339-d62846772d7d

====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:        12.16.0                                                                        │
  │ Browser:        Firefox 114 (headless)                                                         │
  │ Node Version:   v16.16.0 (/home/runner/runners/2.305.0/externals/node16/bin/node)              │
  │ Specs:          3 found (login-message.cy.ts, login.cy.ts, reset-password.cy.ts)               │
  │ Searched:       **/*.cy.ts                                                                     │
  │ Experiments:    experimentalMemoryManagement=true                                              │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘

Which matches the version defined in the action: https://github.com/cypress-io/github-action/blob/d69252d52b9a31bad4f418f05ba2bc83687a02eb/action.yml#L99-L101

Since we are using badeball/[email protected], which requires Node v18, because it uses findLastIndex(), the cypress-io/github-action@v5 step fails:

     CypressError: `cy.task('cypress-cucumber-preprocessor:spec-envelopes')` failed with the following error:

> state.messages.findLastIndex is not a function

https://on.cypress.io/api/task

Because this error occurred during a `before all` hook we are skipping the remaining tests in the current suite: `Specifications`
      at <unknown> (***/__cypress/runner/cypress_runner.js:151199:78)
      at tryCatcher (***/__cypress/runner/cypress_runner.js:18744:23)
      at Promise._settlePromiseFromHandler (***/__cypress/runner/cypress_runner.js:16679:31)
      at Promise._settlePromise (***/__cypress/runner/cypress_runner.js:16736:18)
      at Promise._settlePromise0 (***/__cypress/runner/cypress_runner.js:16781:10)
      at Promise._settlePromises (***/__cypress/runner/cypress_runner.js:16857:18)
      at _drainQueueStep (***/__cypress/runner/cypress_runner.js:13451:12)
      at _drainQueue (***/__cypress/runner/cypress_runner.js:13444:9)
      at ../../node_modules/bluebird/js/release/async.js.Async._drainQueues (***/__cypress/runner/cypress_runner.js:13460:5)
      at Async.drainQueues (***/__cypress/runner/cypress_runner.js:13330:14)
  From Your Spec Code:
      at taskSpecEnvelopes (***/__cypress/tests?p=cypress/***/specifications/specifications.feature:14009:14)
      at Context.beforeHandler (***/__cypress/tests?p=cypress/***/specifications/specifications.feature:14375:9)
      at Context.eval (***/__cypress/tests?p=cypress/***/specifications/specifications.feature:14070:27)
  
  From Node.js Internals:
    TypeError: state.messages.findLastIndex is not a function
        at specEnvelopesHandler (/home/runner/work/vali/vali/***-tests/node_modules/@badeball/cypress-cucumber-preprocessor/dist/plugin-event-handlers.js:269:57)
        at invoke (/home/runner/.cache/Cypress/12.16.0/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/run_plugins.js:246:16)
        at <unknown> (/home/runner/.cache/Cypress/12.16.0/Cypress/resources/app/node_modules/@packages/server/lib/plugins/util.js:59:14)
        at tryCatcher (/home/runner/.cache/Cypress/12.16.0/Cypress/resources/app/node_modules/bluebird/js/release/util.js:16:23)
        at Function.Promise.attempt.Promise.try (/home/runner/.cache/Cypress/12.16.0/Cypress/resources/app/node_modules/bluebird/js/release/method.js:39:29)
        at Object.wrapChildPromise (/home/runner/.cache/Cypress/12.16.0/Cypress/resources/app/node_modules/@packages/server/lib/plugins/util.js:58:23)
        at RunPlugins.taskExecute (/home/runner/.cache/Cypress/12.16.0/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/run_plugins.js:252:10)
        at RunPlugins.execute (/home/runner/.cache/Cypress/12.16.0/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/run_plugins.js:166:21)
        at EventEmitter.<anonymous> (/home/runner/.cache/Cypress/12.16.0/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/run_plugins.js:56:12)
        at EventEmitter.emit (node:events:527:28)
        at EventEmitter.emit (node:domain:475:12)
        at process.<anonymous> (/home/runner/.cache/Cypress/12.16.0/Cypress/resources/app/node_modules/@packages/server/lib/plugins/util.js:33:22)
        at process.emit (node:events:527:28)
        at process.emit (node:domain:475:12)
        at process.emit.sharedData.processEmitHook.installedValue [as emit] (/home/runner/.cache/Cypress/12.16.0/Cypress/resources/app/node_modules/@cspotcode/source-map-support/source-map-support.js:745:40)
        at emit (node:internal/child_process:938:14)
        at processTicksAndRejections (node:internal/process/task_queues:84:21)

ricardo-dematos avatar Jul 11 '23 15:07 ricardo-dematos

@ricardo-dematos

If you want to log your cucumber issue separately, we could take a look to see if there is some workaround which may be used.

Edit: We would need a specific example which is failing in github-action. I chose a random test https://github.com/badeball/cypress-cucumber-preprocessor/tree/master/examples/ct-webpack-react-ts and successfully ran it in github-action@v5.

There is an old comment in this issue from me which I wrote before I began to understand how the JavaScript action github-action worked. I have hidden that comment now, since it does not help so much.

GitHub has been asked to provide a later Node.js version after Node.js 16 (see https://github.com/orgs/community/discussions/58226) for JavaScript Actions to work with, however they have not yet responded with any concrete commitments. I would assume that if/when GitHub announces and releases updated support that there would be a new version of github-action released which would run under whatever GitHub provides (18? 20?).

Probably this issue (https://github.com/cypress-io/github-action/issues/489) should be closed, because it is an architectural restriction of github-action being a GitHub JavaScript Action that the action's Node.js version is hard-coded. It is only Cypress itself which runs under this Node.js version. Other steps which are spawned by other options of github-action actually run under the runner's version of Node.js. Possibly we could make use of that for cucumber.

MikeMcC399 avatar Jul 11 '23 16:07 MikeMcC399

@ricardo-dematos

Using the github-action command option, Cypress can be run using the Node.js version set up in the runner instead of node16 specified by the JavaScript Action definition.

Please note however the restrictions described in the README for command, as this option by-passes many other options. It should give you a workaround for badeball/cypress-cucumber-preprocessor until GitHub provides a migration path to later Node.js versions.

If you have questions about this, I suggest moving to a separate issue for clarity.

MikeMcC399 avatar Jul 11 '23 18:07 MikeMcC399

I read through this issue. Is there something for us to do in our GH Action? It looks like you can choose the version from the ones GH supports. I'm not entirely clear if 18 is supported right now (conflicting info). If it is, you should be able to choose that one. If not, it would be blocked, but not by us.

lmiller1990 avatar Jul 12 '23 22:07 lmiller1990

@lmiller1990

I read through this issue. Is there something for us to do in our GH Action? It looks like you can choose the version from the ones GH supports. I'm not entirely clear if 18 is supported right now (conflicting info). If it is, you should be able to choose that one. If not, it would be blocked, but not by us.

  • One action would be to document the Node.js usage in the README > Node.js Support section. I have made a proposal in PR https://github.com/cypress-io/github-action/pull/961, which you are welcome to review.
  • Perhaps the document changes in the PR will also clear up your uncertainty about the support of Node.js 18? github-action@v5 can be called from a workflow environment set up for Node.js 18. Node versions example shows this working. This is currently the default version for GitHub-hosted runners. If Cypress is being run from github-action@v5 in its default mode, then the Cypress Module API call is made using the GitHub setting runs.using node16 for this action. This is currently the only version made available by GitHub for this purpose.

MikeMcC399 avatar Jul 13 '23 06:07 MikeMcC399

Looks like documenting this is the only actionable item here. Thanks for the PR!

lmiller1990 avatar Jul 14 '23 01:07 lmiller1990

Looks like we are at the mercy of GH to give us Node.js 18 in their actions. I think the PR doc clarifies; i don't see an other work to do at this point in time, so I will close this.

lmiller1990 avatar Jul 14 '23 01:07 lmiller1990

Sorry to reply in a closed issue, but this still has more to discuss and I feel it's the correct issue for that.


@MikeMcC399 from reading #642 and your comments in other issues, I fully understand why cypress-io/github-action uses Node.js v16 to execute Cypress and not a previous setup Node.js version.


@ricardo-dematos

Using the github-action command option, Cypress can be run using the Node.js version set up in the runner instead of node16 specified by the JavaScript Action definition.

Please note however the restrictions described in the README for command, as this option by-passes many other options. It should give you a workaround for badeball/cypress-cucumber-preprocessor until GitHub provides a migration path to later Node.js versions.

Yes, but as you point out, then almost all other options are irrelevant.

This

      - name: 'Run end-to-end tests'
        id: cypress
        timeout-minutes: 15  # must be adjusted with e2e tests progress
        uses: cypress-io/github-action@v5
        env:
          ELECTRON_EXTRA_LAUNCH_ARGS: '--disable-gpu'  # see https://github.com/cypress-io/cypress/issues/25357
        with:
          working-directory: 'e2e-tests'
          browser: '${{ steps.setup.outputs.browser }}'
          headed: false
          config: 'video=false'  # see https://github.com/cypress-io/github-action/issues/483
          env: 'host="${{ inputs.deployment_url }}",username="${{ inputs.deployment_username }}",password="${{ inputs.deployment_password }}"'

must be changed to something like this

      - name: 'Run end-to-end tests'
        id: cypress
        timeout-minutes: 15  # must be adjusted with e2e tests progress
        uses: cypress-io/github-action@v5
        env:
          ELECTRON_EXTRA_LAUNCH_ARGS: '--disable-gpu'  # see https://github.com/cypress-io/cypress/issues/25357
        with:
          working-directory: 'e2e-tests'
          command: 'npx cypress run -- --e2e --browser ${{ inputs.browser }} --headless --config "video=false" --env "host="${{ inputs.deployment_url }}",username="${{ inputs.deployment_username }}",password="${{ inputs.deployment_password }}""'

which is less elegant and prone to issues #272 , #473 and #594 .


I tried command-prefix: '--' , as suggested by @rbayliss , and although it uses the previous setup Node.js version, it results in Error: The process '/opt/hostedtoolcache/node/18.16.1/x64/bin/npx' failed with exit code 2 . This error prevents the job summary from being printed.

image


After reading issue #23 and its resolution through #24 , I tried setting the cache-key to the one defined by actions/setup-node , which follows the pattern node-cache-${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }} , while cypress-io/github-action uses the pattern npm-${{ toLowerCase(runner.os) }}-${{ runner.arch }}-${{ hash(?) }} .

It didn't work as a way to force using the previous setup Node.js .


@MikeMcC399 your replies have been invaluable to understand this GH Action, how to work around some perks and get the most out of it. Kudos! 👍

ricardo-dematos avatar Jul 14 '23 19:07 ricardo-dematos

which is less elegant and prone to issues #272 , #473 and #594 .

We can definitely accept a PR improving the GH Action! It looks like you tried but no luck. I also don't fully grok why that would fix / make us less prone to those issues.

Error: The process '/opt/hostedtoolcache/node/18.16.1/x64/bin/npx' failed with exit code 2

I think exit code 2 is something to with failed dependencies installation.

We can re-open if you think there's a good path forward to properly resolving this.

lmiller1990 avatar Jul 16 '23 22:07 lmiller1990

We can definitely accept a PR improving the GH Action!

Sorry, but I don't have the knowledge to accomplish that. 😓

It looks like you tried but no luck. I also don't fully grok why that would fix / make us less prone to those issues.

When using the command setting, one cannot break the command in several lines to facilitate reading (#272), one cannot use quotes, or at least they cause problems (#473), and cannot take full advantage from Cypress Cloud features (#594).

I understand why the command setting exists, but it must be used carefully.

Error: The process '/opt/hostedtoolcache/node/18.16.1/x64/bin/npx' failed with exit code 2

I think exit code 2 is something to with failed dependencies installation.

Before the 'Run end-to-end tests' step, we are executing this step:

      - name: 'Install dependencies'  # see https://docs.cypress.io/guides/continuous-integration/introduction#Dependencies
        id: dependencies
        run: 'sudo apt-get --quiet --no-install-recommends --assume-yes install libgtk2.0-0 libnotify-dev'
        shell: 'bash'

Note that the remaining dependencies are already present in the ubuntu-latest runner.

Also note that the exit code matches the number of failed tests.

ricardo-dematos avatar Jul 17 '23 09:07 ricardo-dematos