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

Feature分支下GitHub Actions定时调度与API调用失效排查求助

Feature分支无法触发GitHub Actions的原因及修复方案

一、Cron调度触发的问题

GitHub Actions的schedule触发器默认仅在仓库默认分支执行,Feature分支的定时任务不会自动运行。要让指定Feature分支也能触发定时任务,需在Workflow配置中明确指定分支范围:

修改Workflow的on.schedule配置:

on: 
  schedule:
    - cron: '1 * * * *'
      branches: [main, feature/*] # 列出需要触发的分支,支持通配符匹配

二、API触发的问题

使用repository_dispatch API触发时,若未指定分支,默认会执行默认分支的Workflow。要触发Feature分支的流水线,需在API请求中通过client_payload传递分支名,并在Workflow中配置读取该参数:

1. 修改API请求,添加分支参数

curl -L \
  -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer token" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/repos/org/repo_name/dispatches \
  -d '{"event_type":"develop-package", "client_payload": {"branch": "feature/your-target-branch"}}'

2. 在Workflow中读取分支参数并切换

on:
  repository_dispatch:
    types: [develop-package]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: 切换到指定分支
        uses: actions/checkout@v4
        with:
          ref: ${{ github.event.client_payload.branch }}
      # 后续步骤...

三、其他检查项

  • 分支Workflow权限:进入仓库Settings > Actions > General,确认"Workflow permissions"设置为允许所有分支运行Workflow,或Feature分支未被加入禁用列表。
  • 令牌权限:API使用的Bearer token需具备repo(私有仓库)或public_repo(公共仓库)权限,且该令牌能访问目标Feature分支(无分支保护规则限制)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 12:07:20