Skip to content

Instantly share code, notes, and snippets.

@pmatv
Created June 1, 2021 07:43
Show Gist options
  • Save pmatv/e0432656946f460b0d7aac15b6d2bbec to your computer and use it in GitHub Desktop.
Save pmatv/e0432656946f460b0d7aac15b6d2bbec to your computer and use it in GitHub Desktop.
Run Rspec tests in parallel
name: app
on:
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-18.04
services:
database:
image: postgres:12.1-alpine
env:
POSTGRES_USER: app
POSTGRES_PASSWORD: pass
ports:
- '5432:5432'
redis:
image: redis
ports:
- 6379:6379
options: --entrypoint redis-server
search:
image: elasticsearch:6.8.2
ports:
- 9200:9200
env:
discovery.type: single-node
strategy:
fail-fast: false
matrix:
# Set N number of parallel jobs you want to run tests on.
# Use higher number if you have slow tests to split them on more parallel jobs.
# Remember to update ci_node_index below to 0..N-1
ci_node_total: [8]
#ci_node_total: [2]
# set N-1 indexes for parallel jobs
# When you run 2 parallel jobs then first job will have index 0, the second job will have index 1 etc
ci_node_index: [0,1,2,3,4,5,6,7]
#ci_node_index: [0,1]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6.6
bundler: Gemfile.lock
- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.bundle
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-
- name: Install dependencies
run: |
bundle config path ~/.bundle
bundle install --jobs 4 --retry 3
- name: Set up Database
env:
DATABASE_URL: postgresql://app:pass@localhost:5432/app_test
RACK_ENV: test
run: |
bundle exec rake db:create
bundle exec rake db:migrate
- name: Run Unit Tests
env:
DATABASE_URL: postgresql://app:pass@localhost:5432/app_test
REDIS_HOST: redis://localhost:6379/0
ELASTICSEARCH_URL: http://localhost:9200
RACK_ENV: test
CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
CI_NODE_INDEX: ${{ matrix.ci_node_index }}
CI_PARALLEL_TESTS: true
run: bundle exec rake "knapsack:rspec[-f RspecJunitFormatter -o reports/rspec/report.xml -f documentation]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment