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

相关推荐
逛逛GitHub28 分钟前
不要错过这 18 个本周 YYDS 的 GitHub 开源项目。
github
大刚测试开发实战35 分钟前
TestHub数据工厂发布!附更新指南
前端·后端·github
在水一缸39 分钟前
深度解析:GitHub “虚假星星“ 经济链与开源信任危机
开源·github·技术选型·虚假星星·信任危机·灰色产业链
2601_961845151 小时前
行测电子版pdf教材|真题|解析
pdf·新媒体运营·github·个人开发·内容运营·规格说明书·极限编程
我最爱吃鱼香茄子1 小时前
【保姆级】Git配置用户名和邮箱(全局/局部)解决提交记录不识别、贡献图不亮问题
git·gitee·github·小白教程·git配置·程序员开发工具
yyuuuzz1 小时前
云服务器软件部署的常见问题与经验
linux·运维·服务器·网络·数据库·人工智能·github
码流怪侠1 小时前
【GitHub】 Headroom 深度解析:AI Agent 上下文压缩层的完整技术拆解
人工智能·github·agent
Appoint_x1 小时前
我受够了浏览器标签越开越乱,所以做了一个「标签工作台」
github
夫唯不争,故无尤也2 小时前
安全协作:私有仓库的正确共享方式
安全·github·多人协作
Safeploy安策数据2 小时前
政务云加密太慢?万兆服务器密码机如何破解高并发性能瓶颈
linux·运维·github