-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deployment troubleshooting: rake task updates
- Loading branch information
Showing
2 changed files
with
44 additions
and
39 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
# Only include this task in development and test environments (because rspec is only available | ||
# in those environments and we don't ever want to run CI tasks in other environments). | ||
if ['development', 'test'].include?(Rails.env) | ||
namespace :derivativo do | ||
require 'rspec/core/rake_task' | ||
RSpec::Core::RakeTask.new(:rspec) do |spec| | ||
spec.rspec_opts ||= [] | ||
spec.rspec_opts << '--backtrace' if ENV['CI'] | ||
end | ||
namespace :derivativo do | ||
require 'rspec/core/rake_task' | ||
RSpec::Core::RakeTask.new(:rspec) do |spec| | ||
spec.rspec_opts ||= [] | ||
spec.rspec_opts << '--backtrace' if ENV['CI'] | ||
end | ||
|
||
require 'rubocop/rake_task' | ||
desc 'Run style checker' | ||
RuboCop::RakeTask.new(:rubocop) do |task| | ||
task.requires << 'rubocop-rspec' | ||
task.fail_on_error = true | ||
end | ||
require 'rubocop/rake_task' | ||
desc 'Run style checker' | ||
RuboCop::RakeTask.new(:rubocop) do |task| | ||
task.requires << 'rubocop-rspec' | ||
task.fail_on_error = true | ||
end | ||
|
||
desc 'CI build without rubocop' | ||
task ci_nocop: ['derivativo:setup:config_files', :environment, 'derivativo:ci_specs'] | ||
desc 'CI build without rubocop' | ||
task ci_nocop: ['derivativo:setup:config_files', :environment, 'derivativo:ci_specs'] | ||
|
||
desc 'CI build with Rubocop validation' | ||
task ci: ['derivativo:setup:config_files', :environment, 'derivativo:rubocop', 'derivativo:ci_specs'] | ||
desc 'CI build with Rubocop validation' | ||
task ci: ['derivativo:setup:config_files', :environment, 'derivativo:rubocop', 'derivativo:ci_specs'] | ||
|
||
desc 'CI build just running specs' | ||
task ci_specs: :environment do | ||
rspec_system_exit_failure_exception = nil | ||
desc 'CI build just running specs' | ||
task ci_specs: :environment do | ||
rspec_system_exit_failure_exception = nil | ||
|
||
duration = Benchmark.realtime do | ||
ENV['RAILS_ENV'] = 'test' | ||
Rails.env = ENV['RAILS_ENV'] | ||
duration = Benchmark.realtime do | ||
ENV['RAILS_ENV'] = 'test' | ||
Rails.env = ENV['RAILS_ENV'] | ||
|
||
Rake::Task['db:environment:set'].invoke | ||
Rake::Task['db:drop'].invoke | ||
Rake::Task['db:create'].invoke | ||
Rake::Task['db:migrate'].invoke | ||
begin | ||
Rake::Task['derivativo:rspec'].invoke | ||
rescue SystemExit => e | ||
rspec_system_exit_failure_exception = e | ||
end | ||
Rake::Task['db:environment:set'].invoke | ||
Rake::Task['db:drop'].invoke | ||
Rake::Task['db:create'].invoke | ||
Rake::Task['db:migrate'].invoke | ||
begin | ||
Rake::Task['derivativo:rspec'].invoke | ||
rescue SystemExit => e | ||
rspec_system_exit_failure_exception = e | ||
end | ||
puts "CI run finished in #{duration} seconds." | ||
# If present, re-raise any caught exit exception after CI duration display, | ||
# so we can still display the run time even when a system exception comes up. | ||
# This exception triggers an exit call with the original error code sent out by rspec failure. | ||
raise rspec_system_exit_failure_exception unless rspec_system_exit_failure_exception.nil? | ||
end | ||
puts "CI run finished in #{duration} seconds." | ||
# If present, re-raise any caught exit exception after CI duration display, | ||
# so we can still display the run time even when a system exception comes up. | ||
# This exception triggers an exit call with the original error code sent out by rspec failure. | ||
raise rspec_system_exit_failure_exception unless rspec_system_exit_failure_exception.nil? | ||
end | ||
rescue LoadError => e | ||
# Be prepared to rescue so that this rake file can be loaded in environments where RSpec | ||
# is unavailable (i.e. production/deployed environments). | ||
puts '[Warning] Exception creating ci/rubocop/rspec rake tasks. '\ | ||
'This message can be ignored in environments that intentionally '\ | ||
'do not pull in certain development/test environment gems '\ | ||
'(i.e. production/deployed environments).' | ||
puts e | ||
end |