GitHub Action – 无效的工作流文件 – YAML 语法错误

huangapple go评论62阅读模式
英文:

GitHub Action - Invalid workflow file - YAML syntax error

问题

GitHub Workflow中的YAML语法问题通常会在缩进、引号和特殊字符等方面引起错误。在您提供的YAML中,问题在于您使用了HTML编码的引号(")而不是正常的双引号 (")。以下是已修复的YAML代码:

# This is a basic workflow to help you get started with Actions

name: TestWorkflowGithub

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the "main" branch
  pull_request:
    branches:
    - 'testbranch/**'
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # The type of runner that the job will run on
  runs-on: ubuntu-latest

  # Steps represent a sequence of tasks that will be executed as part of the job
  steps:
    - name: Checkout the code
      uses: actions/checkout@v3

    - name: Install PMD
      run: |
        PMD_VERSION=`cat pmd/pmd-version.txt`
        wget https://github.com/pmd/pmd/releases/download/pmd_releases%2F6.54.0/pmd-bin-6.54.0.zip
        unzip pmd-bin-6.54.0.zip -d ~
        mv ~/pmd-bin-6.54.0 ~/pmd
        ~/pmd/bin/run.sh pmd --version        

    # Run PMD scan
    - name: Run PMD scan
      run: ~/pmd/bin/run.sh pmd -d force-app -R pmd/ruleset.xml -f text

请注意,我已将双引号 " 替换了 HTML 编码的引号 ("),这应该解决您的YAML语法问题。如果还有其他问题,请随时提出。

英文:

I am trying to setup my first GitHub Workflow and I am facing many YAML syntax issues even I am using the official documentation.

I am using the below YAML:

# This is a basic workflow to help you get started with Actions

name: TestWorkflowGithub

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the "main" branch
  pull_request:
    branches:
    - 'testbranch/**'
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # The type of runner that the job will run on
  runs-on: ubuntu-latest

  # Steps represent a sequence of tasks that will be executed as part of the job
  steps:
    - name: Checkout the code
      uses: actions/checkout@v3

    - name: Install PMD
      run: |
        PMD_VERSION=`cat pmd/pmd-version.txt`
        wget https://github.com/pmd/pmd/releases/download/pmd_releases%2F6.54.0/pmd-bin-6.54.0.zip
        unzip pmd-bin-6.54.0.zip -d ~
        mv ~/pmd-bin-$6.54.0 ~/pmd
        ~/pmd/bin/run.sh pmd --version

    # Run PMD scandd
    - name: Run PMD scan
      run: ~/pmd/bin/run.sh pmd -d force-app -R pmd/ruleset.xml -f text

GitHub is showing me the below error:
You have an error in your yaml syntax on line 14

Note: the line 14 is "runs-on: ubuntu-latest"

Which is the syntax issue in the above YAML file?

答案1

得分: 2

你缺少了作业标识符

jobs:
  foo: # <-- This
    runs-on: ubuntu-latest

    steps:
      - name: Checkout the code
        uses: actions/checkout@v3

  steps:

下次可以使用actionlintvscode-yaml来避免这种语法问题 GitHub Action – 无效的工作流文件 – YAML 语法错误

英文:

You are missing the job identifier:

jobs:
  foo: # <-- This
    runs-on: ubuntu-latest

    steps:
      - name: Checkout the code
        uses: actions/checkout@v3

  steps:

You can use actionlint or vscode-yaml to avoid such syntax issues next time GitHub Action – 无效的工作流文件 – YAML 语法错误

答案2

得分: 1

一个快速定位YAML文件中语法问题的好方法是使用新的VSCode扩展:

GitHub Actions:Visual Studio Code扩展现在公开测试中(2023年3月)

GitHub Actions的VS Code扩展现在公开测试中。
该扩展包括丰富的编辑功能,如语法验证和自动完成,使工作流程的编写和编辑更快更容易。
开发人员还可以直接从VS Code查看工作流运行、检查日志并触发重新运行。

要开始使用,请访问VS Code Marketplace或从Actions VS Code Extension博客文章了解更多关于该扩展的功能。

通过访问我们的公共路线图了解Actions的下一步计划。

英文:

A good way to quickly pinpoint the syntax issue in your YAML file is to use the new VSCode extension:

> ## GitHub Actions: Visual Studio Code Extension is now in public beta (Mar. 2023)
>
> The GitHub Actions extension for VS Code is now in public beta.
> This extension includes rich editing features, such as syntax validation and autocomplete, making workflow authoring and editing faster and easier.
> Developers will also be able to view workflow runs, inspect logs, and trigger re-runs directly from VS Code.
>
> To get started, visit the VS Code Marketplace or learn more about the extension's capabilities from the Actions VS Code Extension blog post.
>
> See what's next for Actions by visiting our public roadmap.

huangapple
  • 本文由 发表于 2023年2月19日 09:19:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/75497433.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定