CI for Windows Go Packages with AppVeyorJul 9, 2014
I recently needed to update my npipe package, and since I want it to be production quality, that means setting up CI, so that people using my package can know it’s passing tests. Normally I’d use Travis CI or Drone.io for that, but npipe is a Windows-only Go package, and neither of the aforementioned services support running tests on Windows.
With some googling, I saw that Nathan Youngman had worked with AppVeyor to add Go support to their CI system. The example on the blog talks about making a build.cmd file in your repo to enable Go builds, but I found that you can easily set up a Go build without having to put CI-specific files in your repo.
To get started with AppVeyor, just log into their site and tell it where to get your code (I logged in with Github, and it was easy to specify what repo of mine to test). Once you choose the repo, go to the Settings page on AppVeyor for that repo. Under the Environment tab on the left, set the clone directory to C:\GOPATH\src<your import path> and set an environment variable called GOPATH to C:\GOPATH. Under the build tab, set the build type to “SCRIPT” and the script type to “CMD”, and make the contents of the script
go get -v -d -t <your import path>/…(this will download the dependencies for your package). In the test tab, set the test type to “SCRIPT”, the script type to “CMD” and the script contents to
go test -v -cover ./…(this will run all the tests in verbose mode and also output the test coverage).
That’s pretty much it. AppVeyor will automatically run a build on commits, like you’d expect. You can watch the progress on a console output on their page, and get a pretty little badge from the badges page. It’s free for open source projects, and seems relatively responsive from my admittedly limited experience.
This is a great boon for Go developers, so you can be sure your code builds and passes tests on Windows, with very little work to set it up. I’m probably going to add this to all my production repos, even the ones that aren’t Windows-only, to ensure my code works well on Windows as well as Linux.