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

相关推荐
Nautiluss1 小时前
一起玩XVF3800麦克风阵列(八)
大数据·人工智能·嵌入式硬件·github·音频·语音识别
uhakadotcom5 小时前
Python Protobuf 全面教程:常用 API 串联与实战指南
前端·面试·github
周杰伦_Jay7 小时前
【GOFrame】模块化框架与生产级实践
开发语言·gitlab·github
托马斯-酷涛12 小时前
加速GitHub加载速度-最终篇
github·proxy·代理
yuguo.im12 小时前
5 分钟快速入门 Github Actions
ci/cd·github·actions
阿里嘎多学长12 小时前
2025-12-12 GitHub 热点项目精选
开发语言·程序员·github·代码托管
gAlAxy...14 小时前
详解 Gitee/GitHub 中 HTTPS/SSH 方式数据库仓库创建与本地连接
https·gitee·github
测试人社区-小明14 小时前
AI在金融软件测试中的实践
人工智能·测试工具·金融·pycharm·机器人·github·量子计算
CoderJia程序员甲15 小时前
GitHub 热榜项目 - 日榜(2025-12-12)
ai·开源·大模型·github·ai教程
yuguo.im15 小时前
5 分钟快速入门 Gitlab CI/CD
ci/cd·gitlab·github