Skip to content

Instantly share code, notes, and snippets.

@tuomasj
Created May 6, 2022 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuomasj/5d7e5eeb17e9296227e318fe09e808ba to your computer and use it in GitHub Desktop.
Save tuomasj/5d7e5eeb17e9296227e318fe09e808ba to your computer and use it in GitHub Desktop.
Github Actions for CI -- Ruby on Rails, PostgreSQL, Redis, Elasticsearch in May 2022
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
services:
db:
image: postgres
ports: ['5432:5432']
env:
POSTGRES_DB: rails_test
POSTGRES_USER: rails
POSTGRES_PASSWORD: password
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis
ports: ['6379:6379']
options: --entrypoint redis-server
elasticsearch:
image: elasticsearch:7.17.1
ports: ['9200:9200']
options: -e="discovery.type=single-node" --health-cmd="curl http://localhost:9200/_cluster/health" --health-interval=10s --health-timeout=5s --health-retries=10
env:
RAILS_ENV: test
DATABASE_URL: "postgres://rails:password@localhost:5432/rails_test"
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v2
with:
node-version: 14
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0.1
bundler-cache: true
- name: Verify Elasticsearch connection from host
env:
ELASTIC_SEARCH_URL: http://localhost:${{ job.services.elasticsearch.ports[9200] }}
run: |
echo $ELASTIC_SEARCH_URL
curl -fsSL "$ELASTIC_SEARCH_URL/_cat/health?h=status"
- name: Build and create DB
run: bundle exec rails db:setup
- name: Install dependencies
run: |
bundle install
yarn install
- name: Run tests
env:
ELASTICSEARCH_URL: http://localhost:${{ job.services.elasticsearch.ports[9200] }}
run: |
echo $ELASTICSEARCH_URL
bundle exec rails test
- name: Run system tests
env:
ELASTICSEARCH_URL: http://localhost:${{ job.services.elasticsearch.ports[9200] }}
run: |
echo $ELASTICSEARCH_URL
bundle exec rails test:system
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment