I’m a big fan of GitHub Actions, especially the robust ecosystem of actions that can be included into continuous integration pipelines with just a few lines of configuration code. And thanks to the devcontainers/ci action, using an existing development container setup could make running a test suite or other common CI processes much, much simpler than it might have been in the past.
First off, this assumes you’ve already got your application set up to support devcontainer-based development, with a test suite that runs from within the container. If you don’t, this is as good a time as any to set one up.
Once that’s in place, create a file in .github/workflows to add the workflow. Name it something like ci.yml. Here’s what mine looks like:
name: Run test suite
- name: Check out code
- name: "Create environment files"
cp config/database-ci.yml config/database.yml
cp .sample.env .env
- name: run tests
runCmd: bin/rspec --format documentation
Let’s break this down. I’ve set up the workflow to run any time a push is made to the main or staging branch, or a pull request is opened against either of those branches.
I’ve defined a job to run tests. The job is broken into three steps:
That’s it! It may take some trial and error to work end-to-end. Approach it scientifically—change one thing, let it run, course-correct, and try again. When I’m creating a new GitHub Actions-based workflow, or updating an existing one, I usually create a draft pull request and make incremental changes to it, sneaking up gradually on the final solution.
If you liked my series on practical advice for adding reliable tests to your Rails apps, check out the expanded ebook version. Lots of additional, exclusive content and a complete sample Rails application.
Ruby on Rails news and tips, and other ideas and surprises from Aaron at Everyday Rails. Delivered to your inbox on no particular set schedule.