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

Use node version config files if node-version input is omitted #239

Closed
wants to merge 9 commits into from

Conversation

sndrs
Copy link

@sndrs sndrs commented Mar 5, 2021

This PR uses @ehmicky's preferred-node-version to attempt to determine a node version to use if you omit node-version before it falls back to the PATH version.

It checks the following places (edited to reflect @ehmicky's comment below):

  1. .n-node-version
  2. .naverc
  3. .node-version
  4. .nodeenvrc
  5. .nvmrc (accurately parsing nvm versions)
  6. package.json#engines.node

and finally the following environment variables:

  1. NODIST_NODE_VERSION
  2. NODE_VERSION
  3. DEFAULT_NODE_VERSION

We're using this approach at the guardian (in a fork) and it seems to work well.

But we'd rather stay official :)

@sndrs sndrs changed the title Use node version config files is node-version input is omitted Use node version config files if is node-version input is omitted Mar 5, 2021
@sndrs sndrs changed the title Use node version config files if is node-version input is omitted Use node version config files if node-version input is omitted Mar 5, 2021
@sndrs sndrs force-pushed the upstream-version branch from c6c5cf6 to ae4555e Compare March 5, 2021 14:40
src/main.ts Show resolved Hide resolved
@ruscon
Copy link

ruscon commented Mar 13, 2021

can we push forward this feature?

@jasonkarns
Copy link

jasonkarns commented Mar 15, 2021

edit: this was all based on an inaccurate assumption which has since been corrected.

I like the idea, but I would be wary of using https://www.npmjs.com/package/preferred-node-version as it stands. Per the documentation for that tool (without any first-hand experience) it seems to prioritize nvm, then package.json and then all other version managers. That's fine for a specific node package like https://www.npmjs.com/package/preferred-node-version to use; but that's inappropriate for github's official node action.

I would suggest the official action should prioritize a version file that isn't version-manager specific (like .node-version which is supported by multiple node version managers), falling back to version-manager-specific files, and then package.json#engines.node's "fuzzy" matching as a last resort. (I would expect package.json to be last because its version specs is intended to contain ranges; and deterministic builds on CI should be preferred)

@ehmicky
Copy link

ehmicky commented Mar 15, 2021

Hi everyone (I maintain that library)!

For reference, this is the current priority order. The current logic prioritizes version manager-specific files because they are more specific. For example, .nvmrc is used by many tools (for example Netlify uses it). If a project has both a .nvmrc and a .naverc file, I would assume .nvmrc to be more likely to be part of the project as "boilerplate" or as part of some sort of global configuration (since parent directories are searched for). This leads to manager-specific files being prioritized.

After those comes package.json engines.node which has lower priority for the reason mentioned by @jasonkarns. Also because its intent is to define the allowed Node.js version for consumers, which might not be the same the Node.js version for developers (which might be more relevant in CI).

Finally comes the environment variables: NODIST_NODE_VERSION, NODE_VERSION and DEFAULT_NODE_VERSION. Those have the lowest priority because they are global and might apply to many projects, i.e. are less specific.

@jasonkarns
Copy link

@ehmicky thanks for clarifying and correcting my misinterpretation! I retract my "opposition" to this PR.

My (inaccurate) assumption was based solely on the phrasing of the readme:

This looks for any .nvmrc or package.json [...] This also looks for any [other files] or [variables].

@ehmicky
Copy link

ehmicky commented Mar 15, 2021

One note: the library can throw. For example, if the project has an .nvmrc with an invalid Node.js version (wrong syntax, or Node.js version does not exist). Would it be a good idea not to print the error as a warning message, and not make the build fail when this happens? Or would hard failure be proper in that case?

@nrako
Copy link

nrako commented Mar 15, 2021

I believe a hard failure would be expected here. I don't think there's any reason why an invalid nodejs version should fail silently.

@sndrs
Copy link
Author

sndrs commented Mar 16, 2021

thanks @ehmicky – i'll update the description of the PR to reflect the ordering

@Macavirus
Copy link

Is there any blocker to merging this?

@sndrs
Copy link
Author

sndrs commented Apr 6, 2021

@Macavirus I'm not sure. Currently 2 checks are failing but i've followed the advice and don't understand what the issues are.

I'm also not clear whether GitHub would be interested in merging it either.

@jasonkarns are you able to advise?

In the meantime, we're using https://github.com/guardian/actions-setup-node at the guardian (basically this PR) if that's any help to anyone

@jasonkarns
Copy link

@sndrs I'm not a member of the team and do not have any capability to merge or weigh in on the PR more than anyone else here. So far I haven't seen a github team member in this thread.

@sndrs
Copy link
Author

sndrs commented Apr 6, 2021

@jasonkarns lol sorry! i'm not sure where i got that idea from – sorry to alert you :)

@bryanmacfarlane (because you last merged a PR in the repo – apologies if you too are the wrong person) are you able to advise if this is something that might get merged? if so, any advice on how i can fix the broken checks?

@jasonkarns
Copy link

(@sndrs no worries! I was at @github for a time, so quite likely you saw my name associated as an org member)

@sndrs sndrs closed this Sep 9, 2021
@sndrs sndrs deleted the upstream-version branch September 9, 2021 16:11
@AlexWayfer
Copy link

@gordey4doronin @maxim-lobanov @dmitry-shibanov no reviews here? 😞

@sndrs sndrs restored the upstream-version branch September 9, 2021 16:41
@sndrs sndrs reopened this Sep 9, 2021
@sndrs
Copy link
Author

sndrs commented Sep 9, 2021

got confused with working with forks and accidentally closed this. not intentional

@AlexWayfer
Copy link

got confused with working with forks and accidentally closed this. not intentional

Oh, nice. There are conflicts, BTW.

# Conflicts:
#	dist/index.js
#	package-lock.json
@sndrs
Copy link
Author

sndrs commented Sep 24, 2021

hopefully the conflicts are dealt with and license checks now pass (they pass for our fork at https://github.com/guardian/actions-setup-node and which is still used across the guardian).

be great if someone is able to kick them off? (or just close this PR if it's not going to be merged so i can stop updating it 😄)

@sndrs
Copy link
Author

sndrs commented Nov 9, 2021

@maxim-lobanov given #338 and that no one from GitHub has ever responded to this PR, should I just close it? getting strong vibes GitHub's not all that interested 😉

@sndrs
Copy link
Author

sndrs commented Nov 20, 2021

thanks everyone for your input. GitHub are going with their own solution in #338 so I'm closing this.

in case anyone is using the fork I mentioned, we'll archive it when the official action supports version files natively, so it should keep working but won't get upstream updates

@sndrs sndrs closed this Nov 20, 2021
deining pushed a commit to deining/setup-node that referenced this pull request Nov 9, 2023
Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 4.28.2 to 4.28.3.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v4.28.3/packages/eslint-plugin)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/eslint-plugin"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

8 participants