首页 > 解决方案 > GitHub 上的 YAMLException 在第 20 行说“映射条目的缩进错误”

问题描述

我尝试了几种格式化程序和 IDE,但它们不会产生我在 GitHub 文本编辑器中遇到的相同错误。我正在为 GitHub Actions 编写教程,在尝试提交和触发操作时无法克服这个特定错误。我得到错误- name: Build docker。我该怎么做才能修复/清除错误?

name: CI-dev-pipeline
on:
  # Triggers the workflow on push or pull request events but only for the develop branch
  push:
    branches: [ develop ]
  pull_request:
    branches: [ develop ]
jobs:
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest
    container:
      image: lucasalt/act_base:latest
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2
        with:
          path: "workflow"

    - name: Build docker
      run: | 
        echo ---Building and starting up docker---
        docker-compose -f ./workflow/docker-compose.test.yml -p testing up -d
        echo ---Containers up---
        
    - name: Run test
      run: |
        echo --- Running test cases ---
        docker-compose -f ./workflow/docker-compose.test-github.yml -p testing up --build --exit-code-from api-test
        echo --- Completed test cases ---
        
   - name: Extract commit
        shell: bash
        run: |
          echo "GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_ENV

  - name: Get branch name (merge)
    if: github.event_name != 'pull_request'
    shell: bash
    run: echo "BRANCH=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV

  - name: Get branch name (pull request)
    if: github.event_name == 'pull_request'
    shell: bash
    run: echo "BRANCH=$(echo ${GITHUB_HEAD_REF} | tr / -)" >> $GITHUB_ENV


  - name: Send slack notification
    if: always()
    uses: edge/simple-slack-notify@master    
    env:
      SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
    with:
      channel: '#deployment'
      status: ${{ job.status }}
      success_text: '${env.GITHUB_WORKFLOW} #${env.GITHUB_RUN_NUMBER} build completed successfully'
      failure_text: '${env.GITHUB_WORKFLOW} #${env.GITHUB_RUN_NUMBER} build failed'
      cancelled_text: '${env.GITHUB_WORKFLOW} #${env.GITHUB_RUN_NUMBER} build was cancelled'
      fields: |
        [{ "title": "Repository", "value": "${env.GITHUB_REPOSITORY}", "short": true },
        { "title": "Branch", "value": "${env.BRANCH}", "short": true },
        { "title": "Commit", "value": "${env.GITHUB_SHA_SHORT}", "short": true },
        { "title": "Action URL", "value": "${env.GITHUB_SERVER_URL}/${env.GITHUB_REPOSITORY}/actions/runs/${env.GITHUB_RUN_ID}"}]

标签: yamlgithub-actions

解决方案


推荐阅读