Search code examples
github-actionsbuilding-github-actions

GitHub Action error: "Top level 'runs:' section is required"


I am trying to get a private GitHub action to work within my private GitHub org. The private repo that contains these workflow 'templates' has this simple file structure as I'm just trying to get the bare minimum to work:

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

And the action.yml file contents are:

name: Test

on: push

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

    - name: Echo
      run: |
        echo Heyyyyy

I am trying to use this action in another private repo with a workflow file with these contents:

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

When this action runs, I get the following error: ##[error]Top level 'runs:' section is required for /home/runner/work/<private-repo>/./github-actions/test/action.yaml

Trying to debug this, I updated the workflow that uses the template to cat the file contents of this file:

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

..and I get the contents I would expect:

> 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

Why would this not be working when using it from the action repo, but the exact same content works in the target repo?


Solution

  • You have to differentiate between workflows, actions, and different action types.

    Workflows are toplevel elements. Actions are building blocks that can be used in workflows. The action you defined in action.yml is actually a workflow but should be a composite run steps action, i.e. a specific type of action, that has to follow the rules given in: https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-composite-run-steps-actions

    You can find an example for a composite run steps action here: https://docs.github.com/en/actions/creating-actions/creating-a-composite-run-steps-action#creating-an-action-metadata-file

    If you use the following as action.yaml, it should work:

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