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

相关推荐
时光追逐者5 小时前
Visual Studio使用GitHub Copilot提高.NET开发工作效率
c#·github·.net·copilot·ai编程·微软技术·visual studio
油泼辣子多加13 小时前
2025年02月01日Github流行趋势
github
萨文 摩尔杰13 小时前
hexo部署到github page时,hexo d后page里面绑定的个人域名消失的问题
github
油泼辣子多加1 天前
2025年01月31日Github流行趋势
github
Ronin-Lotus2 天前
上位机知识篇---Git&GitHub
git·学习·github
AI悦创|编程1v12 天前
GitHub Actions定时任务配置完全指南:从Cron语法到实战示例
github
**kwargs2 天前
ssh密钥登录GitHub时一直提示“Error: Permission denied (publickey)”
运维·ssh·github
dreadp2 天前
解锁豆瓣高清海报:深度爬虫与requests进阶之路
前端·爬虫·python·beautifulsoup·github·requests
江_小_白3 天前
fatal: unable to access ‘https://github
github
小华同学ai3 天前
Van-Nav:新年,将自己学习的项目地址统一整理搭建自己的私人导航站,供自己后续查阅使用,做技术的同学应该都有一个自己网站的梦想
学习·gitee·开源·github