Output node and npm version numbers from package.json
package.json
{
"name": "your-package",
"engines": {
"node": "12.13.x",
"npm": "^6.1.3"
}
}
.github/workflow/test.yml
name: Get node and npm versions from package.json
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Read node and npm versions from package.json
uses: skjnldsv/read-package-engines-version-actions@v2
id: package-engines-versions
- name: Show node version number
run: echo "Node version is ${{ steps.package-engines-versions.outputs.nodeVersion }}"
# Version is 12.13.x
- name: Show npm version number
run: echo "Npm version is ${{ steps.package-engines-versions.outputs.npmVersion }}"
# Version is ^6.1.3
Path of package.json
, ./
by default.
path/to/package.json
{
"name": "your-package",
"engines": {
"node": "12.13.x",
"npm": "^6.1.3"
}
}
name: Get node and npm versions from package.json
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Read node and npm versions from package.json
uses: skjnldsv/read-package-engines-version-actions@v2
with:
path: "./path/to/package.json"
id: package-engines-versions
- name: Show node version number
run: echo "Node version is ${{ steps.package-engines-versions.outputs.nodeVersion }}"
# Version is 12.13.x
- name: Show npm version number
run: echo "Npm version is ${{ steps.package-engines-versions.outputs.npmVersion }}"
# Version is ^6.1.3
fallbackNode
and fallbackNpm
allows you to define a fallback value if not defined
{
"name": "your-package",
"engines": {
}
}
name: Get node and npm versions from package.json
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Read node and npm versions from package.json
uses: skjnldsv/read-package-engines-version-actions@v2
with:
fallbackNode: '^14'
fallbackNpm: '^6'
id: package-engines-versions
- name: Show node version number
run: echo "Node version is ${{ steps.package-engines-versions.outputs.nodeVersion }}"
# Version is ^14
- name: Show npm version number
run: echo "Npm version is ${{ steps.package-engines-versions.outputs.npmVersion }}"
# Version is ^6
MIT