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_pagepage 参数做分页处理,例如:

复制代码
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,可指定 statecontextdescription(作为运行结果显示)

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

相关推荐
四千岁2 小时前
Obsidian + jsDelivr + PicGo = 免费无限图床:一键上传,全平台粘贴即发
前端·程序员·github
wusfe2 小时前
适配 Anthropic 兼容 AI 提供商的环境配置快速切换工具
github
m0_694845573 小时前
marimo搭建教程:替代Jupyter的交互式开发工具
服务器·ide·python·docker·jupyter·github
梦梦代码精3 小时前
智能体编排 + MCP + 知识库,开源可商用!
人工智能·神经网络·gitee·开源·github·代码规范
前进的李工3 小时前
SSH隧道实现Dify与Ollama跨服务器通信
开发语言·大模型·github·腾讯云·autodl·dify
汪海游龙3 小时前
04.03 AI 精选:Google 发布 Gemma 4 开源模型
github
起个名字总是说已存在3 小时前
github开源AI技能:UI UX Pro Max智能设计系统生成器
人工智能·ui·开源·github
一叶飘零_sweeeet4 小时前
IDEA 集成 GitHub Copilot 指南:解锁 10 倍编码效率的全链路实战
github·intellij-idea·copilot
darkb1rd4 小时前
flipoff:零成本打造复古翻牌显示屏幕方案
开源·github·好物分享
Maynor9964 小时前
OpenClaw v2026.3.13-1 版本更新解析:63项改动全面解读
github