为什么我在github操作上运行作业时总是失败?即使我在机器上安装了最新版本的Node

zed5wv10  于 2023-02-15  发布在  Node.js
关注(0)|答案(1)|浏览(159)

我已经安装了最新版本的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安装,但结果仍然是一样的。

qvtsj1bj

qvtsj1bj1#

publish作业缺少strategy。您还必须在publish下定义它。
在没有strategy的情况下,此处使用${{ matrix.node-version }}无效:

publish:
    runs-on: ubuntu-latest
    # ...
    steps:
      # ...
      - uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }} # invalid

您需要验证在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).

除此之外,图像中的错误:

[semantic-release]: node version >=18 is required. Found v16.19.0.

意味着此步骤只能在NodeJS v18+上运行。安装其他较低版本(如14.x和16.x)将导致失败。这使得strategy完全冗余,因为您只需要v18:

- uses: actions/setup-node@v3
        with:
          node-version: 18

您可能希望使用https://rhysd.github.io/actionlint/来检查工作流,以确定潜在的问题。

相关问题