-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
node-version as fallback of node-version-file #939
Comments
Hello @y-nk |
To me this feels backwards; generally, config files are the default and "inline settings/flags" override the defaults. If you're specifying a |
@fregante that is untrue, especially in monorepos where the node-version file can be there (or not) depending on the package/service running the job, but you could always use a hardcoded base version as a fallback. |
I don’t think "monorepos" are the standard. I'm thinking more about CLIs and literally everything else:
I don’t think it should be anything but that. |
@fregante i understand your standpoint. as a mean not to remain unblocked, would you have any recommendation for something less verbose/more elegant than this: - if: ${{ !inputs.workspaceRelativePath }}
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
registry-url: https://npm.pkg.github.com/
scope: '@company'
- if: ${{ inputs.workspaceRelativePath }}
uses: actions/setup-node@v4
with:
node-version-file: ${{ format('{0}/.node-version', inputs.workspaceRelativePath) }}
cache: 'pnpm'
registry-url: https://npm.pkg.github.com/
scope: '@company' ? |
I agree with @fregante in that I expect my explicitly given parameter in the CI workflow file to have more weight than the files in the repo. My CI workflow is there to keep repo file changes in check. Maybe we can have a weak option
Update: I don't fully understand the PATH problem in #912, but it seems to in some way be a version number oracle, so we shoudl probably support it here as well. Name could be |
I have an issue closely related to this that is related to use of multiple node version $ cat .tool-versions
nodejs 20.18.0 18.20.4 Basically the Currently it seems impossible to use This means that if I want to test both, I have to copy the exact version from the Does anyone have a workaround for this issue? |
@ssbarnea you need to create a first job which will read the .tool-versions and build a json out of it (using job outputs), then pass that json to a 2nd job into your matrix. job1:
runs-on: ubuntu-latest
outputs:
node-versions: ${{ steps.tool-versions.outputs.result }}
steps:
- id: tool-versions
run: |
# this bash was suggested by chatgpt.
result=$(cat .tool-versions | jq -R 'split(" ") | { (.[0]): .[1:] } | .nodejs')
echo "result=$result" >> $GITHUB_OUTPUT
job2:
needs: job1
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ${{ fromJSON(needs.job1.outputs.node-versions) }}
steps:
- uses: actions/setup-node@v5
node-version: ${{ matrix.node-version }} drafted hastily so some typos may occur ; general idea is there. |
Description
Currently the behavior is that
node-version
is preferred rather thannode-version-file
if both are provided.setup-node/src/main.ts
Lines 85 to 95 in d86ebcd
I would like to propose the opposite since
node-version
is actually hardcoded in the action parameters, but the file is not guaranteed to be there.setup-node/src/util.ts
Lines 8 to 12 in d86ebcd
Currently, scenarios resolved as following:
What I'm requesting for is a change in the 2 lasts scenarios:
Justification
This is just a nicer API, i think. it does not remove the case of conscious crash of the pipeline if no
node-version
is given, but it does nicely propose a fail-safe for people interested.Note
We could also have another parameter such as
node-version-fallback-if-file-not-found
but it'd just increase the complexity of the api.Are you willing to submit a PR?
Yes, i'm ok with that.
The text was updated successfully, but these errors were encountered: