Home > front end >  Github Action error every step must define a `uses` or `run` key
Github Action error every step must define a `uses` or `run` key

Time:07-20

I couldn't make this workflow work, I'm always receiving this error every step must define a "uses" or "run" key, but looking at my script I don't see any issues, can someone pls help me fix this? It does not seem like a - problem as it usually is.

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

name: Build Digital Ocean Image

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the "master" branch
  push:
    branches:
      - '*'
      - '*/*'
      - '**'
      - '!master'
  pull_request:
    branches: [ "master" ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  packages:
    runs-on: ubuntu-latest

    steps:
      - name: Install packages
        run: |
          apt-get install curl -y
          curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
          sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
          sudo apt-get update && sudo apt-get install packer
          apt-get install ansible -y
  
  # This workflow contains a single job called "build"
  build:
    # 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:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - name: Checkout
        uses: actions/checkout@v3

      # Runs a single command using the runners shell
      - name: Packer init
        env:
          DIGITALOCEAN_TOKEN=${{ secrets.DIGITALOCEAN_TOKEN }}
        run: packer init
        working-directory: /home/runner/work/packer-do-custom-images/demo

      # Runs a set of commands using the runners shell
      - name: Packer build
        run: packer build .
        working-directory: /home/runner/work/packer-do-custom-images/demo

CodePudding user response:

The runs-on directive is missing (commented!), just add/uncomment it after the name, like:

  # This workflow contains a single job called "build"
  build:
    # 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:

To fix the issue.

I would suggest to use the actionlint tool to discover error like this, as example:

> actionlint .github/workflows/test.yaml
.github/workflows/test.yaml:35:3: "runs-on" section is missing in job "build" [syntax-check]
   |
35 |   build:
   |   ^~~~~~

UPDATE:

As side notes also the env variable as issue: you should use : instead of = like:

  - name: Packer init
    env:
      DIGITALOCEAN_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }}
  • Related