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

GHA可重用工作流:workflow_dispatch成功但push触发失败

GitHub Actions工作流执行问题排查

问题背景

我有3个GitHub Actions工作流,其中reusable.yml位于独立仓库:

push-client.yml(推送触发)

name: Execute on push

on:
  push: 

jobs:
  deploy: 
    uses: <my-org>/<reusable-workflow-repo>/.github/workflows/reusable.yml@main
    with:
      runner: 'WinRunner1'
      import-submodules: 'recursive'
    secrets:
      repo_token: ${{ secrets.REPO_READ_PAT }}

workflow-dispatch.yml(手动触发)

name: Execute on manual click

on:
  workflow_dispatch:
    inputs:
      runner:
        required: true
        type: choice
        options:
          - 'WinRunner1'
          - 'WinRunner2'
      import-submodules:
        type: choice
        required: true
        options:
          - 'recursive' #All submodule levels
          - 'true' #Only first submodule level
          - 'false'

jobs:
  deploy: 
    #name: Call Reusable Workflow
    uses: <my-org>/<my-reusable-repo>/.github/workflows/reusable.yml@main
    with:
      runner: ${{ github.event.inputs.runner }}
      import-submodules: ${{ github.event.inputs.import-submodules }}
    secrets:
      repo_token: ${{ secrets.REPO_READ_PAT }}

reusable.yml(可复用工作流)

name: Reusable 

on:
  workflow_call:
    inputs:
      runner:
        required: true
        type: string
      import-submodules:
        type: string
        required: true
    secrets:
      repo_token:
        description: 'PAT with access to caller repo + submodules. If no submodules, native GITHUB_TOKEN works.'
        required: true

jobs:
  checkout: 
    runs-on: ${{ github.event.inputs.runner }}
    steps:
      - name: Checkout Repository without Submodules
        uses: actions/checkout@v4
        if: ${{ github.event.inputs.import-submodules == 'false' }}
        with:
          token: ${{ secrets.REPO_TOKEN }}
      - name: Checkout Repository with Submodules
        uses: actions/checkout@v4
        if: ${{ github.event.inputs.import-submodules == 'true' }}
        with:
          submodules: true
          token: ${{ secrets.REPO_TOKEN }}
      - name: Checkout Repository with Recursive Submodules
        uses: actions/checkout@v4
        if: ${{ github.event.inputs.import-submodules == 'recursive' }}
        with:
          submodules: recursive
          token: ${{ secrets.REPO_TOKEN }}
      - name: Checkout reusable workflow's repo to access Python scripts hosted there
        uses: actions/checkout@v4
        with:
          repository: <my-org>/<reusable-workflow-repo>
          token: ${{ secrets.REPO_TOKEN }}
          path: reusable-workflow-repo

问题现象

workflow-dispatch.yml手动触发能正常执行,但push-client.yml在代码推送触发时执行失败,错误信息如下:

Error when evaluating 'runs-on' for job 'checkout'. <my-org>/<reusable-workflow-repo>/.github/workflows/reusable.yml@main (Line: 19, Col: 14): Unexpected value ''

问题原因

核心问题是可复用工作流的参数引用逻辑错误:

  • 当工作流由workflow_dispatch手动触发时,github.event.inputs确实能获取到用户选择的参数,所以workflow-dispatch.yml能正常运行。
  • 但当通过其他工作流(比如push-client.yml)调用可复用工作流时,传入的参数属于workflow_call定义的输入,此时应该用${{ inputs.xxx }}来引用,而非github.event.inputs。
  • push-client.yml触发时,github.event是push事件,不存在inputs字段,所以${{ github.event.inputs.runner }}会返回空字符串,导致runs-on的值为空,直接触发错误。

修复方案

修改reusable.yml中的所有参数引用,把github.event.inputs替换为inputs,修改后的代码如下:

name: Reusable 

on:
  workflow_call:
    inputs:
      runner:
        required: true
        type: string
      import-submodules:
        type: string
        required: true
    secrets:
      repo_token:
        description: 'PAT with access to caller repo + submodules. If no submodules, native GITHUB_TOKEN works.'
        required: true

jobs:
  checkout: 
    runs-on: ${{ inputs.runner }}
    steps:
      - name: Checkout Repository without Submodules
        uses: actions/checkout@v4
        if: ${{ inputs.import-submodules == 'false' }}
        with:
          token: ${{ secrets.REPO_TOKEN }}
      - name: Checkout Repository with Submodules
        uses: actions/checkout@v4
        if: ${{ inputs.import-submodules == 'true' }}
        with:
          submodules: true
          token: ${{ secrets.REPO_TOKEN }}
      - name: Checkout Repository with Recursive Submodules
        uses: actions/checkout@v4
        if: ${{ inputs.import-submodules == 'recursive' }}
        with:
          submodules: recursive
          token: ${{ secrets.REPO_TOKEN }}
      - name: Checkout reusable workflow's repo to access Python scripts hosted there
        uses: actions/checkout@v4
        with:
          repository: <my-org>/<reusable-workflow-repo>
          token: ${{ secrets.REPO_TOKEN }}
          path: reusable-workflow-repo

修改完成后,无论是手动触发还是推送触发,可复用工作流都能正确获取传入的参数,push-client.yml即可正常执行。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.27 16:52:42