对于 CI 服务器,推荐使用的 Go 构建系统是什么?

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

Recommended Go build system for a CI server?

问题

所以我有一个使用go-gettable依赖项和测试等的Go项目。

我想将其集成到Jenkins中。除了编写makefile之外,有没有其他人推荐的用于此用例的自动构建系统?

我需要:

  1. 自动安装go-get依赖项(它们当然可以在规范文件中)
  2. 递归构建。
  3. 运行测试。
  4. GOPATH/GOROOT管理(用于隔离SDK和路径)

我以前使用过godag来完成这种工作,但它似乎有点不维护了。

编辑:目前,我使用以下脚本直接输入到Jenkins作为构建步骤:

#这个命令获取依赖项但不安装它们,避免权限问题
go get -d

#构建包,-x输出编译器命令行
go build -x

#这个有点棘手 - ./... 表示“对于每个子包递归执行”
go test ./...
英文:

So I have a go project with go-gettable dependencies, tests, etc.

I want to integrate it into Jenkins. Is there an automated build system for go that anyone recommends for this use case, other than writing makefiles?

I need:

  1. <s>automatic installation of go-get deps (they can be in a spec file of course)</s>
  2. recursive build.
  3. running tests.
  4. GOPATH/GOROOT management (to isolate SDKs and paths)

I've used godag in the past for this sort of job but it seems a bit unmaintained.

EDIT: For the time being I'm living with the following script entered directly into Jenkins as a build step:

#this gets the dependencies but doesn&#39;t install them, avoiding permission problems
go get -d

#build the packages, -x outputs the compiler command line
go build -x

#this was tricky - ./... means &quot;for each sub-package recursively&quot;
go test ./... 

答案1

得分: 8

你也可以使用TeamCity来完成这个任务。

以下是一个构建Terraform的示例。

TeamCity代理设置:

  • 安装Go
  • 将Go添加到环境变量中
  • 不要忘记重新启动代理,因为路径已更改

TeamCity构建设置:

  • 使用代理端检出(如果我们想要包括.git文件夹,因为很多构建脚本都会使用它)

  • 使用检出规则(我们想要使用Go的约定):

    +:. => src/github.com/mitchellh/terraform

构建步骤:

echo cd %system.teamcity.build.checkoutDir%
cd "%system.teamcity.build.checkoutDir%"
path=C:\Program Files (x86)\Git\bin;%env.Path%;%system.teamcity.build.checkoutDir%\bin;
echo path=C:\Program Files (x86)\Git\bin;%env.Path%;%system.teamcity.build.checkoutDir%\bin;
set GOPATH=%system.teamcity.build.checkoutDir%
echo set GOPATH=%system.teamcity.build.checkoutDir%

echo "获取依赖项"
go get golang.org/x/tools/cmd/vet
go get golang.org/x/tools/cmd/cover
go get golang.org/x/tools/cmd/stringer
go get github.com/mitchellh/gox

echo cd %system.teamcity.build.checkoutDir%\src\github.com\mitchellh\terraform
cd "%system.teamcity.build.checkoutDir%\src\github.com\mitchellh\terraform"

echo "更新资源"
go get ./...

echo "运行静态代码分析"
go tool vet -asmdecl -atomic -bool -buildtags -copylocks -methods -nilfunc -printf -rangeloops -shift -structtags -unsafeptr .

echo "构建"
cd scripts
sh build.sh

echo "运行单元测试"
go test -timeout=30s -parallel=4

echo "运行代码覆盖率"
go test -coverprofile=coverage.out
go tool cover -html=coverage.out
rm coverage.out
英文:

You can do it with teamcity as well.

Here is an example for building terraform.

Teamcity agent setup:

  • Install Go
  • Add Go to path
  • Don't forget to restart agent as path was changed

Teamcity build setup:

  • Use agent side checkout (if we want to include the .git folder, which a lot of build scripts make use of)

  • Use checkout rule (we want to use the Go convention):

    +:. => src/github.com/mitchellh/terraform

Build steps:

echo cd %system.teamcity.build.checkoutDir%
cd &quot;%system.teamcity.build.checkoutDir%&quot;
path=C:\Program Files (x86)\Git\bin;%env.Path%;%system.teamcity.build.checkoutDir%\bin;
echo path=C:\Program Files (x86)\Git\bin;%env.Path%;%system.teamcity.build.checkoutDir%\bin;
set GOPATH=%system.teamcity.build.checkoutDir%
echo set GOPATH=%system.teamcity.build.checkoutDir%

echo &quot;Getting dependancies&quot;
go get golang.org/x/tools/cmd/vet
go get golang.org/x/tools/cmd/cover
go get golang.org/x/tools/cmd/stringer
go get github.com/mitchellh/gox

echo cd %system.teamcity.build.checkoutDir%\src\github.com\mitchellh\terraform
cd &quot;%system.teamcity.build.checkoutDir%\src\github.com\mitchellh\terraform&quot;

echo &quot;Update resources&quot;
go get ./...

echo &quot;Run static code analysis&quot;
go tool vet -asmdecl -atomic -bool -buildtags -copylocks -methods -nilfunc -printf -rangeloops -shift -structtags -unsafeptr .

echo &quot;Build&quot;
cd scripts
sh build.sh

echo &quot;Run unit tests&quot;
go test -timeout=30s -parallel=4

echo &quot;Run code coverage&quot;
go test -coverprofile=coverage.out
go tool cover -html=coverage.out
rm coverage.out

答案2

得分: 2

我正在使用在Mac上运行的Team City构建服务器,它运行一个rake文件,在rake文件中,我执行所有的命令来获取依赖项(go gets),运行测试并构建到正确的环境。

如果你需要在编写Rake文件方面的指导,请告诉我。

另外,我一直在使用这个框架为REST API创建功能测试。这个框架已经多次帮助我节省了代码。你可以在http://github.com/DigitalInnovation/cucumber_rest_api找到它。

英文:

I am using a Team City build server on a Mac that runs a rake file, in the rake file I do all the commands to get dependancies, (go gets), tests and builds to the correct environment.

let me know if you want any pointers in writing the Rake files,

As a side note, i have been creating functional tests for REST Api's using this frame work. This has saved my code many times over. http://github.com/DigitalInnovation/cucumber_rest_api

答案3

得分: 0

自2019年8月起,TeamCity 2019.1现在直接支持Go语言。请参阅“在TeamCity中构建Go程序”。

要在TeamCity中启用Go支持,您需要:

  • 进入“构建配置设置”|“构建特性”页面,
  • 点击“添加构建特性”,
  • 从列表中选择“Golang”。

对于 CI 服务器,推荐使用的 Go 构建系统是什么?

TeamCity内置支持Go语言,无需安装外部插件。TeamCity解析go test命令的执行结果,并将结果持久化存储,可以从历史角度查看这些数据。因此,所有与测试报告相关的TeamCity功能现在都适用于Go开发人员。

英文:

Since August 2019, TeamCity 2019.1 now supports Go directly.
See "Building Go programs in TeamCity"

> To enable Go support in TeamCity,

> - go to Build Configuration Settings | Build Features,

  • click Add build feature, and
  • select Golang from the list.

对于 CI 服务器,推荐使用的 Go 构建系统是什么?

> Support for Go is provided by TeamCity out of the box, there are no external plugins required.
TeamCity parses results of go test command execution. The results are persisted and it is possible to review the figures in a historical perspective.
Consequently, all the TeamCity features that are related to test reporting are now available for Go developers.

huangapple
  • 本文由 发表于 2014年1月15日 18:04:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/21134345.html
匿名

发表评论

匿名网友

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

确定