Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hard coded Node.js version #489

Closed
RobinKnipe opened this issue Jan 23, 2022 · 17 comments
Closed

Hard coded Node.js version #489

RobinKnipe opened this issue Jan 23, 2022 · 17 comments
Assignees

Comments

@RobinKnipe
Copy link

The config in action.yml overrides any previously set node version (e.g. via actions/setup-node):

using: 'node12'

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).

@rbayliss
Copy link

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.

@RobinKnipe
Copy link
Author

RobinKnipe commented Jan 25, 2022

@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.

@rbayliss
Copy link

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: #484. We're likely to still be dealing with unexpected node versions, but probably not v12 anymore.

kevinold pushed a commit that referenced this issue Feb 2, 2022
…ainer node version instead of the GitHub Action version of node (currently node v16)

Per #489 (comment)
@h2oearth
Copy link

h2oearth commented Jun 2, 2022

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

admah pushed a commit that referenced this issue Jun 2, 2022
…ainer node version instead of the GitHub Action version of node (currently node v16)

Per #489 (comment)
younho9 added a commit to younho9/notion-url-shortener that referenced this issue Jun 4, 2022
younho9 added a commit to younho9/notion-url-shortener that referenced this issue Jun 4, 2022
@willitsw
Copy link

willitsw commented Jun 6, 2022

Also facing this issue with Cypress 10.

@einSelbst
Copy link

@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

@MikeMcC399

This comment was marked as outdated.

@ricardo-dematos
Copy link

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:

github-action/action.yml

Lines 99 to 101 in d69252d

runs:
using: 'node16'
main: 'dist/index.js'

Since we are using badeball/cypress-cucumber-preprocessor@v18.0.1, 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)

@MikeMcC399
Copy link
Collaborator

MikeMcC399 commented Jul 11, 2023

@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 (#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
Copy link
Collaborator

@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.

@lmiller1990
Copy link
Contributor

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.

@MikeMcC399
Copy link
Collaborator

@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 docs: explain node.js usage #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.

@lmiller1990
Copy link
Contributor

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

@lmiller1990
Copy link
Contributor

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.

@ricardo-dematos
Copy link

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! 👍

@lmiller1990
Copy link
Contributor

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.

@ricardo-dematos
Copy link

ricardo-dematos commented Jul 17, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants