在构建阶段执行go generate

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

go generate on build stage

问题

在一些构建系统(如Gradle或Blaze)中,我可以在构建阶段生成代码(如ent或proto),而不将其添加到代码库中。

是否可以对go build命令执行相同的操作?

英文:

In some build systems like gradle or blaze I can generate code (ent or proto) on a build stage and don't add in to a repository.

Is it possible to do the same for the go build command?

答案1

得分: 2

是的,如果你在 CI 脚本中将 "go generate" 添加为预构建步骤,可以这样做。

$ go generate
$ go build
$ go test

但我建议更实用的方法是将生成的代码存储在你的代码库中,并在 CI 中进行检查 - 运行 go generate 并断言是否有更改。

链接:

英文:

Yes, if you add "go generate" as your pre-build step in CI script.

$ go generate
$ go build
$ go test

But I would recommend more practical approach: to store your generated code in your repo and check it on CI - run go generate and assert that there is no changes.

Links

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

发表评论

匿名网友

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

确定