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

相关推荐
猫头虎1 小时前
GitHub下载教程:2025年最新详解从GitHub上传、下载文件、子目录与完整项目【图文教程】
git·svn·gitee·开源·github·gitea·gitcode
go54631584652 小时前
在本地环境中运行 ‘dom-distiller‘ GitHub 库的完整指南
人工智能·深度学习·神经网络·算法·矩阵·github
绝无仅有6 小时前
Redis 服务挂掉排查与解决
后端·面试·github
飞询6 小时前
Window 部署 coze-stdio(coze 开发平台)
docker·github·coze
kymjs张涛6 小时前
零一开源|前沿技术周刊 #9
前端框架·开源·github
HelloGitHub6 小时前
《HelloGitHub》第 112 期
开源·github
程序视点7 小时前
Umi-OCR完全指南:开源离线OCR识别软件下载安装使用教程|支持批量PDF/二维码识别
前端·后端·github
草梅友仁16 小时前
草梅 Auth 1.1.0 发布与最新动态 | 2025 年第 30 周草梅周报
开源·github·ai编程
mortimer18 小时前
安装NVIDIA Parakeet时,我遇到的两个Pip“小插曲”
python·github