Skip to content

Commit

Permalink
Deployment troubleshooting: rake task updates
Browse files Browse the repository at this point in the history
  • Loading branch information
elohanlon committed Sep 21, 2023
1 parent bb0a6bb commit d4048a6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 39 deletions.
1 change: 1 addition & 0 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
with rails_env: fetch(:rails_env) do
execute :echo, '"Got here 1"'
execute :rake, 'resque:test'
execute :rake, 'resque:restart_workers'
execute :echo, '"Got here 2"'
end
end
Expand Down
82 changes: 43 additions & 39 deletions lib/tasks/derivativo/ci.rake
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

0 comments on commit d4048a6

Please sign in to comment.