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

相关推荐
Code Talk5 小时前
VS Code markdown preview 与 github markdown渲染数学公式中的“_”不一致的问题
github·markdown·math
Hash the Hacker6 小时前
Anonymous Github, 30s 创建匿名repo供盲审使用
github
方也_arkling6 小时前
【Docker】Docker的安装和使用
docker·容器·github
CoderJia程序员甲6 小时前
GitHub 热榜项目 - 日榜(2026-1-1)
ai·开源·大模型·github·ai教程
2501_9462429315 小时前
MPV-EASY Player (MPV播放器) v0.41.0.1
数据库·经验分享·云计算·计算机外设·github·电脑·csdn开发云
CoderJia程序员甲16 小时前
GitHub 热榜项目 - 日榜(2025-12-30)
git·ai·开源·llm·github
夜流冰18 小时前
Git - github-git-cheat-sheet
git·github
阿里嘎多学长19 小时前
2025-12-30 GitHub 热点项目精选
开发语言·程序员·github·代码托管
AutoMQ20 小时前
[特殊字符] 庆祝 AutoMQ 在 GitHub 上突破 9k Stars!
github
南知意-20 小时前
GitHub 6K Star! 一款完全免费的音乐播放器,爽听VIP歌曲!
linux·windows·开源·github·开源软件·mac