Skip to content

Commit

Permalink
add solargraph & simplecov gems
Browse files Browse the repository at this point in the history
* add bin/coverage for ci
* update GH action
  • Loading branch information
agilous committed Jan 4, 2024
1 parent 57d3a69 commit ec155db
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 21 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ jobs:
- name: Set up database schema
run: bin/rails db:schema:load
# Add or replace test runners here
- name: Run specs
- name: Run Tests
run: bin/rspec
- uses: joshmfrankel/simplecov-check-action@main
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
minimum_suite_coverage: 95

lint:
runs-on: ubuntu-latest
Expand All @@ -44,7 +48,7 @@ jobs:
with:
bundler-cache: true
# Add or replace any other lints here
- name: Security audit application code
- name: Brakeman Scan
run: bin/brakeman
- name: Lint Ruby files
- name: Ruby Linter
run: bin/rubocop --parallel
18 changes: 1 addition & 17 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,26 +1,10 @@
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore all environment files (except templates).
/.env*
!/.env*.erb

# Ignore all logfiles and tempfiles.
/coverage/*
/log/*
/tmp/*

# Ignore storage (uploaded files in development and any SQLite databases).
/storage/*

/public/assets

# Ignore master key for decrypting credentials and more.
/config/master.key

.byebug_history
7 changes: 7 additions & 0 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

require 'simplecov'

SimpleCov.start 'rails' do
minimum_coverage 95
end
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ group :development, :test do
end

group :development do
gem 'solargraph'
gem 'web-console'
end

Expand All @@ -35,5 +36,6 @@ group :test do
gem 'rubocop-rails', require: false
gem 'rubocop-rspec', require: false
gem 'shoulda-matchers'
gem 'simplecov', require: false
gem 'webdrivers'
end
38 changes: 38 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ GEM
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
backport (1.2.0)
base64 (0.2.0)
benchmark (0.3.0)
bigdecimal (3.1.5)
bindex (0.8.1)
bootsnap (1.17.0)
Expand All @@ -128,8 +130,10 @@ GEM
crass (1.0.6)
date (3.3.4)
diff-lcs (1.5.0)
docile (1.4.0)
drb (2.2.0)
ruby2_keywords
e2mmap (0.1.0)
erubi (1.12.0)
factory_bot (6.4.4)
activesupport (>= 5.0.0)
Expand All @@ -148,10 +152,15 @@ GEM
irb (1.11.0)
rdoc
reline (>= 0.3.8)
jaro_winkler (1.5.6)
jbuilder (2.11.5)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
json (2.7.1)
kramdown (2.4.0)
rexml
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
language_server-protocol (3.17.0.3)
loofah (2.22.0)
crass (~> 1.0.2)
Expand Down Expand Up @@ -212,11 +221,14 @@ GEM
nokogiri (~> 1.14)
rainbow (3.1.1)
rake (13.1.0)
rbs (2.8.4)
rdoc (6.6.2)
psych (>= 4.0.0)
regexp_parser (2.8.3)
reline (0.4.1)
io-console (~> 0.5)
reverse_markdown (2.1.1)
nokogiri
rexml (3.2.6)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
Expand Down Expand Up @@ -273,6 +285,28 @@ GEM
websocket (~> 1.0)
shoulda-matchers (6.0.0)
activesupport (>= 5.2.0)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
solargraph (0.50.0)
backport (~> 1.2)
benchmark
bundler (~> 2.0)
diff-lcs (~> 1.4)
e2mmap
jaro_winkler (~> 1.5)
kramdown (~> 2.3)
kramdown-parser-gfm (~> 1.1)
parser (~> 3.0)
rbs (~> 2.0)
reverse_markdown (~> 2.0)
rubocop (~> 1.38)
thor (~> 1.0)
tilt (~> 2.0)
yard (~> 0.9, >= 0.9.24)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
Expand All @@ -284,6 +318,7 @@ GEM
railties (>= 6.0.0)
stringio (3.1.0)
thor (1.3.0)
tilt (2.3.0)
timeout (0.4.1)
turbo-rails (1.5.0)
actionpack (>= 6.0.0)
Expand All @@ -308,6 +343,7 @@ GEM
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
yard (0.9.34)
zeitwerk (2.6.12)

PLATFORMS
Expand All @@ -334,6 +370,8 @@ DEPENDENCIES
rubocop-rails
rubocop-rspec
shoulda-matchers
simplecov
solargraph
sprockets-rails
stimulus-rails
turbo-rails
Expand Down
2 changes: 2 additions & 0 deletions app/channels/application_cable/channel.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

# :nocov: Remove once code is added.
module ApplicationCable
class Channel < ActionCable::Channel::Base
end
end
# :nocov:
2 changes: 2 additions & 0 deletions app/channels/application_cable/connection.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

# :nocov: Remove once code is added.
module ApplicationCable
class Connection < ActionCable::Connection::Base
end
end
# :nocov:
2 changes: 2 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# frozen_string_literal: true

# :nocov: Remove once code is added.
module ApplicationHelper
end
# :nocov:
2 changes: 2 additions & 0 deletions app/helpers/categories_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# frozen_string_literal: true

# :nocov: Remove once code is added.
module CategoriesHelper
end
# :nocov:
6 changes: 6 additions & 0 deletions app/helpers/statements_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

# :nocov: Remove once code is added.
module StatementsHelper
end
# :nocov:
2 changes: 2 additions & 0 deletions app/helpers/transactions_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# frozen_string_literal: true

# :nocov: Remove once code is added.
module TransactionsHelper
end
# :nocov:
2 changes: 2 additions & 0 deletions app/jobs/application_job.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# frozen_string_literal: true

# :nocov: Remove once code is added.
class ApplicationJob < ActiveJob::Base
# Automatically retry jobs that encountered a deadlock
# retry_on ActiveRecord::Deadlocked

# Most jobs are safe to ignore if the underlying records are no longer available
# discard_on ActiveJob::DeserializationError
end
# :nocov:
2 changes: 2 additions & 0 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

# :nocov: Remove once code is added.
class ApplicationMailer < ActionMailer::Base
default from: '[email protected]'
layout 'mailer'
end
# :nocov:
7 changes: 6 additions & 1 deletion bin/ci
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ Dir.chdir(APP_ROOT) do
brakeman_passed = system("bin/brakeman")
terminal_message("Done.\n\n")

terminal_message("Checking Code Coverage...")
coverage_passed = system("bin/coverage")
terminal_message("Done.\n\n")

pass_fail(ruby_tests_passed, "Ruby Tests")
pass_fail(ruby_linting_passed, "Ruby Linter")
pass_fail(brakeman_passed, "Brakeman Scan")
pass_fail(coverage_passed, "Code Coverage")

return 1 unless ruby_tests_passed && ruby_linting_passed && brakeman_passed
return 1 unless ruby_tests_passed && ruby_linting_passed && brakeman_passed && coverage_passed

return 0
end
21 changes: 21 additions & 0 deletions bin/coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env ruby
require 'json'

MINIMUM_COVERAGE = 95

coverage_report_path = "#{Dir.pwd}/coverage/.last_run.json"
if File.exist?(coverage_report_path)
coverage_data = JSON.parse(File.read(coverage_report_path))
coverage_percentage = coverage_data['result']['line']

if coverage_percentage >= MINIMUM_COVERAGE
puts "🥳 Awesome coverage (#{coverage_percentage}%)!\n"
exit 0
else
puts "😥 Coverage insufficient (#{coverage_percentage}%).\n"
exit 1
end
else
puts "Coverage report not found.\n"
exit 1
end
2 changes: 2 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# Prevent database truncation if the environment is production
abort('The Rails environment is running in production mode!') if Rails.env.production?
require 'rspec/rails'
require 'simplecov'

# Add additional requires below this line. Rails is not loaded until this point!

# Requires supporting ruby files with custom matchers and macros, etc, in
Expand Down

0 comments on commit ec155db

Please sign in to comment.