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

Consider the used Node.js version for generating hashes (or provide a way to configure runtime hash inputs) #4124

Closed
ghost91- opened this issue Mar 8, 2023 · 9 comments · Fixed by #7072
Labels
area: caching Issues reported about incorrect cache hits or misses area: ergonomics Issues and features impacting the developer experience of using turbo owned-by: turborepo

Comments

@ghost91-
Copy link

ghost91- commented Mar 8, 2023

Which project is this feature idea for?

Turborepo

Describe the feature you'd like to request

At the moment, Turborepo does not consider the used Node.js version as hash input. This can lead to undesirable situations where CI is set up to execute tasks in multiple different Node.js versions, to ensure that the package works in all of them, but then the task is only ever really executed in one of them, because in the others, it's fetched from the cache.

For this reason, the used Node.js version should be considered an input for every generated hash.

Of course, depending on the repo setup, there could be a lot more runtime context that should be considered a hash input (e.g. arch, OS, etc.). For that reason, it would also make sense to allow users to configure arbitrary runtime inputs, similar to globalEnv and globalDependencies on the global level and env on the per-task level.

For comparison and reference: Nx already provides this feature: https://nx.dev/concepts/how-caching-works#runtime-hash-inputs

Describe the solution you'd like

Ideally, there is a new optional configuration property globalRuntime where users can specify a list of commands to be executed. When turbo is run, those commands are executed and their output is used as an input for all hashes. If the property is not given, Turborepo uses just the command node -v.

Example of how the config could look:

{
  "$schema": "https://turbo.build/schema.json",
  "pipeline": {
    // ... omitted for brevity
  },
 
  "globalRuntime": ["node -v"] // result of executing this will impact the hashes of all tasks
}

Similarly, there is a runtime property that can be used in the configuration of tasks to specify the runtime inputs for a specific task.

Describe alternatives you've considered

One alternative would be put the result of node -v into an environment variable and use that as a has input via globalEnv. However, that is significant effort and some people might simply forget to do it if they execute turbo directly.

We could also write our own small wrapper around turbo that does nothing but put runtime information into an environment variable and then call turbo. But that's also quite cumbersome and error prone.

In total, this just feels like something Turborepo should take care of.

@ghost91- ghost91- added needs: triage New issues get this label. Remove it after triage story labels Mar 8, 2023
@arlyon
Copy link
Contributor

arlyon commented Mar 10, 2023

This issue pops up frequently and I agree that we need to allow users to be able to opt-in to this. We're not sure if that should be a config option (a npm style version string) or a general purpose set of commands like you suggested. We are going to come up with an answer here and I'll update this issue when I have an answer.

@arlyon arlyon removed the needs: triage New issues get this label. Remove it after triage label Mar 10, 2023
@ghost91-
Copy link
Author

Thanks for considering this, I highly appreciate that!

@ghost91-
Copy link
Author

Any news on this? We are repeatedly running into issues because of this, and are considering the different options available. Is there a reasonable chance this will be implemented soonish? If not, we'll need to look for alternatives (such writing a wrapper, or switching to Nx).

@arlyon
Copy link
Contributor

arlyon commented Jun 27, 2023

We are in the middle of our rust rewrite, and plan on tackling this once things settle. For your case, you could potentially write the node version to a file and have that as an input to the tasks that need it? It's definitely solidly in the 'workaround' category however it will do what you need.

@gajus
Copy link

gajus commented Oct 18, 2023

This bit us in a very unpleasant way. We were midway migrating from Node.js v18 to v20, and the CI kept passing all the checks ✅, but then things started to break post deployment. We've gone through the cycle of upgrade/downgrade several times without noticing that Turbo just uses cached version of the tests from another Node.js version. 😭

@styfle
Copy link
Member

styfle commented Oct 20, 2023

you could potentially write the node version to a file and have that as an input to the tasks

For reference, this workaround can be implemented like this:

@gajus
Copy link

gajus commented Oct 20, 2023

It is similar to what we did. Just added .nvmrc. Not great, but works.

@mehulkar
Copy link
Contributor

Just an update, we talked about this again in our team meeting and we want to fix this. For now, the script @styfle provided above or using .nvmrc is a good workaround. You can also add the node version to the engines key and if you keep that updated with your build runtime, changes to the root package.json will cause a cache misses

@mehulkar mehulkar added area: ergonomics Issues and features impacting the developer experience of using turbo area: caching Issues reported about incorrect cache hits or misses and removed needs: team input Filter for core team meetings labels Oct 23, 2023
anthonyshew added a commit that referenced this issue Jan 26, 2024
### Description

While we may consider OS and arch handling as a feature in the future,
we don't today. Here, we're documenting how to handle this advanced use
case as well as jotting down a proper way of handling Node.js versions.

Closes #4124 and
#1315

---------

Co-authored-by: Nicholas Yang <nicholas.yang@vercel.com>
@anthonyshew
Copy link
Contributor

Docs have gotten an update for this! Thanks for flagging, folks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: caching Issues reported about incorrect cache hits or misses area: ergonomics Issues and features impacting the developer experience of using turbo owned-by: turborepo
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants