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

相关推荐
星蓝_starblue1 天前
零服务器、零数据库!开源growth-board,利用GitHub自动管理刷题/学习/求职全流程
服务器·数据库·程序人生·系统架构·node.js·github·改行学it
夏天的峰没有风1 天前
Typora加github加PicGo搭建图床使用教程
github·claude code
Liekkas Kono1 天前
Github Star History 趋势图工具推荐
github·swhl
逛逛GitHub1 天前
盘点 2 个看起来贼炫酷酷酷的 GitHub 项目,炒的还挺火的。
github
卡卡罗特AI1 天前
GitHub怎么用?零基础,保姆级使用教程-上!建议收藏
前端·后端·github
YuePeng1 天前
不写一行接口,让 DBeaver 直连你的指标层——背后只用了一个端口
后端·架构·github
别动我齐刘海1 天前
Day6 unitree_G1人形机器人GMR—— MotionInput
c语言·c++·人工智能·学习·机器学习·机器人·github
leoZ2311 天前
实战复盘:用 Claude Code 从零搭一个 GitHub PR 统计工具
java·人工智能·python·深度学习·自然语言处理·github·llama
阿里嘎多学长2 天前
2026-08-04 GitHub 热点项目精选
开发语言·程序员·github·代码托管
MicrosoftReactor2 天前
技术速递|GitHub Copilot App 入门指南:快速上手
ai·github·copilot·copilot app