We linked to a gist with the `circle.yml` example described in this post from Crystal's wiki.
One of the first things we do when we bootstrap a project at Manas is to set up a continuous integration server. Since in general we use GitHub, for open source projects Travis is a no brainer. However, we also work on a number of private repositories for which Travis has strong competition: CircleCI.
CircleCI offers a single CI container for unlimited private repositories on its free tier plan. It’s great if you are playing around with dozens of little projects that aren’t quite ready for primetime, but you still want to hold onto best practices without skyrocketing costs.
These days we’re exactly in that situation, experimenting with our beloved Crystal on a number of different applications.
You’d think using CircleCI to build applications that use novel programming languages like Crystal should make you hate your life. Actually, it turns out to be a rather pleasant experience! Just add a circle.yml
file to your project’s root directory with the contents below.
A couple of remarks:
- Crystal doesn’t ship with the main Linux distributions (yet), neither is it natively supported by CircleCI (yet). That’s why we need to install it manually, as you can see in
dependencies: pre:
. - CircleCI uses Ubuntu, so you may be wondering why we don’t use Crystal’s official APT repository instead of the self-contained tar.gz package. The reason is that currently CircleCI’s cache doesn’t play well with APT (see next bullet).
- We’re taking advantage of CircleCI’s cache feature, which significantly reduces build times if your dependencies don’t change often. We achieve that by listing Crystal’s target directory in
dependencies: cached_directories:
and then conditionally executing the installation commands independencies: pre:
. - Again, since CircleCI currently doesn’t provide support Crystal out of the box, we need to tailor how tests get run. We just make sure to install shards before running (
test: pre:
) and then run the standardcrystal spec
command fromtest: override
.
That’s it! You now have no excuses to not write beautiful, performant code in Crystal, resting safe on a robust continuous integration environment that has your back covered in case of regressions :).