Skip to content

Commit

Permalink
feat: add a Github Action for linting, security & testing (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tao-Galasse committed Sep 23, 2024
1 parent 58733bc commit c31d36d
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 6 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Ruby

on:
push:
branches: [ master ]
pull_request: {}

env:
DATABASE_URL: postgres://postgres:[email protected]:5432/test
BASE_URL: localhost:3000

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3.5
bundler-cache: true
- name: Run rubocop
run: bundle exec rubocop

security:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3.5
bundler-cache: true
- name: bundler-audit
run: bundle exec bundle audit check --update
- name: Brakeman
run: bundle exec brakeman

test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres
ports:
- 5432:5432
env:
POSTGRES_PASSWORD: test
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3.5
bundler-cache: true
- name: Create database
run: bundle exec bin/rails db:create db:migrate RAILS_ENV=test
- name: Run tests
run: bundle exec rails test:prepare && bundle exec rails test && bundle exec rspec
- name: SimpleCov+ Action
uses: joshmfrankel/simplecov-check-action@main
with:
minimum_suite_coverage: 100
github_token: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ group :development, :test do
gem 'pry-rails', '~> 0.3.9'
gem 'rspec-rails'
gem 'rspec_api_documentation', '~> 6.1'
gem 'simplecov', '~> 0.17.1', require: false
gem 'simplecov', require: false
gem 'simplecov-json', require: false
gem 'faker', '~> 2.7'
end

Expand Down
15 changes: 10 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,15 @@ GEM
connection_pool (>= 2.2.5, < 3)
rack (~> 2.0)
redis (>= 4.5.0, < 5)
simplecov (0.17.1)
simplecov (0.22.0)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.13.1)
simplecov-json (0.2.3)
json
simplecov
simplecov_json_formatter (0.1.4)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
Expand Down Expand Up @@ -445,7 +449,8 @@ DEPENDENCIES
rubocop-rails
rubocop-rspec
sidekiq (~> 6.2)
simplecov (~> 0.17.1)
simplecov
simplecov-json
sprockets-rails
state_machines-activerecord (~> 0.6.0)
tzinfo-data
Expand Down
9 changes: 9 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# frozen_string_literal: true

require 'simplecov'
require 'simplecov-json'

SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new(
[
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::JSONFormatter
]
)

SimpleCov.start :rails do
add_filter '/channels/'
add_filter '/controllers/application_controller.rb'
Expand Down

0 comments on commit c31d36d

Please sign in to comment.