当我的存储库上的生产分支有推送时,我尝试在我的 VPS 上部署 next.js 应用程序,但 SSH 脚本失败,因为 Node.js 版本停留在 v12.22.9,即使我指定在 main.yml 中使用 actions/[email protected] 使用节点 18.x。
我的main.yml文件:
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
sh 文件包含所有安装和部署命令,当作业运行时,出现以下错误:
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 ?? []
我想我看到了问题:
appleboy/ssh-action
操作在远程主机上执行其
script
命令,而不是在GHA容器(它有一个新的、未使用的节点v18实例)中。您应该能够通过 SSH 连接到远程主机并通过执行 node -v
获得相同的结果。