This week I attended OpenStack Summit in Vancouver, while the overwhelming focal point was containers, CI/CD systems got some healthy attention. Among the conversation was where small projects should get their CI of which third party, self hosted, bash scripts, etc were all options.
The consensus was that hosting your own Jenkins for fun was a great option (blog post on self-hosted Jenkins in K8s coming soon) but for those who don’t want to maintain your own CI system there are several incredibly simple options that are free for open source projects.
I’m going to focus on Travis-CI as it is the dominate, free, hosted CI, and came highly recommended from the conversations at the summit.
I decided to test it on a project I created to learn Golang; a one time password (OTP) library which can be found here.
- Sign in to Travis with your GitHub account and add your repository
- Add a
.travis.ymlfile to your project root with the following
language: go # versions to test go: - 1.9 - release - tip # get dependencies before_install: - go get -t -v ./... # run tests script: - go test -v -race ./...
All your commits will now run CI test builds
The Travis dashboard has pregenerated badges you can add to your project to show your current build status.
Want Code Coverage?!
Adding code coverage is simple. I tested a few services and found CodeCov to be the best. Here’s how to get easy, simple code coverage monitoring
- Login to CodeCov with yout GitHub account
- Add your repository to your watch list
- Update your
.travis.ymlwith these to
language: go # versions to test go: - 1.9 - release - tip # get dependencies before_install: - go get -t -v ./... # run tests script: - go test -race -coverprofile=coverage.txt -covermode=atomic # push results to CodeCov after_success: - bash <(curl -s https://codecov.io/bash)
Kepe in mind this is a very simple implementation and there are endless customizations that one can use. Here’s a much more expansive example .travis.yml build script.
If you go with the more expansive route I would recommend setting up some pre-commit hooks to run the linters and gocyclo to remove added frustration of having to go back and forth yak-shaving.