You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Github Action报错:every step must define a `uses` or `run` key 求助

修复Github Action工作流的every step must define a "uses" or "run" key错误

你的工作流报错的核心原因是**build任务缺少必填的runs-on配置**,你把这行注释掉了,导致GitHub无法识别该任务的运行环境,进而触发了误报的step错误提示。除此之外,还有两个需要优化的点:packages任务和build任务是独立运行的,build任务无法共享packages任务中安装的工具;硬编码工作目录不够灵活。

以下是修复后的完整配置:

# 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:
  build:
    # 指定运行环境,必填项
    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 code
        uses: actions/checkout@v3

      # 安装依赖工具:curl、packer、ansible
      - name: Install dependencies
        run: |
          sudo apt-get update
          sudo apt-get install curl ansible -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 -y

      # Runs a single command using the runners shell
      - name: Packer init
        env:
          DIGITALOCEAN_TOKEN=${{ secrets.DIGITALOCEAN_TOKEN }}
        run: packer init
        # 使用GitHub内置变量代替硬编码路径
        working-directory: ${{ github.workspace }}/demo

      # Runs a set of commands using the runners shell
      - name: Packer build
        env:
          DIGITALOCEAN_TOKEN=${{ secrets.DIGITALOCEAN_TOKEN }}
        run: packer build .
        working-directory: ${{ github.workspace }}/demo

关键修复点说明:

  • 恢复build任务的runs-on: ubuntu-latest配置,这是GitHub Action任务的必填项,缺失会导致系统无法正常解析任务结构。
  • 把packages任务的安装步骤合并到build任务中,因为不同任务运行在独立的runner实例上,无法共享已安装的工具。
  • 将硬编码的工作目录改为${{ github.workspace }}/demo,利用GitHub内置变量提高配置的通用性。
  • 在Packer build步骤中也添加了DIGITALOCEAN_TOKEN环境变量,避免packer构建时因缺少权限报错。

内容的提问来源于stack exchange,提问作者Kaleby Cadorin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 05:54:17