为何需要访问私有存储库执行 `go list -mod=readonly -m all`?
时间:2024-03-06
浏览:249
作者:佚名
Golang不知道大家是否熟悉?今天我将给大家介绍《为何需要访问私有存储库执行 `go list -mod=readonly -m all`?》,这篇文章主要会讲到等等知识点,如果你在看完本篇文章后,有更好的建议或者发现哪里有问题,希望大家都能积极评论指出,谢谢!希望我们能一起加油进步!
问题内容
我正在尝试打印具有供应商目录的 go 项目中的直接依赖项列表:
go list -mod=readonly -m -f '{{ if not .indirect }}{{ .path }}{{ end }}' all
据我了解,我必须使用 -mod=readonly 因为 go list 拒绝根据供应商中的部分信息进行报告。这在我的笔记本电脑上有效,因为我可以访问私人存储库 github.com/monzo/argo-rollouts,但在 ci 中失败并显示:
go list -m: github.com/argoproj/[email protected] (replaced by github.com/monzo/[email protected]): version "v0.0.0-20220309162305-84c86ea52e8f" invalid: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /home/circleci/go/pkg/mod/cache/vcs/052bf06be1713582ba9f1144e9982b362ff355fec71675863c108f9cf5a00bb4: exit status 128:
error: repository not found.
fatal: could not read from remote repository.
please make sure you have the correct access rights
and the repository exists.
为什么 go list -mod=readonly 需要访问私有存储库?我没有提供-u。
此外,为什么在供应商模式下无法在本地获取此信息?
编辑:我找到了一种解决方法,可以在供应商模式下将符合条件的模块传递给 go list -m,但它涉及解析仅适用于计算机的不稳定的供应商/modules.txt 文件。
% cat modules-that-provide-packages.awk
BEGIN {
mod = ""
}
# Remember the module
/^# / {
mod = $2
}
# Print the module if it provides a package
!/^# / {
print mod
}
% awk -f modules-that-provide-packages.awk vendor/modules.txt /
| sort -u \
| xargs go list -m -f '{{ if not .Indirect }}{{ .Path }}{{ end }}'正确答案
我认为答案是:go list -m 不需要访问私有存储库,但填充一个空的 GOMODCACHE 需要。
go list -m 从以下任一位置获取模块信息:
GOMODCACHE,但这必须已填充。 CI 中它是空的,所以 Go 会尝试从私有仓库下载。因此出现错误。vendor目录,但您必须提供特定模块。go 列表 -m allgives up in vendor-mode。
今天关于《为何需要访问私有存储库执行 `go list -mod=readonly -m all`?》的内容就介绍到这里了,是不是学起来一目了然!想要了解更多关于的内容请关注golang学习网公众号!
本文内容来源于互联网,如有侵权请联系删除。
近期热门
11.18
11.15
站内热门
最新文章
11.20
11.20
11.20
11.20
热门专题
