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

相关推荐
Salt_072812 小时前
DAY 36 官方文档的阅读
python·算法·机器学习·github
粟悟饭&龟波功13 小时前
【GitHub热门项目精选】(2025-12-19)
前端·人工智能·后端·github
天勤量化大唯粉15 小时前
枢轴点反转策略在铜期货中的量化应用指南(附天勤量化代码)
ide·python·算法·机器学习·github·开源软件·程序员创富
CoderJia程序员甲15 小时前
GitHub 热榜项目 - 日榜(2025-12-19)
ai·开源·llm·github
小明_GLC15 小时前
关于Pycharm中导入github项目,出现依赖包报错
github
张小九9918 小时前
fpocket安装和使用教程
linux·机器学习·github
charlee4420 小时前
Github项目CI&CD部署
ci/cd·github·devops·github actions
知行力20 小时前
【GitHub每日速递 20251219】Claude-Mem:持久内存压缩系统,为Claude Code带来上下文连续性新体验!
github
薛定e的猫咪21 小时前
覆盖文献到写作全流程!GPT-Academic 多模型学术助手安装与使用指南
人工智能·gpt·github
鸽鸽程序猿1 天前
【Redis】Java客户端使用Redis
java·redis·github