Last active
August 16, 2022 14:59
-
-
Save peimelo/e730df30b15807e938a8363ea4fc76c7 to your computer and use it in GitHub Desktop.
Ruby on Rails Tests - GitHub Actions + Publish code coverage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/database.ci.yml | |
test: | |
adapter: postgresql | |
encoding: unicode | |
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> | |
database: <%= ENV["POSTGRES_DB"] %> | |
username: <%= ENV['POSTGRES_USER'] %> | |
password: <%= ENV["POSTGRES_PASSWORD"] %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .github/workflows/ruby.yml | |
name: Ruby | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
env: | |
POSTGRES_DB: postgres | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: password | |
jobs: | |
test: | |
name: Test | |
environment: controlled-health-api | |
runs-on: ubuntu-latest | |
services: | |
postgres: | |
image: postgres:12 | |
ports: ['5432:5432'] | |
env: | |
POSTGRES_PASSWORD: password | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Setup Ruby | |
uses: ruby/setup-ruby@v1 | |
with: | |
ruby-version: 3.0.4 | |
bundler-cache: true | |
- name: Install dependencies | |
run: | | |
sudo apt-get update && sudo apt-get -yqq install libpq-dev | |
bundle install --jobs 4 --retry 3 | |
- name: Run tests | |
env: | |
RAILS_ENV: test | |
PGHOST: localhost | |
DISABLE_SPRING: 1 | |
run: | | |
cp config/database.ci.yml config/database.yml | |
bundle exec rails db:schema:load | |
bundle exec rspec --format progress | |
- name: Publish code coverage | |
uses: paambaati/[email protected] | |
env: | |
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment