yml语法格式报错问题?

问题描述

今天配置GitHub action的时候提示我的.yml配置文件有语法错误

请问17行那里有什么地方写的不对么?

Invalid workflow file: .github/workflows/npm-publish.yml#L17
You have an error in your yaml syntax on line 17
image.png
on:
  release:
    types: [created]
  push:
    branches:
      - master
      - dev/test

jobs:
  publish-npm:
    runs-on: ubuntu-latest
    steps:
      - name: CheckOut
        uses: actions/checkout@v3
        
      - name: Use Node
        uses: actions/setup-node@v3
        with:
          node-version: 16
          registry-url: https://registry.npmjs.org/

      # 添加缓存,逻辑和CI Workflow里的一样
      - name: Cache
        id: cache-dependencies
        uses: actions/cache@v3
        with:
          path: |
            **/node_modules
          key: ${{hashFiles('**/pnpm-lock.yaml')}}

      # 安装依赖。命中缓存则跳过此步
      - name: Installing Dependencies
        if: steps.cache-dependencies.outputs.cache-hit != 'true'
        run: |
          npm i pnpm -g
          pnpm install
      
      # 打包
      - name: Build
        run: |
          cd packages/icon-vue-components
          pnpm build
          npm publish --access public

      # - run: npm publish --access public
      env:
        NODE_AUTH_TOKEN: ${{secrets.npm_token}}
阅读 3k
1 个回答

大概知道什么问题了,一开始因为vscode没有装检查yml格式的插件,也没有配置perttier,导致不能知道问题在哪里,后来装了一个yaml插件,就可以提示错误位置了,完整代码如下,主要是env那里需要加一个缩进

jobs:
  publish-npm:
    runs-on: ubuntu-latest
    steps:
      # 拉代码 安装node
      - name: CheckOut
        uses: actions/checkout@v3
      - name: Use Node
        uses: actions/setup-node@v3
        with:
          node-version: 16
          registry-url: https://registry.npmjs.org/

      # 添加缓存,逻辑和CI Workflow里的一样
      - name: Cache
        id: cache-dependencies
        uses: actions/cache@v3
        with:
          path: |
            **/node_modules
          key: ${{hashFiles('**/pnpm-lock.yaml')}}

      # 安装依赖。命中缓存则跳过此步
      - name: Installing Dependencies
        if: steps.cache-dependencies.outputs.cache-hit != 'true'
        run: |
          npm i pnpm -g
          pnpm install

      # 打包
      - name: Build
        run: |
          cd packages/icon-vue-components
          pnpm build
          npm publish --access public

        # - run: npm publish --access public
        env:
          NODE_AUTH_TOKEN: ${{secrets.npm_token}}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏