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

无需push触发,如何让GitHub Actions的workflow_dispatch生效?

问题

我正尝试使用GitHub Actions搭建作业自动评分体系,要求仅通过workflow_dispatch触发测试(学生需通过Actions tab手动启动),且不允许学生修改.github文件,因此不想设置push触发规则。过去两年里,仅用workflow_dispatch配置的仓库都正常,但新建的模板仓库中工作流无法在Actions tab显示。已排除默认分支问题(仓库仅含main分支),查阅资料得知可能需要先通过push触发,但此前并无此要求。附上工作流代码,询问是否是工作流本身存在问题:

name: wordle_check
on: workflow_dispatch
jobs:
   run-instructor-tests:
      runs-on: ubuntu-latest
      steps:
         - uses: actions/checkout@v3
         - run: curl https://autograder.computing.gvsu.edu/wordle_engine_instructor_test.py --output wordle_engine_instructor_test.py -k
         - run: python3 -m unittest wordle_engine_test.py
         - run: python3 -m unittest wordle_engine_instructor_test.py
解决方案
  • 先确认工作流文件路径:必须放在仓库根目录的.github/workflows/文件夹下,且文件后缀为.yml或.yaml。路径错误会导致GitHub Actions无法识别工作流,自然不会在Actions tab显示。
  • 修正YAML缩进问题:你的代码中jobs下的任务和步骤缩进层级不一致,YAML对缩进要求严格,层级混乱会导致工作流无法被解析。修正后的代码如下:
name: wordle_check
on: workflow_dispatch
jobs:
  run-instructor-tests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - run: curl https://autograder.computing.gvsu.edu/wordle_engine_instructor_test.py --output wordle_engine_instructor_test.py -k
      - run: python3 -m unittest wordle_engine_test.py
      - run: python3 -m unittest wordle_engine_instructor_test.py
  • 首次推送触发:如果路径和语法都没问题,尝试手动推送一次工作流文件到main分支。当前GitHub Actions对部分新模板仓库有机制变更,首次触发工作流后,workflow_dispatch选项才会在Actions tab显示。
  • 测试步骤注意事项:wordle_engine_test.py若为学生提交文件,需确保其存在,否则测试会失败,但这不会影响工作流在Actions tab的展示。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 12:42:07