I am trying to deploy my next.js application on my VPS when there is a push on the production branch on my repo, but the SSH script is failing because the node.js version is stuck on v12.22.9, even though I specify in the main.yml to use node 18.x using actions/[email protected].
My main.yml file:
name: Deploy
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ production ]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Use Node.js 18
uses: actions/[email protected]
with:
node-version: 18
- name: Deploy using ssh
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: 22
script: |
node -v
./deploy-landing.sh
The sh file has all of the install and deployment commands, and when the job runs, these are the errors:
out: v12.22.9
...
err: npm WARN EBADENGINE Unsupported engine {
err: npm WARN EBADENGINE package: '[email protected]',
err: npm WARN EBADENGINE required: { node: '>=16.8.0' },
err: npm WARN EBADENGINE current: { node: 'v12.22.9', npm: '8.5.1' }
err: npm WARN EBADENGINE }
...
out: > next build
err: /var/www/landing/node_modules/next/dist/build/index.js:435
err: ...pageKeys.app ?? []
2
Answers
I added these two lines to the top of my .sh file:
And the node version properly updated.
I think I see the problem: the
appleboy/ssh-action
action executes itsscript
command(s) on the remote host and not in the GHA container (which has a fresh, unused, node v18 instance). You should be able to SSH onto the remote host and get an identical result by executingnode -v
.