Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby test and lint github action workflow #161

Merged
merged 3 commits into from
Jun 1, 2024
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
64 changes: 64 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
name: "Continuous Integration"

on:
push:
branches: ['main']
pull_request:
types: ['opened', 'reopened', 'synchronize', 'unlocked']

jobs:
ruby-lint:
name: Ruby Lint
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1.178.0
with:
ruby-version: '3.2.3'
bundler-cache: true # runs 'bundle install' and caches installed gems automatically

- name: Ruby Lint
run: bundle exec standardrb --parallel -f github

rails-test:
name: Rails Test
runs-on: ubuntu-latest

services:
postgres:
image: postgres:15
ports:
- "5432:5432"
env:
POSTGRES_DB: sif
POSTGRES_USER: sif
POSTGRES_PASSWORD: password
redis:
image: redis:7.0

env:
RAILS_ENV: test
DATABASE_URL: "postgres://sif:password@localhost:5432/sif"
REDIS_URL: "redis://localhost:6379/1"
BROWSERSLIST_IGNORE_OLD_DATA: true

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1.178.0
with:
ruby-version: '3.2.3'
bundler-cache: true # runs 'bundle install' and caches installed gems automatically

- name: Set up database
run: bin/rails db:setup

- name: Run tests
run: bin/rails test
5 changes: 5 additions & 0 deletions .standard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parallel: true
ruby_version: 3.2

plugins:
- standard-rails
6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ gem "tzinfo-data", platforms: %i[windows jruby]
group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[mri windows]

# a linting tool, to encourage/enforce a consistent code style
gem "standardrb"
gem "standard-rails"
end

group :development do
gem "bundler-audit"
gem "pry", "~> 0.14.2"
gem "standardrb"
# Use console on exceptions pages [https://github.com/rails/web-console]
gem "web-console"
end

Expand Down
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ GEM
rubocop-performance (1.21.0)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rails (2.23.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-ast (>= 1.30.0, < 2.0)
ruby-progressbar (1.13.0)
rubyzip (2.3.2)
sassc (2.4.0)
Expand Down Expand Up @@ -316,6 +321,9 @@ GEM
standard-performance (1.4.0)
lint_roller (~> 1.1)
rubocop-performance (~> 1.21.0)
standard-rails (1.0.2)
lint_roller (~> 1.0)
rubocop-rails (~> 2.23.1)
standardrb (1.0.1)
standard
stimulus-rails (1.3.3)
Expand Down Expand Up @@ -376,6 +384,7 @@ DEPENDENCIES
selenium-webdriver
shadcn-ui (~> 0.0.12)
sprockets-rails
standard-rails
standardrb
stimulus-rails
turbo-rails
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ services:
POSTGRES_PASSWORD: password
POSTGRES_DB: sif
ports:
- 5432
- 5432:5432
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this intended? (not too familiar with myself)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think one port is the port inside the container and the other is outside the container (or the other way around)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! This lets the postgres docker image be useable from your host machine.

So if you're comfortable with docker, you could run docker compose up -d db from this project directory and have Postgres without having to install it on your OS directly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in docker configuration--ports and volumes in particular--the colon-separated thing:thing refers to outside:inside or host:image.

In this case, 5432:5432 read left to right says, "expose on port 5432 on my host machine the port 5432 from inside the docker container".

When we use a single value like 5432, it means "the docker container I'm describing should expose port 5432 to other containers on the same network." "The same network" here means the other services named in docker-compose.yml.

healthcheck:
test: ["CMD-SHELL", "pg_isready", "--database", "stocks_in_the_future_development" ]
interval: 10s
Expand Down
Loading