Skip to content

Commit

Permalink
Merge pull request #13680 from danidoni/refactor-environment-check-in…
Browse files Browse the repository at this point in the history
…-rake-dev-tasks

Refactor environment check
  • Loading branch information
saraycp committed Jan 13, 2023
2 parents f21a8fe + af223fd commit 98dee6b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 63 deletions.
17 changes: 10 additions & 7 deletions src/api/lib/tasks/dev.rake
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ namespace :dev do
RakeSupport.copy_example_file('../../dist/ec2utils.conf')
end

task development_environment: :environment do
unless Rails.env.development?
puts "You are running this rake task in #{Rails.env} environment."
puts 'Please only run this task with RAILS_ENV=development'
puts 'otherwise it will destroy your database data.'
exit(1)
end
end

desc 'Bootstrap the application'
task :bootstrap, [:old_test_suite] => [:prepare, :environment] do |_t, args|
args.with_defaults(old_test_suite: false)
Expand Down Expand Up @@ -63,13 +72,7 @@ namespace :dev do
# This is automatically run in Review App or manually in development env.
namespace :test_data do
desc 'Creates test data to play with in dev and CI environments'
task create: :environment do
unless Rails.env.development?
puts "You are running this rake task in #{Rails.env} environment."
puts 'Please only run this task with RAILS_ENV=development'
puts 'otherwise it will destroy your database data.'
return
end
task create: :development_environment do
require 'factory_bot'
include FactoryBot::Syntax::Methods
require 'active_support/testing/time_helpers'
Expand Down
9 changes: 1 addition & 8 deletions src/api/lib/tasks/dev/news.rake
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@ namespace :dev do
# Run this task with: rails "dev:news:data[3]"
# replacing 3 with any number to indicate how many times you want this code to be executed.
desc 'Creates a notification and all its dependencies'
task :data, [:repetitions] => :environment do |_t, args|
unless Rails.env.development?
puts "You are running this rake task in #{Rails.env} environment."
puts 'Please only run this task with RAILS_ENV=development'
puts 'otherwise it will destroy your database data.'
return
end

task :data, [:repetitions] => :development_environment do |_t, args|
args.with_defaults(repetitions: 1)
repetitions = args.repetitions.to_i
require 'factory_bot'
Expand Down
9 changes: 1 addition & 8 deletions src/api/lib/tasks/dev/notifications.rake
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@ namespace :dev do
# Run this task with: rails "dev:notifications:data[3]"
# replacing 3 with any number to indicate how many times you want this code to be executed.
desc 'Creates a notification and all its dependencies'
task :data, [:repetitions] => :environment do |_t, args|
unless Rails.env.development?
puts "You are running this rake task in #{Rails.env} environment."
puts 'Please only run this task with RAILS_ENV=development'
puts 'otherwise it will destroy your database data.'
return
end

task :data, [:repetitions] => :development_environment do |_t, args|
args.with_defaults(repetitions: 1)
repetitions = args.repetitions.to_i
require 'factory_bot'
Expand Down
27 changes: 3 additions & 24 deletions src/api/lib/tasks/dev/requests.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@ namespace :dev do
namespace :requests do
# Run this task with: rails dev:requests:multiple_actions_request
desc 'Creates a request with multiple actions'
task multiple_actions_request: :environment do
unless Rails.env.development?
puts "You are running this rake task in #{Rails.env} environment."
puts 'Please only run this task with RAILS_ENV=development'
puts 'otherwise it will destroy your database data.'
return
end

task multiple_actions_request: :development_environment do
require 'factory_bot'
include FactoryBot::Syntax::Methods

Expand Down Expand Up @@ -73,14 +66,7 @@ namespace :dev do
end

desc 'Creates several requests with submit actions and diffs'
task request_with_multiple_submit_actions_and_diffs: :environment do
unless Rails.env.development?
puts "You are running this rake task in #{Rails.env} environment."
puts 'Please only run this task with RAILS_ENV=development'
puts 'otherwise it will destroy your database data.'
return
end

task request_with_multiple_submit_actions_and_diffs: :development_environment do
require 'factory_bot'
include FactoryBot::Syntax::Methods

Expand Down Expand Up @@ -120,14 +106,7 @@ namespace :dev do
end

desc 'Creates a request which builds and produces build results'
task request_with_build_results: :environment do
unless Rails.env.development?
puts "You are running this rake task in #{Rails.env} environment."
puts 'Please only run this task with RAILS_ENV=development'
puts 'otherwise it will destroy your database data.'
return
end

task request_with_build_results: :development_environment do
require 'factory_bot'
include FactoryBot::Syntax::Methods

Expand Down
9 changes: 1 addition & 8 deletions src/api/lib/tasks/dev/staging.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@ namespace :dev do
namespace :staging do
# Run this task with: rails dev:staging:data
desc 'Creates a staging workflow with a project and a confirmed user'
task data: :environment do
unless Rails.env.development?
puts "You are running this rake task in #{Rails.env} environment."
puts 'Please only run this task with RAILS_ENV=development'
puts 'otherwise it will destroy your database data.'
return
end

task data: :development_environment do
require 'factory_bot'
include FactoryBot::Syntax::Methods
timestamp = Time.now.to_i
Expand Down
9 changes: 1 addition & 8 deletions src/api/lib/tasks/dev/workflows.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@ namespace :dev do
namespace :workflows do
# Run this task with: rails dev:workflows:create_workflow_runs
desc 'Creates a workflow token, workflow runs, artifacts and some of their dependencies'
task create_workflow_runs: :environment do
unless Rails.env.development?
puts "You are running this rake task in #{Rails.env} environment."
puts 'Please only run this task with RAILS_ENV=development'
puts 'otherwise it will destroy your database data.'
return
end

task create_workflow_runs: :development_environment do
require 'factory_bot'
include FactoryBot::Syntax::Methods

Expand Down

0 comments on commit 98dee6b

Please sign in to comment.