GitHub 操作错误:"Top level 'runs:' section is required"



我正试图让一个私有GitHub操作在我的私人GitHub组织中工作。包含这些工作流"模板"的私有repo有这个简单的文件结构,因为我只是想让最低限度的操作:

.
├── .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/<private-repo>/./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.yml中定义的操作实际上是一个工作流,但应该是composite run steps action,即特定类型的操作,必须遵循中给出的规则:https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-对于复合运行步骤操作

您可以在此处找到composite run steps action的示例:https://docs.github.com/en/actions/creating-actions/creating-a-composite-run-steps-action#creating-动作元数据文件

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

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

我关于混淆GitHub Actions术语的笔记。我希望这能澄清问题。


  • 问:什么是GitHubActionS
  • A: 一个CI/CD平台,允许开发人员自动化构建、测试和部署

  • 问:什么是GitHub工作流
  • A: 工作流是一个可配置的自动化过程(即,每push运行一个on(,它将运行一个或更多的CCD_ 10。它们在回购中的.github/workflows中进行了定义

  • 问:什么是GitHub"可重复使用";Worklfow
  • A: 在另一个工作流中引用的工作流

  • 问:什么是GitHub操作
  • A: 操作是GitHub Actions平台的自定义应用程序,它执行复杂但经常重复的任务。它们在.github/actions/<action_name>/action.yml中定义回购

  • 问:什么是GitHub"复合物";操作
  • A: 复合操作允许您在一个操作中组合多个工作流steps

例如

name: Initialise the app environment
inputs:
node-version:
required: true
type: string
runs:
using: 'composite'
steps:
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '${{ inputs.node-version }}'
- name: Install dependencies
shell: bash # ! the dev has to specify this line at every `run` step in a composite action
run: npm install

最新更新