Martín Verzilli

Martín Verzilli

Using CircleCI for your Crystal projects

4 min
Jun 13 2016
crystal, devops
4 min
Jun 13 2016

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 meets Crystal

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:

  1. 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:.
  2. 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).
  3. 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 in dependencies: pre:.
  4. 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 standard crystal spec command from test: 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 :).