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

相关推荐
chaors3 小时前
DeepResearchSystem 0x03:HITL
llm·github·ai编程
OpenTiny社区4 小时前
Loop Engineering:让 AI Agent 自己跑起来的工程方法
前端·github
木心术14 小时前
GitHub Actions自动化运维实战:从CI/CD到全链路DevOps
运维·自动化·github
炸膛坦客5 小时前
Git 和 GitHub:(七)将本地新建仓库与 GitHub 远程仓库关联起来(SSH)
git·ssh·github
fthux6 小时前
GitZip Pro:给GitHub仓库“瘦身”的魔法剪刀手
人工智能·chrome·ai·语言模型·开源·github·open source
u1301307 小时前
GitHub 热榜项目:周榜(2026-07-26)
github
逛逛GitHub7 小时前
这个开源的 Skills 让 Codex 帮你女朋友管理穿搭,太有意思了~
github
晨汐丶7 小时前
GitHub 上全是 Agent 项目,但你怎么知道哪个真的靠谱?我写了一个分析器
github
流量猎手9 小时前
GitHub 使用说明
大数据·elasticsearch·github
炸膛坦客13 小时前
Git 和 GitHub:(六)在本地新建仓库并进行一次提交
git·github