【问题标题】:GitHub Action error: "Top level 'runs:' section is required"GitHub 操作错误:“需要顶级‘运行:’部分”
【发布时间】:2020-12-21 21:19:16
【问题描述】:

我正在尝试让一个私有 GitHub 操作在我的私有 GitHub 组织中工作。包含这些工作流“模板”的私有仓库具有这种简单的文件结构,因为我只是试图让最低限度的工作:

.
├── .git
├── test
│   ├── action.yml

action.yml 文件内容为:

name: Test

on: push

jobs:
  test:
    name: Test
    runs-on: ubuntu-latest
    steps:

    - name: Echo
      run: |
        echo Heyyyyy

我正在尝试在另一个私人存储库中使用此操作,其中包含以下内容的工作流文件:

name: Test

on:
  push:
    branches:
      - master

jobs:
  test:
    name: Test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          repository: <private-actions-repo>
          token: ${{ secrets.REPO_TOKEN }}
          path: github-actions
      - name: Test private action
        uses: ./github-actions/test

当此操作运行时,我收到以下错误: ##[error]Top level 'runs:' section is required for /home/runner/work/&lt;private-repo&gt;/./github-actions/test/action.yaml

为了调试这个,我将使用模板的工作流更新为cat这个文件的文件内容:

      - name: Test private action
        run: |
          cat ./github-actions/test/action.yml

..我得到了我期望的内容:

> Run cat ./github-actions/test/action.yml
name: Test

on: push

jobs:
  test:
    name: Test
    runs-on: ubuntu-latest
    steps:

    - name: Echo
      run: |
        echo Heyyyyy

为什么在 action repo 中使用它时这不起作用,但在目标 repo 中使用完全相同的内容?

【问题讨论】:

    标签: github-actions


    【解决方案1】:

    您必须区分工作流、操作和不同的操作类型。

    工作流是顶级元素,不可组合。操作是可用于工作流的构建块。您在action.yml 中定义的操作实际上是一个工作流,但应该是composite run steps action,即一种特定类型的操作,必须遵循以下规则: https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-composite-run-steps-actions

    您可以在此处找到composite run steps action 的示例: https://docs.github.com/en/actions/creating-actions/creating-a-composite-run-steps-action#creating-an-action-metadata-file

    如果您将以下内容用作action.yaml,它应该可以工作:

    name: Test
    description: 'composite run action'
    
    runs:
      using: "composite"
      steps: 
        steps:
        - name: Echo
          shell: bash
          run: |
            echo Heyyyyy
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-19
      • 2020-12-15
      • 2020-09-19
      • 2022-07-31
      • 1970-01-01
      • 2022-10-23
      • 2020-05-02
      相关资源
      最近更新 更多