You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Actions Node.js CI工作流YAML无法验证,报27行缺冒号错误求助

问题原因

两个语法错误导致YAML解析失败:

  1. 块标量符号后未正确缩进
    你使用了>-折叠块标量语法声明run命令,后续的git命令行必须比run字段多缩进至少2个空格,否则YAML解析器会将命令行识别为同级的新键,触发「缺冒号」的报错。
  2. 误用HTML实体转义
    YAML配置中直接书写半角双引号、大于号即可,不需要转义为>、"这类HTML实体,转义后的字符会被识别为非法语法。

修正后的完整配置

# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
name: Node.js CI

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [12.x, 14.x, 16.x]

    steps:
      - uses: actions/checkout@v2
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
      - run: >-
          git config --global url."https://".insteadOf git://
      - run: >-
          git config --global url."https://github.com/".insteadOf git@github.com:
      - run: npm ci
      - run: npm run build --if-present

如果你不需要跨多行写命令,也可以直接把命令和run写在同一行,不需要用>-语法,写法如下:

- run: git config --global url."https://".insteadOf git://
- run: git config --global url."https://github.com/".insteadOf git@github.com:

内容的提问来源于stack exchange,提问作者juniper-

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 22:54:00