Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,66 @@ on:
jobs:
test:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:14
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: quote_editor_test
ports:
- 5432:5432
options: >-
--health-cmd="pg_isready -U postgres"
--health-interval=10s
--health-timeout=5s
--health-retries=5

chrome:
image: selenium/standalone-chrome:latest
ports:
- 4444:4444
options: >-
--add-host=host.docker.internal:host-gateway
--shm-size=2g

env:
RAILS_ENV: test
DATABASE_URL_TEST: postgres://postgres:postgres@127.0.0.1:5432/quote_editor_test
SELENIUM_REMOTE_URL: http://127.0.0.1:4444/wd/hub

steps:
- uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: "18"
cache: "yarn"

- name: Install JS deps
run: yarn install --frozen-lockfile

- name: Check Postgres is reachable
run: |
sudo apt-get update
sudo apt-get install -y postgresql-client
PGPASSWORD=postgres psql -h 127.0.0.1 -U postgres -d quote_editor_test -c "select 1;"

- name: Show DB env vars
run: |
echo "RAILS_ENV=$RAILS_ENV"
echo "DATABASE_URL=$DATABASE_URL"
echo "DATABASE_URL_TEST=$DATABASE_URL_TEST"

- name: Prepare DB
run: bin/rails db:prepare

- name: Run system tests
run: bin/rails test:system
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ GEM
nio4r (2.7.5)
nokogiri (1.17.2-aarch64-linux)
racc (~> 1.4)
nokogiri (1.17.2-x86_64-linux)
racc (~> 1.4)
pg (1.6.3-aarch64-linux)
pg (1.6.3-x86_64-linux)
pp (0.6.3)
prettyprint
prettyprint (0.2.0)
Expand Down Expand Up @@ -243,6 +246,7 @@ GEM

PLATFORMS
aarch64-linux
x86_64-linux

DEPENDENCIES
bootsnap
Expand Down
12 changes: 10 additions & 2 deletions test/application_system_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :remote_chrome

setup do
Capybara.server_host = "0.0.0.0"
Capybara.app_host = "http://web:#{Capybara.server_port}"
if ENV["GITHUB_ACTIONS"] == "true"
# CI: Rails runs on the runner, Chrome runs in a container.
# Bind Rails to all interfaces, and have Chrome reach the runner via host gateway.
Capybara.server_host = "0.0.0.0"
Capybara.app_host = "http://host.docker.internal:#{Capybara.server_port}"
else
# Docker Compose: both services on the same docker network
Capybara.server_host = "0.0.0.0"
Capybara.app_host = "http://web:#{Capybara.server_port}"
end
end
end