Created
March 1, 2020 12:40
-
-
Save geewiz/a08fe0889ebef8eb0c75c808e544d514 to your computer and use it in GitHub Desktop.
My Rake tasks for Rails apps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# Add your own tasks in files placed in lib/tasks ending in .rake, | |
# for example lib/tasks/capistrano.rake, and they will automatically | |
# be available to Rake. | |
require File.expand_path("config/application", __dir__) | |
Rails.application.load_tasks | |
task default: :test | |
task :rubocop do | |
sh "bundle exec rubocop ." | |
end | |
desc "Run complete test suite" | |
task :test do | |
Rake::Task["rubocop"].invoke | |
Rake::Task["security:rbp"].invoke | |
Rake::Task["security:brakeman"].invoke | |
if ENV["CIRCLE_TEST_REPORTS"] | |
Rake::Task["spec_ci"].invoke | |
else | |
Rake::Task["spec"].invoke | |
end | |
end | |
namespace :db do | |
desc "Update database with new migrations" | |
task :update do | |
puts "Updating #{ENV['RAILS_ENV']} database" | |
Rake::Task["db:migrate"].invoke | |
Rake::Task["db:test:prepare"].invoke | |
end | |
desc "Reset development database" | |
task :nuke do | |
sh "bundle exec rails db:migrate:reset db:seed" | |
sh "bundle exec rails db:migrate:reset RAILS_ENV=test" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
begin | |
require "rspec/core/rake_task" | |
Rake::Task[:spec].clear | |
RSpec::Core::RakeTask.new(:spec) do |task| | |
task.rspec_opts = "--format Fuubar --color" | |
end | |
# RSpec task providing metadata for CircleCI | |
RSpec::Core::RakeTask.new(:spec_ci) do |task| | |
task.rspec_opts = "-r rspec_junit_formatter" + | |
" --format RspecJunitFormatter" + | |
" -o $CIRCLE_TEST_REPORTS/rspec/junit.xml" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
namespace :security do | |
desc "Rails Best Practices" | |
task :rbp do | |
path = File.expand_path("../..", __dir__) | |
sh "rails_best_practices #{path}" | |
end | |
desc "Static analysis vulnerability scanner" | |
task :brakeman, :output_files do |_t, args| | |
require "brakeman" | |
files = args[:output_files].split(" ") if args[:output_files] | |
Brakeman.run app_path: ".", | |
output_files: files, | |
print_report: true, | |
exit_on_warn: true | |
end | |
desc "Check Gemfile.lock for insecure dependencies" | |
task :gems do | |
sh "bundle-audit update" | |
sh "bundle-audit check" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment