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

相关推荐
kyriewen5 小时前
你还在手动敲命令部署?GitHub Actions 让你 push 即上线,摸鱼时间翻倍
前端·面试·github
求索实验室10 小时前
让AI真正"看见"界面:纯视觉GUI自动化编排器开源了
github·agent
梦梦代码精12 小时前
《企业开源商城选型:商业闭环、二次开发与成本平衡》
java·开发语言·低代码·开源·github
AI工具测评与分析14 小时前
2026年4月GitHub热门开源项目榜单:AI智能体正式迈入工业化协作时代
人工智能·开源·github
星栈14 小时前
Rust + DDD 三层架构:没有 Spring、没有 DI 容器,解耦能力一点不少
后端·github
梦梦代码精14 小时前
LikeShop 二次开发扩展能力白皮书——面向业务增长的可扩展电商架构实践
java·架构·github
逛逛GitHub14 小时前
推荐 6 个小众但实用的 GitHub 开源项目,有点意思啊。
github
yyuuuzz14 小时前
企业出海中的技术稳定性问题梳理
运维·服务器·网络·github·aws
朱一头zcy16 小时前
Git的下载和基本原理、Git常用命令与分支管理、IDEA集成Git、IDEA关联Github和Gitee
git·gitee·github·intellij-idea
星浩AI17 小时前
一个搞音乐的,用 AI 写了款编程工具DeepSeek TUI,本文就是它写的
github·agent·deepseek