Run rails tests with github actions matrix strategy
You can easily speedup tests runs by using matrix strategy with github actions.
Create a script called for example ci_tests which generates for example the following JSON output:
{
"include": [
{
"name": "System tests",
"files": "test/controllers/home_controller_test.rb test/controllers/onboarding_controller_test.rb"
},
{
"name": "Model tests",
"files": "test/models/user_test.rb test/models/post_test.rb"
}
]
}
Create a github action workflow:
name: CI
on: \[push\]
jobs:
configure:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
\- name: Checkout to repository
uses: actions/checkout@v4
\- name: Set matrix data
id: set-matrix
run: echo "matrix=$(jq -c . <<< $(./ci\_tests))" >> $GITHUB\_OUTPUT
tests:
runs-on: ubuntu-latest
needs: configure
strategy:
matrix: ${{ fromJson(needs.configure.outputs.matrix) }}
name: ${{ matrix.name }}
steps:
\- uses: actions/checkout@v4
...
- name: Run tests
env:
RAILS\_ENV: test
run: |
./bin/rails test ${{matrix.files}}
Credits
- Illustration générée par intelligence artificielle
Comments
Leave a comment
Your comment will appear after moderation.
Your name and email are only used to identify your comment. Your email is never shown publicly. Privacy policy.
Related articles
Docker
Self-Hosting a Docker Registry for Kamal Deployments
Self-Hosting a Docker Registry for Kamal Deployments Moving from GitHub Container Registry to a private, self-hosted registry on your local…
Read the article →
Homelab
My Automated Tech News Digest with Claude Cowork Schedules
There are tasks we keep pushing back. Not because they're hard, but because they're repetitive and time-consuming. Daily tech news is one…
Read the article →
Homelab
Build a daily tech digest with n8n, RSS and OpenAI
What you'll build: an automated workflow that aggregates 16 RSS sources every morning (Reddit, Hacker News, newsletters, FR/EN blogs),…
Read the article →