Continuous Analysis For Your Rails Project Using Vile and CircleCI
In this post I am going to show you how to use Vile and CircleCI to continuously analyze your Rails project. For ease I will assume you have your project under some sort of source control, in this case Git and GitHub.
Getting Started
Unless you have an existing project create one first, and add it to source control:
Installing Vile
Getting and installing Vile is easy. If you don’t already have NodeJS installed, you can grab a copy here.
Then just add Vile using npm:
Or, if using you are using Yarn:
Picking Some Plugins
The core library and CLI comes with some general purpose plugins (coverage, stats, checking npm for updates), but we need to install additional plugins to perform more powerful types of analysis.
If you are using a non-JS language — in this case Ruby — you might also need to install peer dependencies using other package managers. In this case, all we need is npm
, gem
and bundler
:
Configuring Some Things
Most plugins support both the allow
and ignore
directives you can configure Vile with.
For starters, create a .vile.yml
in your project root that looks like this:
Note: some plugins might only support their own config file.
For example, in your .rubocop.yml
:
Tracking Test Coverage in Ruby
Vile’s coverage plugin currently supports lcov
data only. SimpleCov + simplecov-lcov is great for generating the right data. However setting it up is not covered in this tutorial, and it will be assumed you have successfully followed the install instructions or already use it.
You can also skip this part for now and you will just see a warning from the coverage plugin.
Testing It Out
By now you should be able to run vile analyze
and see all the issues and data that it generates.
A truncated example:
Uploading Your First Commit
Now that we have everything setup we can submit our first commit (of data) to vile.io.
Don’t worry if you don’t have vile-git
or any other vile SCM plugin installed as a commit SHA will be generated for you.
To get started:
- Login and generate an auth token (type: “all”)
- Create a new_project (in this case: “new_app”)
- Set some ENV vars and use the
--upload
flag:
And voilà! If everything went OK you should be able to browse your project’s updated dashboard, view commits, files, issues, and even see what new insights have been generated.
However, running Vile locally only gets you so far.
Ready to take it to the next level?
Continuous Analysis
By hooking Vile into a CI service like CircleCI, you can continuously build and analyze your code on every branch and commit you push.
Using another build server? No problem! As long as you run Vile anytime after your configure and test steps you‘ll be good to go.
With CircleCI, your circle.yml
should look something like this:
At this point you’re probably noticing the npm run -s vile
and wondering where the heck that is coming from.
With npm you can use the scripts section in your package.json.
This allows you to easily make use of the CLI without having to install a package globally.
Given that, your package.json
file should now look something like this:
Now we can just add our updated config and push our code:
Lastly if you haven’t already, grab a CircleCI account, add your repository, and then enable its first build to ensure everything works as expected.
Note: Don’t forget to set VILE_TOKEN
and VILE_PROJECT
on your build server before building!
Automatically Triggering Builds
We also highly recommend setting up a daily cron job on your build server to ensure your code is built, tested and analyzed in a routinely continuous way.
In the case of CircleCI you can easily configure Vile to automatically trigger builds by going to your project’s dashboard and clicking on the Integrations tab.
Putting It All Together
To recap, we added Vile to our project, set it up to run on every commit we push to our build server, and even set it up to test and analyze our project in a routinely continuous manner.
Using this setup we can constantly gain new insights, monitor for dependency releases, track code complexity and tech debt, get timely security alerts, and most importantly: keep an up-to-date high level project overview at all times.
For a good example of a project in action, checkout Vile’s public page here. If you have any questions or feedback please feel free to reach out to us on Twitter, send an email to support@vile.io, or even use our in-app help desk.
If you prefer, you can also peruse the full source code for the demo here.
And if you haven't already, checkout Vile on GitHub!
Happy punishing,
~ The Vile Team