Skip to content

Commit

Permalink
Add GitHub Actions
Browse files Browse the repository at this point in the history
* Update README.md

* Clean up ci.yml

* Add standardrb

* Standardize

* Add test:all task
  • Loading branch information
excid3 committed Aug 7, 2023
1 parent 43d5b84 commit 6e0dcc2
Show file tree
Hide file tree
Showing 18 changed files with 99 additions and 50 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ on:
push:
branches:
- master

jobs:
sqlite:
runs-on: ubuntu-latest

env:
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
BUNDLE_PATH_RELATIVE_TO_CWD: true

steps:
- name: SQLite3 version
run: sqlite3 --version
Expand All @@ -30,8 +28,7 @@ jobs:
run: bundle exec standardrb
- name: Run tests
env:
DATABASE_URL: "sqlite3:pay_test"
STRIPE_PRIVATE_KEY: ${{ secrets.STRIPE_PRIVATE_KEY }}
DATABASE_URL: "sqlite3:signalman_test"
run: |
bin/rails db:test:prepare
bin/rails test:all
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ gem "web-console", group: :development

# Start debugger with binding.b [https://github.com/ruby/debug]
# gem "debug", ">= 1.0.0"

gem "standardrb", "~> 1.0"
49 changes: 45 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ GEM
tzinfo (~> 2.0)
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
bindex (0.8.1)
builder (3.2.4)
capybara (3.39.2)
Expand All @@ -97,6 +98,9 @@ GEM
importmap-rails (1.2.1)
actionpack (>= 6.0.0)
railties (>= 6.0.0)
json (2.6.3)
language_server-protocol (3.17.0.3)
lint_roller (1.1.0)
loofah (2.21.3)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
Expand Down Expand Up @@ -128,11 +132,15 @@ GEM
racc (~> 1.4)
nokogiri (1.15.3-x86_64-linux)
racc (~> 1.4)
parallel (1.23.0)
parser (3.2.2.3)
ast (~> 2.4.1)
racc
public_suffix (5.0.3)
puma (6.3.0)
nio4r (~> 2.0)
racc (1.7.1)
rack (2.2.7)
rack (2.2.8)
rack-test (2.1.0)
rack (>= 1.3)
rails (7.0.6)
Expand All @@ -149,7 +157,7 @@ GEM
activesupport (= 7.0.6)
bundler (>= 1.15.0)
railties (= 7.0.6)
rails-dom-testing (2.1.1)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
Expand All @@ -163,13 +171,30 @@ GEM
rake (>= 12.2)
thor (~> 1.0)
zeitwerk (~> 2.5)
rainbow (3.1.1)
rake (13.0.6)
redis (5.0.6)
redis-client (>= 0.9.0)
redis-client (0.14.1)
redis-client (0.15.0)
connection_pool
regexp_parser (2.8.1)
rexml (3.2.6)
rubocop (1.52.1)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.2.2.3)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.29.0)
parser (>= 3.2.1.0)
rubocop-performance (1.18.0)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
ruby-progressbar (1.13.0)
rubyzip (2.3.2)
selenium-webdriver (4.11.0)
rexml (~> 3.2, >= 3.2.5)
Expand All @@ -186,6 +211,20 @@ GEM
sqlite3 (1.6.3-arm64-darwin)
sqlite3 (1.6.3-x86_64-darwin)
sqlite3 (1.6.3-x86_64-linux)
standard (1.30.1)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.52.0)
standard-custom (~> 1.0.0)
standard-performance (~> 1.1.0)
standard-custom (1.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.50)
standard-performance (1.1.2)
lint_roller (~> 1.1)
rubocop-performance (~> 1.18.0)
standardrb (1.0.1)
standard
thor (1.2.2)
timeout (0.4.0)
turbo-rails (1.4.0)
Expand All @@ -194,6 +233,7 @@ GEM
railties (>= 6.0.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.4.2)
web-console (4.2.0)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
Expand All @@ -205,7 +245,7 @@ GEM
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.9)
zeitwerk (2.6.11)

PLATFORMS
aarch64-linux
Expand All @@ -222,6 +262,7 @@ DEPENDENCIES
signalman!
sprockets-rails
sqlite3
standardrb (~> 1.0)
turbo-rails
web-console

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Signalman
A debug tool for Ruby on Rails application.

[![Tests](https://github.com/excid3/signalman/actions/workflows/ci.yml/badge.svg)](https://github.com/excid3/signalman/actions/workflows/ci.yml)

## Usage
How to use my plugin.

Expand Down
9 changes: 9 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@ load "rails/tasks/engine.rake"
load "rails/tasks/statistics.rake"

require "bundler/gem_tasks"
require "rake/testtask"

Rake::TestTask.new("test:all") do |t|
t.libs << "test"
t.pattern = "test/**/*_test.rb"
t.verbose = false
end

task default: "test:all"
2 changes: 1 addition & 1 deletion app/controllers/signalman/generators/models_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def show
end

def create
@fields = params[:fields].map{ |field| [field[:name], field[:type]].join(":") }
@fields = params[:fields].map { |field| [field[:name], field[:type]].join(":") }
Bundler.with_original_env do
@stdout, @stderr, @status = Open3.capture3("rails", "generate", "model", params[:model_name], *@fields)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def show
end

def create
@fields = params[:fields].map{ |field| [field[:name], field[:type]].join(":") }
@fields = params[:fields].map { |field| [field[:name], field[:type]].join(":") }
Bundler.with_original_env do
@stdout, @stderr, @status = Open3.capture3("rails", "generate", "scaffold", params[:model_name], *@fields)
end
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/signalman/events_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Signalman
module EventsHelper
def signalman_path_for(event)
block = Signalman.events.find{ |key, _| key.match? event.name }.last[:path]
block = Signalman.events.find { |key, _| key.match? event.name }.last[:path]
instance_exec event, &block
end

Expand Down
15 changes: 7 additions & 8 deletions app/models/signalman/event.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
class Signalman::Event < ApplicationRecord
scope :requests, ->{ where(name: "process_action.action_controller") }
scope :mails, ->{ where(name: "deliver.action_mailer") }
scope :queries, ->{ where(name: "sql.active_record") }
scope :views, ->{
scope :requests, -> { where(name: "process_action.action_controller") }
scope :mails, -> { where(name: "deliver.action_mailer") }
scope :queries, -> { where(name: "sql.active_record") }
scope :views, -> {
where(name: [
"render_template.action_view",
"render_partial.action_view",
"render_collection.action_view",
"render_layout.action_view",
"render_layout.action_view"
])
}
scope :jobs, -> {
Expand All @@ -16,10 +16,9 @@ class Signalman::Event < ApplicationRecord
"enqueue.active_job",
"perform.active_job",
"perform_start.active_job",
"discard.active_job",
"discard.active_job"
])
}


scope :recent_first, ->{ order(created_at: :desc) }
scope :recent_first, -> { order(created_at: :desc) }
end
28 changes: 16 additions & 12 deletions lib/signalman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ def process
end

create_event event.payload.slice(
:method,
:path,
:controller,
:action,
:params,
:format,
:status,
:db_runtime,
:view_runtime
).merge(headers: headers)
:method,
:path,
:controller,
:action,
:params,
:format,
:status,
:db_runtime,
:view_runtime
).merge(headers: headers)
end

def skip?
Expand All @@ -101,7 +101,7 @@ class QueryHandler < BaseHandler
# CREATE_TABLE queries have nil for `name`
def skip?
return if event.payload[:name].blank?
IGNORED_QUERIES.any?{ |q| q.match? event.payload[:name] }
IGNORED_QUERIES.any? { |q| q.match? event.payload[:name] }
end

def process
Expand Down Expand Up @@ -147,7 +147,11 @@ def format(arg)
when Array
arg.map { |value| format(value) }
when GlobalID::Identification
arg.to_global_id rescue arg
begin
arg.to_global_id
rescue
arg
end
else
arg
end
Expand Down
2 changes: 1 addition & 1 deletion lib/signalman/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Engine < ::Rails::Engine
end

# helpers must be accessible anywhere for Turbo broadcasts
initializer 'signalman.helpers' do
initializer "signalman.helpers" do
ActiveSupport.on_load :action_controller do
helper Signalman::EventsHelper
end
Expand Down
14 changes: 7 additions & 7 deletions signalman.gemspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
require_relative "lib/signalman/version"

Gem::Specification.new do |spec|
spec.name = "signalman"
spec.version = Signalman::VERSION
spec.authors = ["Chris Oliver"]
spec.email = ["excid3@gmail.com"]
spec.homepage = "https://github.com/excid3/signalman"
spec.summary = "Development tools for Ruby on Rails"
spec.name = "signalman"
spec.version = Signalman::VERSION
spec.authors = ["Chris Oliver"]
spec.email = ["excid3@gmail.com"]
spec.homepage = "https://github.com/excid3/signalman"
spec.summary = "Development tools for Ruby on Rails"
spec.description = "Development tools for Ruby on Rails"
spec.license = "MIT"
spec.license = "MIT"

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "https://github.com/excid3/signalman"
Expand Down
1 change: 0 additions & 1 deletion test/dummy/app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class UserMailer < ApplicationMailer

# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
Expand Down
8 changes: 4 additions & 4 deletions test/dummy/config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
config.eager_load = true

# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.consider_all_requests_local = false
config.action_controller.perform_caching = true

# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
Expand Down Expand Up @@ -53,7 +53,7 @@
config.log_level = :info

# Prepend all log lines with the following tags.
config.log_tags = [ :request_id ]
config.log_tags = [:request_id]

# Use a different cache store in production.
# config.cache_store = :mem_cache_store
Expand Down Expand Up @@ -83,9 +83,9 @@
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name")

if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger = ActiveSupport::Logger.new($stdout)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
config.logger = ActiveSupport::TaggedLogging.new(logger)
end

# Do not dump schema after migrations.
Expand Down
2 changes: 1 addition & 1 deletion test/dummy/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}

# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.cache_store = :null_store

Expand Down
1 change: 0 additions & 1 deletion test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

end
2 changes: 0 additions & 2 deletions test/dummy/test/mailers/previews/user_mailer_preview.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Preview all emails at http://localhost:3000/rails/mailers/user_mailer
class UserMailerPreview < ActionMailer::Preview

# Preview this email at http://localhost:3000/rails/mailers/user_mailer/notification
def notification
UserMailer.notification
end

end
1 change: 0 additions & 1 deletion test/dummy/test/mailers/user_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ class UserMailerTest < ActionMailer::TestCase
assert_equal ["from@example.com"], mail.from
assert_match "Hi", mail.body.encoded
end

end

0 comments on commit 6e0dcc2

Please sign in to comment.