Skip to content

Instantly share code, notes, and snippets.

@tinovyatkin
Created September 27, 2019 08:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tinovyatkin/a4fbcc623cb8cb271c45d48ad8ec45a0 to your computer and use it in GitHub Desktop.
Save tinovyatkin/a4fbcc623cb8cb271c45d48ad8ec45a0 to your computer and use it in GitHub Desktop.
Install Node.JS version pinned at `engines` in `package.json` on GitHub Actions Workflow
on:
push:
branches:
- master
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
# extract `engines.node` from package.json and save it to output
- name: Get Node.JS version from package.json
id: get-versions
run: echo ::set-output name=node::$(jq -r .engines.node ./package.json)
- uses: actions/setup-node@v1
with:
node-version: ${{steps.get-versions.outputs.node}}
@isaacbowen
Copy link

For anyone else who finds this via Google, here's a run line that works with GitHub's deprecation of ::set-output:

run: echo "node=$(jq -r .engines.node ./package.json)" >> $GITHUB_OUTPUT

@zrisher
Copy link

zrisher commented Jan 19, 2023

@karthikeyan-arumugam-1558 is correct, simply specify node-version-file: 'package.json' under the with: for the Setup Node action to accomplish the above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment