Class: Renuo::Cli::Commands::ConfigureSemaphore
- Inherits:
-
Object
- Object
- Renuo::Cli::Commands::ConfigureSemaphore
- Defined in:
- lib/renuo/cli/commands/configure_semaphore.rb
Instance Attribute Summary collapse
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#project_name ⇒ Object
Returns the value of attribute project_name.
-
#slack_endpoint ⇒ Object
Returns the value of attribute slack_endpoint.
Instance Method Summary collapse
- #create_semaphore_deployment_targets ⇒ Object
- #create_semaphore_notification ⇒ Object
- #create_semaphore_secrets ⇒ Object
-
#initialize ⇒ ConfigureSemaphore
constructor
A new instance of ConfigureSemaphore.
- #render(template_file) ⇒ Object
-
#run ⇒ Object
rubocop:disable Metrics/MethodLength.
- #semaphore_cli_installed? ⇒ Boolean
- #write_or_warn(file_path, content) ⇒ Object
Constructor Details
#initialize ⇒ ConfigureSemaphore
Returns a new instance of ConfigureSemaphore.
14 15 16 17 |
# File 'lib/renuo/cli/commands/configure_semaphore.rb', line 14 def initialize @project_name = File.basename(Dir.getwd) @slack_endpoint = "https://hooks.slack.com/services/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" end |
Instance Attribute Details
#environment ⇒ Object
Returns the value of attribute environment.
4 5 6 |
# File 'lib/renuo/cli/commands/configure_semaphore.rb', line 4 def environment @environment end |
#project_name ⇒ Object
Returns the value of attribute project_name.
4 5 6 |
# File 'lib/renuo/cli/commands/configure_semaphore.rb', line 4 def project_name @project_name end |
#slack_endpoint ⇒ Object
Returns the value of attribute slack_endpoint.
4 5 6 |
# File 'lib/renuo/cli/commands/configure_semaphore.rb', line 4 def slack_endpoint @slack_endpoint end |
Instance Method Details
#create_semaphore_deployment_targets ⇒ Object
53 54 55 56 |
# File 'lib/renuo/cli/commands/configure_semaphore.rb', line 53 def create_semaphore_deployment_targets system("sem create dt main -p #{project_name}") system("sem create dt develop -p #{project_name}") end |
#create_semaphore_notification ⇒ Object
43 44 45 46 47 |
# File 'lib/renuo/cli/commands/configure_semaphore.rb', line 43 def create_semaphore_notification File.write("tmp/notification.#{project_name}.yml", render("../templates/semaphore/notification.yml.erb")) system("sem create -f tmp/notification.#{project_name}.yml") FileUtils.rm("tmp/notification.#{project_name}.yml") end |
#create_semaphore_secrets ⇒ Object
49 50 51 |
# File 'lib/renuo/cli/commands/configure_semaphore.rb', line 49 def create_semaphore_secrets system("sem create secret -p #{project_name} #{project_name}") end |
#render(template_file) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/renuo/cli/commands/configure_semaphore.rb', line 58 def render(template_file) file_path = File.join(File.dirname(__FILE__), template_file) semaphore_template = File.read(file_path) renderer = ERB.new(semaphore_template) renderer.result(binding) end |
#run ⇒ Object
rubocop:disable Metrics/MethodLength
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/renuo/cli/commands/configure_semaphore.rb', line 19 def run # rubocop:disable Metrics/MethodLength return unless semaphore_cli_installed? FileUtils.mkdir_p(%w[.semaphore .semaphore/bin tmp]) write_or_warn(".semaphore/semaphore.yml", render("../templates/semaphore/semaphore.yml.erb")) %w[main develop].each do |environment| @environment = environment write_or_warn(".semaphore/#{environment}-deploy.yml", render("../templates/semaphore/semaphore-deploy.yml.erb")) end write_or_warn(".semaphore/bin/cache_restore", render("../templates/semaphore/bin/cache_restore.erb")) write_or_warn(".semaphore/bin/cache_store", render("../templates/semaphore/bin/cache_store.erb")) create_semaphore_notification create_semaphore_secrets create_semaphore_deployment_targets end |
#semaphore_cli_installed? ⇒ Boolean
37 38 39 40 41 |
# File 'lib/renuo/cli/commands/configure_semaphore.rb', line 37 def semaphore_cli_installed? semaphore_cli_installed = `sem context | grep '*'`.strip == "* renuo_semaphoreci_com" warn("You need to install and configure Semaphore CLI to run this command.") unless semaphore_cli_installed semaphore_cli_installed end |
#write_or_warn(file_path, content) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/renuo/cli/commands/configure_semaphore.rb', line 65 def write_or_warn(file_path, content) if File.exist?(file_path) warn("#{file_path} exists already. I will not overwrite it.") else File.write(file_path, content) say("#{file_path} added.") end end |