惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

月光博客
月光博客
Apple Machine Learning Research
Apple Machine Learning Research
IT之家
IT之家
阮一峰的网络日志
阮一峰的网络日志
雷峰网
雷峰网
S
SegmentFault 最新的问题
量子位
有赞技术团队
有赞技术团队
V
V2EX
宝玉的分享
宝玉的分享
Hugging Face - Blog
Hugging Face - Blog
B
Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Jina AI
Jina AI
C
Check Point Blog
G
Google Developers Blog
博客园 - 叶小钗
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园_首页
T
Tailwind CSS Blog
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
酷 壳 – CoolShell
酷 壳 – CoolShell
U
Unit 42

陈少文的网站

巨变与机遇的未来十年 Kubernetes 平台管理软件压力测试方案 使用镜像部署 Hexo 静态页面 终于等到你 - GitHub 镜像仓库服务(ghcr.io) 一起来学 Go --(6)Interface 一起来学 Go --(5)Goroutine 和 Channel 什么是函数式编程 如何在 Kubernetes 集群集成 Kata 柯里化与偏函数 使用 PyGithub 自动创建 Label 软件产品是团队能力的输出 Helm 2 、Helm 3 比较 IoT 变现 Kubernetes 中的 DNS 服务 国内的 Helm 镜像源 Harbor 使用自签证书支持 Https 访问 DevOps 工具链之 Prow 如何使用 kfctl 安装 Kubeflow VS Code 无法下载 Go 插件的工具包 工程师更应具有服务精神 你不知道的 Docker 使用技巧 使用 Docker 运行 Tensorflow 论中国 什么是左移 如何清空 Git 仓库全部历史记录 一禅小和尚 有风吹过厨房 时间的玫瑰 如何在 CentOS 安装 GPU 驱动 开发 Tips(19)
本地执行没问题, GitHub Actions 却一直报错
微信公众号 · 2021-02-02 · via 陈少文的网站

Please enable Javascript to view the contents

1. 一个令人困惑的问题

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
name: Go

on: [push, pull_request]

jobs:
  build:
    name: CI
    runs-on: ubuntu-latest
    steps:
      - name: Set up Go 1.13
        uses: actions/setup-go@v1
        with:
          go-version: 1.13
      - name: Check out code into the Go module directory
        uses: actions/checkout@v2
      - name: Check pr is properly formatted
        run: diff -u <(echo -n) <(gofmt -d ./pkg ./cmd ./tools ./test)
      - name: Test & Build
        run: make all

上面是项目中 workflow 的一部分, 主要用来检测代码风格、执行单元测试、编译代码。提交 Pull Requests 时, 就会触发执行。

但 GitHub Actions 一直报错, 提示如下:

1
Error: vet: pkg/kapis/cluster/v1alpha1/handler_test.go:405:87: too few arguments in call to informers.NewInformerFactories

问题的关键在于, 本地执行没有任何报错。刚开始怀疑是 GitHub Actions 不够稳定, 可能存在抖动。于是, 反复推送, 但是错误依旧。

2. 线上调试

直接祭出了杀手锏, 登录 Ngrok 拿到 Authtoken 配置到 Secrets 中。然后, 添加如下片段至失败的任务之前:

1
2
3
4
5
6
- uses: shaowenchen/debugger-action@v2
  name: debugger
  timeout-minutes: 30
  continue-on-error: true
  with:
    ngrok_token: ${{ secrets.NGROK_TOKEN }}

在 Actions 的执行日志中, 找到 SSH 登录链接。执行命令, 远程登录 Runner 进行调试:

1
ssh root@@0.tcp.ngrok.io -p 17656

输入密码 root, 即可在线调试。可是, 还是提示同样的错误, 只能另想办法。

3. 日志中发现端倪

根据错误, 我猜测是代码缓存、同步之类的问题。于是, 翻了下 Actions 的完整日志, 终于发现了端倪。

1
2
3
Checking out the ref
/usr/bin/git log -1 --format='%H'
'0f878e746fe9ce55a6c4b793c66f501c14c456f5'

日志中的一个 SHA 值引起了我的注意, 因为之前在 Jenkins 中碰到过一个 Git 记录找不到的问题。一个 SHA 就代表着一个版本记录。

然后, 我在本地 git checkout -f 0f878e746fe9ce55a6c4b793c66f501c14c456f5, 竟然提示找不到这条记录。将折叠的 Checking out the ref 日志展开:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
Checking out the ref
  /usr/bin/git checkout --progress --force refs/remotes/pull/3254/merge
  Note: switching to 'refs/remotes/pull/3254/merge'.

  You are in 'detached HEAD' state. You can look around, make experimental
  changes and commit them, and you can discard any commits you make in this
  state without impacting any branches by switching back to a branch.

  If you want to create a new branch to retain commits you create, you may
  do so (now or later) by using -c with the switch command. Example:

    git switch -c <new-branch-name>

  Or undo this operation with:

    git switch -

  Turn off this advice by setting config variable advice.detachedHead to false

  HEAD is now at 0f878e7 Merge 2ecc7398161e7a0211c59b52061c9e3800d28551 into 38eaa5cde0580ac4d29537065b687e090db557c6

Merge 2ecc7398161e7a0211c59b52061c9e3800d28551 into 38eaa5cde0580ac4d29537065b687e090db557c6, 原来 actions/checkout 默认将 Pull Requests 分支的代码合并到最新代码上, 产生了一条新记录。

问题的原因找到了, 研发在 fork 主干代码之后, 开发新的功能。但是在这个过程中, 主干分支已经合并了其他人的代码。当已经合并的代码与 Pull Requests 中的代码有冲突时, 就会导致这种现象。

解决问题的办法就是, 每次提交 Pull Requests 之前, 都重新拉取一次 upstream 的代码, 接着 rebase 解决冲突, 再提交。这里的冲突有两类, 一个是文件冲突, 另一种是功能冲突。

4. action/checkout 的参数解读

下面, 我们继续来看一看 action/checkout 的其他参数和功能。

  • fetch-depth 默认值为 1, 仅拉取当前分支。设置为 0 时, 拉取全部分支和 Tag 的记录。
1
2
3
- uses: actions/checkout@v2
  with:
    fetch-depth: 0
  • checkout 多个仓库的代码到指定目录
1
2
3
4
5
6
7
8
- name: Checkout
  uses: actions/checkout@v2

- name: Checkout tools repo
  uses: actions/checkout@v2
  with:
    repository: my-org/my-tools
    path: my-tools
  • checkout 到提交 Pull Requests 的记录上, 默认是 merge 之后的记录
1
2
3
- uses: actions/checkout@v2
  with:
    ref: ${{ github.event.pull_request.head.sha }}

微信公众号