Skip to content

Commit

Permalink
ci: node pipelines now setup node version depending on `lockfileVersi…
Browse files Browse the repository at this point in the history
…on` (#230)
  • Loading branch information
derberg authored Apr 20, 2023
1 parent 24da68a commit a161727
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
37 changes: 37 additions & 0 deletions .github/actions/get-node-version-from-package-lock/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: 'Specify Node version based on package-lock file version'
outputs:
version:
description: 'Node.js version number to use with actions/setup-node action'
value: ${{ steps.getnode.outputs.version }}
runs:
using: "composite"
steps:
- name: Get Node version
uses: actions/github-script@v6
id: getnode
with:
script: |
const { resolve } = require('path');
const packageLockLocation = './package-lock.json';
core.info(`Location of the packae-lock verification script is: ${ resolve(packageLockLocation) }`)
const packageLock = require(packageLockLocation);
const packageLockVersion = packageLock.lockfileVersion;
let nodeVersion;
switch (packageLockVersion) {
case 1:
nodeVersion = '14'
break;
case 2:
nodeVersion = '16'
break;
case 3:
nodeVersion = '18'
break;
default:
nodeVersion = '16'
break;
}
core.setOutput('version', nodeVersion);
6 changes: 5 additions & 1 deletion .github/workflows/if-nodejs-pr-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ jobs:
id: packagejson
run: test -e ./package.json && echo "exists=true" >> $GITHUB_OUTPUT || echo "exists=false" >> $GITHUB_OUTPUT
shell: bash
- if: steps.packagejson.outputs.exists == 'true'
name: Check package-lock version
uses: asyncapi/.github/.github/actions/get-node-version-from-package-lock@master
id: lockversion
- if: steps.packagejson.outputs.exists == 'true'
name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 14
node-version: "${{ steps.lockversion.outputs.version }}"
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- if: steps.packagejson.outputs.exists == 'true'
Expand Down
14 changes: 12 additions & 2 deletions .github/workflows/if-nodejs-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,15 @@ jobs:
id: packagejson
run: test -e ./package.json && echo "exists=true" >> $GITHUB_OUTPUT || echo "exists=false" >> $GITHUB_OUTPUT
shell: bash
- if: steps.packagejson.outputs.exists == 'true'
name: Check package-lock version
uses: asyncapi/.github/.github/actions/get-node-version-from-package-lock@master
id: lockversion
- if: steps.packagejson.outputs.exists == 'true'
name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 14
node-version: "${{ steps.lockversion.outputs.version }}"
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- if: steps.packagejson.outputs.exists == 'true'
Expand Down Expand Up @@ -81,11 +85,17 @@ jobs:
- name: Check if Node.js project and has package.json
id: packagejson
run: test -e ./package.json && echo "exists=true" >> $GITHUB_OUTPUT || echo "exists=false" >> $GITHUB_OUTPUT
- if: steps.packagejson.outputs.exists == 'true'
name: Check package-lock version
uses: asyncapi/.github/.github/actions/get-node-version-from-package-lock@master
id: lockversion
- if: steps.packagejson.outputs.exists == 'true'
name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 14
node-version: "${{ steps.lockversion.outputs.version }}"
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- if: steps.packagejson.outputs.exists == 'true'
name: Install dependencies
run: npm install
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/if-nodejs-version-bump.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ jobs:
- name: Check if Node.js project and has package.json
id: packagejson
run: test -e ./package.json && echo "exists=true" >> $GITHUB_OUTPUT || echo "exists=false" >> $GITHUB_OUTPUT
- if: steps.packagejson.outputs.exists == 'true'
name: Check package-lock version
uses: asyncapi/.github/.github/actions/get-node-version-from-package-lock@master
id: lockversion
- if: steps.packagejson.outputs.exists == 'true'
name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 14
node-version: "${{ steps.lockversion.outputs.version }}"
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- if: steps.packagejson.outputs.exists == 'true'
Expand Down

0 comments on commit a161727

Please sign in to comment.