Skip to content

Commit

Permalink
ci: setup database
Browse files Browse the repository at this point in the history
  • Loading branch information
FlandreDaisuki committed Oct 22, 2024
1 parent 7611c96 commit ba31ef9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,54 @@ jobs:

rspec_test:
runs-on: ubuntu-latest

# ref: https://docs.github.com/en/actions/use-cases-and-examples/using-containerized-services/creating-postgresql-service-containers
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres:14
# Provide the password for postgres
env:
POSTGRES_PASSWORD: rails_github_actions_pa55w0rd
POSTGRES_USER: rails_github_actions
POSTGRES_DB: rails_github_actions_test
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get -yqq install libpq-dev
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: .ruby-version
bundler-cache: true

# ref: https://blog.niclin.tw/2019/10/31/building-a-rails-ci-piepline-and-run-rspec-on-github-actions/
- name: Setup test database
env:
RAILS_ENV: test
PG_USERNAME: rails_github_actions
PG_PASSWORD: rails_github_actions_pa55w0rd
PG_HOST: localhost
PG_PORT: 5432
PG_DATABASE: rails_github_actions_test
run: |
cp config/database.ci.yml config/database.yml
bundle exec rake db:create db:migrate
- name: Run rspec
env:
RAILS_ENV: test
Expand Down
10 changes: 10 additions & 0 deletions config/database.ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# ref: https://blog.niclin.tw/2019/10/31/building-a-rails-ci-piepline-and-run-rspec-on-github-actions/
test:
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: <%= ENV['PG_USERNAME'] %>
password: <%= ENV['PG_PASSWORD'] %>
host: <%= ENV['PG_HOST'] %>
port: <%= ENV['PG_PORT'] %>
database: <%= ENV['PG_DATABASE'] %>

0 comments on commit ba31ef9

Please sign in to comment.