我已经安装了最新版本的NodeJs(v18.14.0),但它仍然无法执行作业,我该怎么办?这是我的工作流程中的代码和错误的屏幕截图。
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
name: Node.js CI
on:
push:
branches: ['main']
pull_request:
branches: ['*']
jobs:
quality:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
publish:
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/main' }}
needs: [quality]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run semantic-release
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
我尝试过通过删除node_modules和package.lock.json来从头安装所有内容,然后执行npm安装,但结果仍然是一样的。
1条答案
按热度按时间qvtsj1bj1#
publish
作业缺少strategy
。您还必须在publish
下定义它。在没有
strategy
的情况下,此处使用${{ matrix.node-version }}
无效:您需要验证在
publish
下安装的是哪个版本的actions/setup-node
,因为publish
下的值是无效的,显然只有默认的预装Node.js 16.19.0。注解:The default preinstalled NodeJS version will be set to 18 from tomorrow (Monday - February 13th, 2023).
除此之外,图像中的错误:
意味着此步骤只能在NodeJS v18+上运行。安装其他较低版本(如14.x和16.x)将导致失败。这使得
strategy
完全冗余,因为您只需要v18:您可能希望使用https://rhysd.github.io/actionlint/来检查工作流,以确定潜在的问题。