This is a GitHub action to parse the node version and the package manager (name and version) from a package.json.
The idea is that with the setup-node action currently devEngines is not supported, but it also does not to setup a specific package manager.
So this action is capable of parsing engines, devEngines as well as packageManager entries from a package.json.
Inputs:
path: The path to thepackage.jsonrelative toworking-directory, defaults to./package.jsonworking-directory: The current working directory - used for reading thepackage.jsonand defaults to theGITHUB_WORKSPACE.
Outputs:
node-version: The detected Node.js versionpackage-manager-name: The name of the detected package manager, likenpmoryarnpackage-manager-version: The version of the detected package manager, like^10.5.1
When for example building a workflow to compile assets the usage could look like this:
name: Node build
on: pull_request
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
name: NPM build
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: Read package.json
uses: nextcloud-libraries/parse-package-engines-action@main # please pin this version to an actual tag for security
id: versions
- name: Set up node ${{ steps.versions.outputs.node-version }}
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
with:
node-version: ${{ steps.versions.outputs.node-version }}
# Here we know we use npm
- name: Set up npm ${{ steps.versions.outputs.package-manager-version }}
run: npm i -g 'npm@${{ steps.versions.outputs.package-manager-version }}'
- name: Install dependencies & build
run: |
npm ci
npm run build --if-present