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

推荐订阅源

WordPress大学
WordPress大学
L
LangChain Blog
D
Docker
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏
S
Secure Thoughts
AI
AI
T
The Blog of Author Tim Ferriss
月光博客
月光博客
U
Unit 42
M
MIT News - Artificial intelligence
P
Proofpoint News Feed
N
News and Events Feed by Topic
酷 壳 – CoolShell
酷 壳 – CoolShell
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
腾讯CDC
Last Week in AI
Last Week in AI
B
Blog
Stack Overflow Blog
Stack Overflow Blog
F
Full Disclosure
博客园 - 司徒正美
博客园 - 三生石上(FineUI控件)
H
Hacker News: Front Page
博客园 - 叶小钗
S
SegmentFault 最新的问题
S
Security @ Cisco Blogs
H
Help Net Security
Recorded Future
Recorded Future
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
阮一峰的网络日志
阮一峰的网络日志
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
Tenable Blog
Jina AI
Jina AI
云风的 BLOG
云风的 BLOG
P
Privacy International News Feed
T
Threat Research - Cisco Blogs
Cloudbric
Cloudbric
爱范儿
爱范儿
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
O
OpenAI News
SecWiki News
SecWiki News
Latest news
Latest news
T
Tor Project blog
The Cloudflare Blog
C
Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
L
Lohrmann on Cybersecurity

陈少文的网站

巨变与机遇的未来十年 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) 使用 Velero 备份 Kubernetes 集群 Kubernetes Cheat Sheet 开发 Tips(18) 如何构建一个 Java 工程 开发 Tips(17) KubeSpray 安装 Kubernetes 报错 ip in ansible_all_ipv4_addresses 基于 Kubernetes 和 Jenkins 搭建自动化测试系统 在 Kubernetes 上动态创建 Jenkins Slave 使用 Jenkins 进行服务拨测 开发 Tips(16) Kubernetes 签发 Ingress 证书及日常故障运维 Kubernetes 中 Deployment 的基本操作 Kubernetes 中的证书 如何使用 KubeBuilder 开发一个 Operator Kubernetes 1.6.0 安装问题汇总 镜像管理工具 -- Harbor 开发 Tips(15) Docker 如何拉取镜像 开发 Tips(14) 使用 Helm 安装 harbor 开发 Tips(13) 使用 S2I 构建云原生应用 在 Kubernetes 中使用 emptyDir、hostPath、localVolume 开发 Tips(12) 开发 Tips(11) 代码质量分析工具 SonarQube 使用 Kubeadm 安装 Kubernetes 集群 一起来学 Go --(4)常用函数 Kubernetes 中的 Ceph Kubernetes 之 Volumes Kubernetes 之 Labels、Selectors 开发 Tips(10) 开源正在重构商业模式 Kubernetes 之网络 Kubernetes 之 API 使用 Helm 和 Operator 快速部署 Prometheus Kubernetes 复杂有状态应用管理框架 -- Operator Kubernetes 的包管理器 -- Helm 一起来学 Go --(3)Go Modules 如何一步一步地优化博客方案 kubectl 实用指南 Kubernetes 中的基本概念 搭建远程 Kubernetes 开发环境 大公司和小公司的 ToB 思路 开发 Tips(9) Go 入门指南 一起来学 Go --(2)数据与逻辑结构 如何预防 Web 富文本中的 XSS 攻击 django-xss-cleaner 云工作时代 一起来学 Go --(1)背景与特点 SaaS 开发团队的不同阶段 你不知道的 Git 使用技巧 输出既服务 微服务设计 继续奔跑 开发 Tips(8) 从账户安全到二次验证 Django 性能之数据库查询优化 Django 性能之分库分表 敏捷开发之研发流程 打造一致性的团队 开发 Tips(7) Pytest 进阶学习之 Mock PaaS 部署之 buildpack Go 开发配置 领域输出才是 PaaS 的核心竞争力 Pytest 入门学习 开发 Tips(6) 如何使用 Jenkins、Docker、GitLab 搭建 Django 自动化部署流程
本地执行没问题, 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 }}

微信公众号