为什么在本地工作时,Github Actions 中的代码检查(linting)无法正常工作?

huangapple go评论84阅读模式
英文:

Why doesn't linting in Github Actions work when it does locally?

问题

我正在构建一个Go项目,并且在每次提交时使用Github Actions。

项目在这里:https://github.com/filecoin-project/bacalhau

当我在本地运行项目时,它可以正常运行,例如:

❯ golangci-lint run

但是当我在Github Actions中运行相同的命令时,我会收到警告,就好像我没有正确地导入模块一样(猜测)。

  Error: undeclared name: `libp2p` (typecheck)
  Error: undeclared name: `libp2p` (typecheck)
  Error: undeclared name: `libp2p` (typecheck)
  Error: "github.com/libp2p/go-libp2p" imported but not used (typecheck)
  
  Error: issues found

即使我移除了linting,我也会遇到类似的问题(它无法正确构建 - 例如https://github.com/filecoin-project/bacalhau/runs/5313987141?check_suite_focus=true)。

唯一一次我亲自登录,通过ssh手动执行构建(例如go build),它也失败了,出现了相同的错误,但是通过执行go mod vendorgo mod tidy命令可以解决。然而,这应该是不必要的,对吗?因为我已经检入了vendor目录?

我漏掉了什么?谢谢!

英文:

I'm building a Go project, and i'm using Github actions on every checkin.

The project is here: https://github.com/filecoin-project/bacalhau

When I run the project locally, it runs fine - e.g.:

❯ golangci-lint run

But when I do the same command in Github Actions, I get warnings like I haven't vendored in the modules correctly (guessing).

  Error: undeclared name: `libp2p` (typecheck)
  Error: undeclared name: `libp2p` (typecheck)
  Error: undeclared name: `libp2p` (typecheck)
  Error: "github.com/libp2p/go-libp2p" imported but not used (typecheck)
  
  Error: issues found

Even when I remove the linting, I get similar problems (it doesn't build properly - e.g. https://github.com/filecoin-project/bacalhau/runs/5313987141?check_suite_focus=true

The ONE time I logged in myself, via ssh, and executed the build manually (e.g. go build) it failed with the same error, but this was solveable by just doing go mod vendor, go mod tidy inline. HOWEVER, this shouldn't be necessary, right? Because I've checked in a vendor directory?

What am I missing? Thanks!

答案1

得分: 0

我通过清空/vendor目录并将其添加到.gitignore文件中来解决了这个问题。这样可以强制GitHub actions重新下载所有内容。不确定这是否是最高效的解决方案,但对我有效!

英文:

I solved this by blowing away everything in my /vendor dir, and .gitignoring it. This forced GitHub actions to redownload everything. Not sure if this was the most efficient solution, but worked for me!

huangapple
  • 本文由 发表于 2022年2月25日 05:09:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/71258290.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定