GitHub Workflow 和 Action 的一些注意事项

GitHub 的 workflow 和 action 存在一些注意事项,总结如下,以供参考

Workflow

on.issues.types

如果需要判断 label,不需要指定 opened,只需要指定 labeled,因为即使 label 是新建时设置的,也会触发 labeled

permissions

如果需要 checkout 当前 repo,需要添加 contents: write,否则会有权限问题

jobs.check.steps.env

如果需要 checkout 当前 repo,需要添加 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }},否则会有权限问题

Action

List repository issues

API 不仅返回 issues,也会返回 prs,默认 30 条每页,可以指定 labels 来过滤

List pull requests

API 返回所有 pull requests,默认 30 条每页,可以通过 per_page 和 page 参数做分页处理,例如:

复制代码
const prs = [];
for (let page = 1; ; page++) {
  const { data } = await octokit.rest.pulls.list({
    ...context.repo,
    base: `refs/heads/main`,
    state: 'open',
    per_page: PER_PAGE,
    page,
  });
  prs.push(...data);
  if (data.length < PER_PAGE) {
    break;
  }
}

Get commit status

API 列出所有 contexts 对应的 state,可以过滤当前的 context

Create commit status

API 用于创建 commit 的 status,可指定 state,context 和 description(作为运行结果显示)

Setting

Require status checks

需要在 Branch protection rule 中的 Protect matching branches 下,勾选 Require status checks to pass before merging

Add required checks

需要将当前的 GitHub action 添加到 Status checks that are required

相关推荐
可乐ea3 小时前
GitHub Security Lab 开源 Fuzzing Taskflow:让 LLM 智能体自己跑完 C/C++ 模糊测试
jvm·c++·github·模糊测试·mcp·代码agent·智能体自动化
TOOLS指南4 小时前
GitHub 和 ai.github 是什么?两者有什么区别
人工智能·github
贾斯汀frank4 小时前
Fleurdelix OS已预装办公套件ONLYOFFICE桌面编辑器
github
wflynn5 小时前
GitHub 日榜趋势速报 | 2026-09-30
开源·github
Cosolar10 小时前
云端部署阿里 Qwen-Image-2.1 保姆级教程
人工智能·后端·github
miofly11 小时前
GitHub 今日推荐|REDox:64 位 token 表示结构化数据,内存占用降 70% 支持多格式互转
开源·c#·github
奋进的LY11 小时前
spacy的安装和使用教程
人工智能·python·深度学习·github
guru12 小时前
手写一个 Tool-Calling Agent:为什么要先不用框架
github
miofly12 小时前
GitHub 日榜趋势速报 | 2026-10-03
开源·github
czhc114007566313 小时前
2026.10.2 GitHub 项目推荐
github