travis-ci中的go.mod更改 [英] go.mod changes in travis-ci
问题描述
我已经升级了项目以使用go 1.11.2模块支持.但是,我遇到了一个非常烦人的问题. go.mod文件的CI不断变化.每天都有不同的文件.今天,go.sum中的行是:
I have upgraded my project to use go 1.11.2 modules support. However, I am running into a very annoying problem. The go.mod file keeps changing in CI. It is a different file each day. Today the lines in go.sum is:
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd h1:HuTn7WObtcDo9uEEU7rEqL0jYthdXAmZ6PP+meazmaU=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
go.mod是:
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd // indirect
我没有更新任何依赖项.他们没有锁!为什么不?如果依赖关系不断变化,这将是一个很大的问题.但是,我看不到其他人对此问题大喊大叫.所以我一定做错了.
I did not update any dependencies. They are not locking! Why not? This is a really big problem if dependencies are constantly changing. However, I do not see others screaming about this problem. So I must be doing something wrong.
我正在使用go mod tidy
在git diff --exit-code
之前将其同步.这在本地有效,但不适用于Travis-CI.我认为这是一个问题,因为在Travis-CI上它需要获取依赖项,并且由于这些依赖项不使用语义版本控制,因此Go可以获取最新的,每次提交到master时都会更改.如果您同意这是问题所在,该如何锁定Go模块的依赖关系?
I am using go mod tidy
to sync it up before a git diff --exit-code
. This works locally but not on Travis-CI. I think it is a problem because on Travis-CI it needs to grab the dependencies and since these dependencies do not use semantic versioning, Go grabs the latest, which changes on every commit to master. If you agree this is the problem, how do I lock dependencies with Go modules?
推荐答案
维基解释了如何使用尚未加入go模块的软件包
The wiki explains how to consume a package that hasn't opted into go modules
以下是相关片段:
如果存储库没有任何有效的semver标签,则 存储库的版本将以伪版本"记录,例如 v0.0.0-20171006230638-a6e239ea1c69(其中包括时间戳和 提交哈希,其目的是允许对整个哈希进行排序 在go.mod中记录了版本,并使其更容易推断出哪个版本 记录的版本比另一个记录的版本晚".
If the repository does not have any valid semver tags, then the repository's version will be recorded with a "pseudo-version" such as v0.0.0-20171006230638-a6e239ea1c69 (which includes a timestamp and a commit hash, and which are designed to allow a total ordering across versions recored in go.mod and to make it easier to reason about which recorded versions are "later" than another recorded version).
您也可以require
个特定的提交哈希值:
You can require
specific commit hashes too:
需要时,可以选择更具体的依赖版本 命令,例如go get foo@v1.2.3,go get foo @ master,go get foo @ e3702bed2,或直接编辑go.mod.
When needed, more specific versions of dependencies can be chosen with commands such as go get foo@v1.2.3, go get foo@master, go get foo@e3702bed2, or by editing go.mod directly.
这篇关于travis-ci中的go.mod更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!